Skip to content

Instantly share code, notes, and snippets.

@MFedyukov
Last active May 27, 2022 20:46
Show Gist options
  • Save MFedyukov/0e7288c35cddcf3708e1b8e741ccb0f9 to your computer and use it in GitHub Desktop.
Save MFedyukov/0e7288c35cddcf3708e1b8e741ccb0f9 to your computer and use it in GitHub Desktop.
Change Yeelight color temperature and brightness depending on the time of day. Set this script to be called upon an event of Yeelight appearance in your local network, using a syslog server with message processing functionality (e.g. https://sourceforge.net/projects/syslogserverwindows/) or using a network monitor (e.g. https://www.paessler.com/…
import datetime as dt
import socket
host = '192.168.0.99'
port = 55443
yeelightPresetDay = b'{"id":1, "method":"set_scene", "params":["ct", 4000, 100]}\r\n'
yeelightPresetEvening = b'{"id":1, "method":"set_scene", "params":["ct", 3060, 63]}\r\n'
yeelightPresetNight = b'{"id":1, "method":"set_scene", "params":["ct", 2700, 1]}\r\n'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
h = dt.datetime.now().hour
#m = dt.datetime.now().minute
if h > 6 and h < 17:
s.sendall(yeelightPresetDay)
elif h >= 17 and h < 20:
s.sendall(yeelightPresetEvening)
else:
s.sendall(yeelightPresetNight)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment