def set_light_name(ip, light_model, light_id): print("Name not defined for Yeelight {}, ID: {}".format(light_model, light_id)) # Identify light for user try: bulb = Bulb(ip) bulb.turn_off() bulb.effect = "sudden" bulb.turn_on() bulb.set_brightness(100) bulb.set_rgb(0, 0, 255) bulb.effect = "smooth" bulb.duration = 10000 bulb.set_rgb(255, 0, 0) except: print( "Communication failed with Yeelight {}, ID: {}".format( light_model, light_id ) ) return "" # Get user input for light name print("This device will change color from blue to red over 10 seconds.") print("Enter name for this device or press enter to skip it:") input_char = input() if input_char == "": try: bulb.turn_off() except: print( "Communication failed with Yeelight {}, ID: {}".format( light_model, light_id ) ) return "" return "" # Set light name device_name = input_char try: bulb.set_name(device_name) except: print( "Communication failed with Yeelight {}, ID: {}".format( light_model, light_id ) ) return "" return device_name
from PIL import ImageGrab import time import os import colorsys DECIMATE = 10 #increase this to reduce the computational requirments try: bulb.turn_on() except: print('Unable to connect to bulb. Please check the IP address.') exit() bulb.start_music() bulb.effect = "sudden" bulb.duration = 200 old_hsv = [1, 1, 1] while True: a = time.time() red = 1 green = 1 blue = 1 try: image = ImageGrab.grab() width = image.size[0] height = image.size[1]
from yeelight import LightType from yeelight import Bulb import time import speedtest bulbleft = Bulb("192.168.x.x", effect="sudden", duration=1000, auto_on=True) #Bulb on the left side of the kitchen. This will be used for upload speeds bulbright = Bulb("192.168.x.x", effect="sudden", duration=1000, auto_on=True) #Bulb on the right side of the kitchen. This will be used for download speeds bulbright.effect = "sudden" bulbleft.effect = "sudden" servers = [] def test(): s = speedtest.Speedtest() s.get_servers() s.get_best_server() s.download() s.upload() res = s.results.dict() return res["download"], res["upload"], res["ping"] d, u, p = test() dkbps = d / 1024 dmbps = dkbps / 1024 ukbps = u / 1024 umbps = ukbps / 1024 bulbright.turn_on() bulbleft.turn_on() print(f'Download speed un-rounded and rounded:\n{dmbps}') print(round(dmbps)) print(f'Upload speed un-rounded and rounded:\n{umbps}') print(round(umbps)) if 0 < dmbps < 2: #If download speed is below 2mbps, set the bulb color to red. bulbright.set_rgb(255, 0, 0)