Exemple #1
0
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]
        image = image.load()