import serial import requests import time from app import yeelight bulbs = { "fernseher" : { "ip" : "192.168.178.127" }, "regal" : { "ip" : "192.168.178.128" }, "monitor" : { "ip" : "192.168.178.126" }, "bett" : { "ip" : "192.168.178.122" } } yeelight = yeelight.Yeelight(bulbs) ser = serial.Serial('/dev/ttyUSB0', 9600) while 1 : out = '' while ser.inWaiting() > 0: out = str(ser.readline()) if out != '': l = list(out) try: del(l[0]) del(l[0]) del(l[2]) del(l[2]) del(l[2]) del(l[2]) del(l[2]) out = "".join(l) #print("try") except: print("Fehlerhafter Wert") finally: print(out) # Taste 3 if(out == "31"): # Abend yeelight.color(0,0,255) if(out == "30"): # Nacht yeelight.temperature(1700) yeelight.brightness(1) # Taste 4 if(out == "41"): # Hell yeelight.brightness(100) if(out == "40"): # Dunkel yeelight.brightness(1) # Taste 5 if(out == "51"): # An yeelight.power("on") if(out == "50"): # Aus yeelight.power("off") time.sleep(.250)