Need a little help writing scripts for the LifxLAN Python Library

Hi there,

I am trying my hand at building a manual switch for my Lifx bulbs using a raspberry pi, a USB numpad and assigning shortcuts to python scripts for each of the keys using @mclarkk 's LifxLAN. All other solutions that use the Lifx Cloud account are way too slow (5-10 seconds from command to action).

I am running Linux in a virtual machine first to make sure that the scripts work before I go out and buy the raspberry pi. But as this is my first time doing anything like this, I am struggling to wrap my head around some of it.

I am trying to address specific bulbs, if I can work that out then the rest should be too hard because the scripts I need won’t be too complicated (on/off, set brightness, set temperature of specific bulbs).

Here is what I have so far:

from lifxlan import *

lifxlan = LifxLAN()
dining = Light("##:##:##:##:##:##", "###.###.###.###")

lifxlan.dining.set_power("off", rapid=True)

And it is returning

Attribute Error: LifxLAN instance has no attribute 'dining'

I am probably way off but any help would be greatly appreciated!
Cheers,
Kristian

You’re on track! Try:

dining.set_power("off", rapid=True)

In fact, you don’t need the line lifxlan = LifxLAN() at all, unless you plan to use one of the following LifxLAN object methods:

get_lights()                                          
set_power_all_lights(power, [duration], [rapid])      
set_color_all_lights_color(color, [duration], [rapid]) 
get_power_all_lights()                             
get_color_all_lights()   

If you’re just controlling the dining light, rather than broadcasting to all lights, you only need the Light object.

You should also be able to get away with leaving off the “rapid=True” flag. That option is mostly useful if you’re making a bunch of rapid changes, like in a fast light show. If you’re turning the lights on and off like you would with normal light usage, you should be okay without it.

The final program would look like:

from lifxlan import Light

dining = Light("##:##:##:##:##:##", "###.###.###.###")
dining.set_power("off")
1 Like

Perfect! Works like a charm. Nothing like that feeling of hitting enter and the light changes without any errors.

Thanks for that! Now I just have to write out all of my scripts, buy a cheap USB numpad and work out how to launch the scripts with it.