Ejemplo n.º 1
0
def setBulbPower(bulbs, power):
    elapsedTime = 0
    # exit if bulb is already in requested state
    bulbStatePre = lazylights.get_state(bulbs)
    if powerState(bulbStatePre) and power == 1:
        return
    if not powerState(bulbStatePre) and power == 0:
        return
    lazylights.set_power(bulbs, power)
    # wait for status update to ensure action was completed
    while elapsedTime < 5:
        bulbState = lazylights.get_state(bulbs)
        if powerState(bulbState) == power:
            print(getLabels(bulbState) + "Bulbs powered " + ("ON" if power else "OFF"))
            return
        time.sleep(0.5)
        elapsedTime += 1
Ejemplo n.º 2
0
def lightChanger():
    global sliderValue, KELVIN
    global bpm, idName
    global beginBPMSlidder
    #mac and IP MUST be associated by pair
    mac1 = ''
    mac2 = ''
    mac3 = ''
    mac4 = ''
    mac5 = ''
    i = 0
    ip1 = sys.argv[i + 1]
    ip2 = sys.argv[i + 2]
    ip3 = sys.argv[i + 3]
    ip4 = sys.argv[i + 4]
    ip5 = sys.argv[i + 5]

    myBulb1 = createBulb(ip1, mac1)
    myBulb2 = createBulb(ip2, mac2)
    myBulb3 = createBulb(ip3, mac3)
    myBulb4 = createBulb(ip4, mac4)
    myBulb5 = createBulb(ip5, mac5)

    bulbs = [myBulb1, myBulb2, myBulb3, myBulb4, myBulb5]
    # now bulbs can be called by their names
    bulbs_by_name = {
        state.label.strip(" \x00"): state.bulb
        for state in lazylights.get_state(bulbs)
    }
    if (len(bulbs) == 0):
        print(
            "No LIFX bulbs found. Make sure you're on the same WiFi network and try again"
        )
        sys.exit(1)
    # turn on
    lazylights.set_power(bulbs, True)
    # do nothing during a tenth of a second
    time.sleep(0.1)
    # init counters/accumulators
    red = 0
    green = 0
    blue = 0
    redReg = 0
    greenReg = 0
    blueReg = 0
    begin1 = time.time()
    beatLenghtReg = DURATION + 1  # to force it to a state beatLenghtReg not equal to beatLenght
    beginBPM = time.time()
    countBeat = 1
    cReg = Color(rgb=(1, 0, 0))
    global cHue
    cHue = cReg.hue
    sliderValueReg = sliderValue
    # the music changed
    while True:
        graphInterfaceUpdate()
        if bpm != 0:
            beatLenght = SLOW_DOWN * 60000.0 / bpm
        else:
            beatLenght = DURATION

        if beatLenghtReg != beatLenght:
            beginBPM = time.time()
            countBeat = 0
            beatLenghtReg = beatLenght
            print("music changed BPM is now: ", bpm,
                  " track name from spotify is ", idName)
        # no music is playing (e.g. pause or just only watching youtube music)
        elif (beatLenght == DURATION):  #i.e. bpm == 0

            cHue += 0.01
            time.sleep(
                0.2
            )  # 20 wifi commands per seconds, can be increased if no checking
            lazylights.set_state(bulbs, (cHue + 0.5) * 360, 1, 1, KELVIN, 200,
                                 False)
            # LIFX 246D45
            lazylights.set_state(bulbs, cHue * 360, 1, 1, KELVIN, 200, False)
            #print(cHue)
        # 31ea4e
        # while music is playing
        else:
            #if sliderValue != sliderValueReg
            beginBPMSlidder = beginBPM + 2 * sliderValue * beatLenght / 100000  #slider value is 0->100
            #print("beginBPMSlidder", beginBPMSlidder)

            #sliderValueReg = sliderValueReg
            # this is the same music
            a = (beatLenght / 1000) - (time.time() -
                                       beginBPMSlidder) % (beatLenght / 1000.0)
            a = max(0, a)
            time.sleep(a)  # should not sleep if 0
            countBeat += 1
            red = random.uniform(0, 1)
            #find RGB that is not looking the same as the previous RGB
            while abs(red - redReg) < 0.15:
                red = random.uniform(0, 1)
            while abs(blue - blueReg) < 0.15:
                blue = random.uniform(0, 1)
            while abs(green - greenReg) < 0.15:
                green = random.uniform(0, 1)

            c = Color(
                rgb=(red, green, blue)
            )  # display a random color but sufficently different from the previous one

            # on even numbers, first lifx is light on
            if countBeat % 2 == 0:
                lazylights.set_state(bulbs, cReg.hue * 360, cReg.saturation,
                                     INTENSITY, KELVIN, 0, False)
            # on odd numbers it is the other one
            else:
                cReg = c
                redReg = red  # save each previous color
                blueReg = blue
                greenReg = green
                lazylights.set_state(bulbs, c.hue * 360, c.saturation,
                                     INTENSITY, KELVIN, 0, False)
Ejemplo n.º 3
0
p = poller()

# Set up our singleton listener for UPnP broadcasts
u = upnp_broadcast_responder()
u.init_socket()

# Add the UPnP broadcast listener to the poller so we can respond
# when a broadcast is received.
p.add(u)

hue = None

bulbs = lazylights.find_bulbs(timeout=1)
if len(bulbs) > 0:
    hue = fauxhue("Fauxhue", u, p, None, 0)
    bulbstate = lazylights.get_state(bulbs)
    for bulb in bulbstate:
        bulbname = str(bulb.label)
        bulbname = bulbname.rstrip('\x00')
        hue.add_bulb(bulbname, state=bool(bulb.power), brightness=(255 * bulb.brightness / 255), action_handler = lifx_api_handler(), private=bulb)

env = Environment()
env.start()
env.discover(10)
for bridgename in env.list_bridges():
    bridge = env.get_bridge(bridgename)
    if len(bridge.Lights) > 0 and hue == None:
        hue = fauxhue("Fauxhue", u, p, None, 0) 
    for lightname in bridge.Lights.keys():
        light = bridge.Lights[lightname]
        lightdata = {'bridge': bridge, 'light': lightname}
Ejemplo n.º 4
0
    import Queue as queue
except ImportError:
    import tkinter as tk
    import queue as queue

LIFX_CONNECT = True

global top
global LAST_UPDATE

MIN_REFRESH_INTERVAL = 0.5
LAST_UPDATE = 0
lastUpdateTimestamp = 0

bulbs = lazylights.find_bulbs(expected_bulbs=1, timeout=10)
print "Found bulb(s): ", bulbs, "\nState", lazylights.get_state(bulbs,
                                                                timeout=5)

MAXIMUM = 40.0
buffSize = 30

top = tk.Tk()
#top.attributes("-fullscreen", True)
top.configure(background='black')
w, h = top.winfo_screenwidth() / 1.25, top.winfo_screenheight() / 2.
#top.overrideredirect(1)
top.geometry("%dx%d+0+0" % (w, h))
top.focus_set()

top.bind('<Escape>', lambda e: e.widget.quit())  # top.destroy())

Ejemplo n.º 5
0
 def __init__(self):
     self.bulbs = lazylights.find_bulbs()
     states = lazylights.get_state(self.bulbs)
     if states:
         self.initial_state = BulbState(states[0])  # being lazy, we'll just use the first bulb's state
         self.current_state = BulbState(states[0])
Ejemplo n.º 6
0
p = poller()

# Set up our singleton listener for UPnP broadcasts
u = upnp_broadcast_responder()
u.init_socket()

# Add the UPnP broadcast listener to the poller so we can respond
# when a broadcast is received.
p.add(u)

hue = None

bulbs = lazylights.find_bulbs(timeout=1)
if len(bulbs) > 0:
    hue = fauxhue("Fauxhue", u, p, None, 0)
    bulbstate = lazylights.get_state(bulbs)
    for bulb in bulbstate:
        bulbname = str(bulb.label)
        bulbname = bulbname.rstrip('\x00')
        hue.add_bulb(bulbname,
                     state=bool(bulb.power),
                     brightness=(255 * bulb.brightness / 255),
                     action_handler=lifx_api_handler(),
                     private=bulb)

env = Environment()
env.start()
env.discover(10)
for bridgename in env.list_bridges():
    bridge = env.get_bridge(bridgename)
    if len(bridge.Lights) > 0 and hue == None:
Ejemplo n.º 7
0
# I use this to manually create a bulb using IP and MAC address.
def createBulb(ip, macString, port=56700):
    return lazylights.Bulb(b'LIFXV2',
                           binascii.unhexlify(macString.replace(':', '')),
                           (ip, port))


# ------------------------------------------------------------------------------------------------------------

# Scan for 2 bulbs
bulbs = lazylights.find_bulbs(expected_bulbs=2, timeout=5)
print(bulbs)
# now bulbs can be called by their names
bulbs_by_name = {
    state.label.strip(" \x00"): state.bulb
    for state in lazylights.get_state(bulbs)
}
# set([
# Bulb(gateway_mac='LIFXV2', mac='\xd0s\xd51\xeaN', addr=('192.168.0.12', 56700)),
# Bulb(gateway_mac='LIFXV2', mac='\xd0s\xd5$mE'   , addr=('192.168.0.14', 56700))
# ])

if (len(bulbs) == 0):
    print(
        "No LIFX bulbs found. Make sure you're on the same WiFi network and try again"
    )
    sys.exit(1)

# turn on
lazylights.set_power(bulbs, True)
# do nothing during a tenth of a second