Get Data from Mi Thermomether using Python
Use Python to get temperature and humidity from Mi thermometer
create a venv and install libraries according to this ‘requirements.txt’
bluepy==1.3.0
lywsd02==0.0.9
lywsd03mmc==0.1.0
code to compute heatindex
import argparse
import lywsd03mmc
parser = argparse.ArgumentParser()
parser.add_argument('mac', help='MAC address of LYWSD02 device', nargs='+')
args = parser.parse_args()
c1 = -8.784_694_755_56
c2 = 1.611_394_11
c3 = 2.338_548_838_89
c4 = -0.146_116_05
c5 = -0.012_308_094
c6 = -0.016_424_827_7778
c7 = 2.211_732e-3
c8 = 7.2546e-4
c9 = -3.582e-6
for mac in args.mac:
try:
client = lywsd03mmc.Lywsd03mmcClient(mac)
print('Fetching data from {}'.format(mac))
data = client.data
print('Temperature: {}°C'.format(data.temperature))
print('Humidity: {}%'.format(data.humidity))
print('Battery: {}%'.format(client.battery))
temperature = data.temperature
RH = data.humidity
HI = c1 + c2 * temperature
HI += c3 * RH + c4 * temperature * RH + c5 * temperature**2
HI += c6 * RH**2 + c7 * temperature**2 * RH
HI += c8 * temperature * RH**2 + c9 * temperature**2 * RH**2
print(f"Heat Index: {HI:.1f}°C")
print()
except Exception as e:
print(e)