Xiaomi_BLE_Temperature_Display_for_HA
Xiaomi_BLE_Temperature_Display_for_HA copied to clipboard
Error in set_address()?
I have four LYWSD03MMC. The last one was always read twice without delay between. I changed this:
# roll around to the next device address
def set_address():
global address_ctr, addresses, adress
address_ctr += 1
if address_ctr > len(addresses):
address_ctr = 0
adress = addresses[address_ctr]
To this:
# roll around to the next device address
def set_address():
global address_ctr, addresses, adress
address_ctr += 1
if address_ctr > len(addresses)-1:
address_ctr = 0
adress = addresses[address_ctr]
And now it reads last sensor only once and after delay starts from 1st one again. I think >= does the same.
I also made some changes to get more clear topics:
# send mqtt
if adress == 'a4:c1:38:aa:aa:aa':
topic = base_topic + 'T1'
elif adress == 'a4:c1:38:bb:bb:bb':
topic = base_topic + 'T2'
elif adress == 'a4:c1:38:cc:cc:cc':
topic = base_topic + 'T3'
elif adress == 'a4:c1:38:dd:dd:dd':
topic = base_topic + 'T4'
else:
topic = base_topic + adress.replace(':','')
print ('Topic',topic)
And retain so I get the newest readings to my phone without wait:
publish.single(topic, message, retain=True, hostname=hostname)
Great program, easy to use. Thank you!