uduncanu / lywsd03mmc

Python library for Xiaomi Mijia LYWSD03MMC sensors
MIT License
57 stars 12 forks source link

Get the data from the BLE advertisements #1

Open jcea opened 3 years ago

jcea commented 3 years ago

Please, support getting the data from the periodic (in my device every 2.5 seconds) advertisements, instead of establishing a BT connection, to keep battery usage low.

uduncanu commented 3 years ago

I'm struggling to find any information about the broadcast data, although I can seem some sources saying that it may be encrypted (which isn't something I've had to deal with so far). Are you aware of any more information about it anywhere?

afer92 commented 2 years ago

View lywsd03mmc fork. With AtcMiThermometerClient you can retrieve thermometers data without connecting. Limitations : can't get firmware and hardware revisions, can't get history.

from lywsd03mmc import AtcMiThermometerClient
# AtcMiThermometerClient(scan_for=15.0, retry=3, debug=False)
client = AtcMiThermometerClient()

client.get_datas()

for thermometer in client.thermometers:
    print('----\n', thermometer) # print all data `)

Result:

Discovered device a4:c1:38:xx:xx:xx
Discovered device a4:c1:38:yy:yy:yy
Device disconnected
Proceed...
Discovered device a4:c1:38:xx:xx:xx
Discovered device a4:c1:38:yy:yy:yy
Received new data from a4:c1:38:xx:xx:xx
----
 mac:   A4:C1:38:xx:xx:xx - ATC_xxxxxx
temp:   22.8 °C
hum:    37 %
batt:   86 %
volts:  2.98 V
rssi:   -54 dB
skip:   False
----
 mac:   A4:C1:38:yy:yy:yy - ATC_yyyyyy
temp:   21.7 °C
hum:    42 %
batt:   88 %
volts:  2.996 V
rssi:   -71 dB
skip:   False
jcea commented 2 years ago

This is nice, @afer92, but it requires a modified firmware.

afer92 commented 2 years ago

This is nice, @afer92, but it requires a modified firmware.

Indeed. The interest of the modified firmware is to preserve the battery. The draw back is the lack of history. To choose is to renounce.

arizzi commented 1 year ago

https://esphome.io/components/sensor/xiaomi_ble.html#obtaining-the-bindkey

afer92 commented 1 year ago

I will have a look, it's a good idea. I use advertissements for miflora sensors (sea device-mqtt.