lywsd03mmc
lywsd03mmc copied to clipboard
Return battery voltage, too
Please extend the structure SensorDataBattery with the voltage of the battery. The value is already present in the code, but it is not returned in SensorDataBattery.
def _process_sensor_data(self, data):
temperature, humidity, voltage = struct.unpack_from('<hBh', data)
temperature /= 100
voltage /= 1000
# Estimate the battery percentage remaining
battery = min(int(round((voltage - 2.1),2) * 100), 100) # 3.1 or above --> 100% 2.1 --> 0 %
self._data = SensorDataBattery(temperature=temperature, humidity=humidity, battery=battery)
Thanks
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
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