Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://codeberg.org/scy/mijia-temphum-upy
MicroPython library to read certain Xiaomi Mijia BLE temperature & humidity sensors.
https://codeberg.org/scy/mijia-temphum-upy
Last synced: 3 months ago
JSON representation
MicroPython library to read certain Xiaomi Mijia BLE temperature & humidity sensors.
- Host: codeberg.org
- URL: https://codeberg.org/scy/mijia-temphum-upy
- Owner: scy
- Created: 2021-07-03T23:41:56.000Z (over 3 years ago)
- Default Branch: main
- Last Synced: 2022-09-13T18:16:36.633Z (about 2 years ago)
- Language:
- Homepage:
- Size: 119 KB
- Stars: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micropython - mijia-temphum-upy - MicroPython library to read certain Xiaomi Mijia BLE temperature & humidity sensors. (Libraries / Communications)
README
# mijia-temphum-upy
This is MicroPython code to read temperature and humidity from certain Xiaomi Mijia sensors.
**Note:**
Consider this beta quality software, I'm in a hurry.## Requirements
This requires MicroPython, a board with BLE support and the [Perthensis](https://codeberg.org/scy/perthensis) `gattc` module.
The latter is currently the most complicated requirement:
`gattc` is still in development and not yet available in a stable branch.## Example
### A single sensor
```python
from mijia_temphum import Central, Sensordef result(val):
print("{0} is at {1}°C and {2}%".format(
val.sensor.hexaddr, val.temp_c, val.hum_pcnt))central = Central()
central.enable()s = Sensor(central, "4C:65:A8:DC:1B:6A", result)
s.request_value()
```### Multiple sensors
```python
from mijia_temphum import Central, Sensorsdef result(val):
print("{0} ({1}) is at {2}°C and {3}%".format(
val.sensor.name, val.sensor.hexaddr, val.temp_c, val.hum_pcnt))def status(done, of, elapsed_s):
print("{0} of {1} sensors read after {2}s".format(
done, of, elapsed_s))central = Central()
central.enable()s = Sensors(central, {
"4C:65:A8:DC:1B:6A": "Desk",
"4C:65:A8:DC:29:07": "Kitchen",
}, result, status)
s.request_all()
```### Multiple sensors regularly
This is using the coroutine scheduler provided by Perthensis.
```python
from mijia_temphum import Central, ScheduledSensors
from perthensis.scheduler import Schedulerdef result(val):
print("{0} ({1}) is at {2}°C and {3}%".format(
val.sensor.name, val.sensor.hexaddr, val.temp_c, val.hum_pcnt))def status(done, of, elapsed_s):
print("{0} of {1} sensors read after {2}s".format(
done, of, elapsed_s))central = Central()
central.enable()s = ScheduledSensors(central, {
"4C:65:A8:DC:1B:6A": "Desk",
"4C:65:A8:DC:29:07": "Kitchen",
}, result, status, 300) # last number is interval in secondssch = Scheduler()
sch(s.schedule)
sch.run_forever()
```