I'm trying to write a script that will automatically turn on and off a xiaomi lamp. After installing the library discover_bulbs() works correctly
>>> from yeelight import discover_bulbs
>>> discover_bulbs()
[{'capabilities': {'bright': '50',
'color_mode': '1',
'ct': '2700',
'fw_ver': '45',
'hue': '359',
'id': '0x0000000002dfb19a',
'model': 'color',
'name': 'bedroom',
'power': 'off',
'rgb': '16711935',
'sat': '100',
'support': 'get_prop set_default set_power toggle '
'set_bright start_cf stop_cf set_scene cron_add '
'cron_get cron_del set_ct_abx set_rgb set_hsv '
'set_adjust set_music set_name'},
'ip': '192.168.0.19',
'port': 55443}]
, but after some time it returns an empty list.If you reset the lamp, the lamp is searched again and stops responding after some time.In the application, the lamp works. It also works if you set the lamp’s IP directly (but the lamp changes its IP from time to time). LAN control enabled. The code is presented below.
from yeelight import *
import time
import schedule
# ip=discover_bulbs()[0]['ip']
ip=discover_bulbs()
print(ip)
bulb=Bulb(ip)
def turnOnAt16():
bulb.turn_on()
bulb.set_brightness(100)
bulb.set_color_temp(4100)
def turnOnAt21():
bulb.turn_on()
bulb.set_rgb(255,0,0)
bulb.set_brightness(100)
def main():
schedule.every().day.at('08:00').do(turnOnAt16)
schedule.every().day.at('16:00').do(turnOnAt16)
schedule.every().day.at('21:30').do(turnOnAt21)
schedule.every().day.at('23:00').do(bulb.turn_off)
while True:
schedule.run_pending()
time.sleep(10)
if __name__=='__main__':
main()
How to solve this problem?
I've looked through all the forums. I tried resetting the lamp. Increase the lamp response time.
For me it started not to work properly after a firmware update.
Fixed by doing this:
ip=discover_bulbs()- started working again