Lazylights is a Python API for controlling Lifx bulbs.
- Python 2
- One or more Lifx bulbs, updated to the 2.0 firmware
To install,
pip install git+https://github.com/mpapi/lazylights
Then, in Python,
import lazylights
import time
bulbs = lazylights.find_bulbs(expected_bulbs=2)
lazylights.set_power(bulbs, True)
time.sleep(1)
lazylights.set_power(bulbs, False)
Lazylights provides no-dependencies Python module with a minimal API for interacting with Lifx bulbs. Before the 2.0 firmware update, discovering and controlling bulbs was more complex than it is now, and this module had a lot more in it. Now, there are four core functions:
-
find_bulbs(expected_bulbs=None, timeout=1)
This discovers bulbs on your local network. It returns a set of
Bulb
objects once it's foundexpected_bulbs
ortimeout
seconds have elapsed (whichever comes first). -
get_state(bulbs, timeout=1)
Takes a sequence of
Bulb
objects and returns a list ofState
objects, which you can inspect to find the current parameters for each bulb.It returns as soon as it has received state from each of
bulbs
ortimeout
seconds have elapsed (whichever comes first). -
set_state(bulbs, hue, saturation, brightness, kelvin, fade, raw=False)
Takes a sequence of
Bulb
objects and sets their state:hue
is an integer from 0 to 360, where 0/360 is redsaturation
is a float from 0 to 1, where 1 is fully saturated; if 0, andkelvin
is set, uses the whiteness scale instead of colorsbrightness
is a float from 0 to 1, where 1 is brightestkelvin
is an integer from 2000 (warmest) to 8000 (coolest)fade
is a transition time in milliseconds, where 0 is instantraw
, if True, uses raw values for hue, saturation, and brightness -- integers from 0 to 65535
-
set_power(bulbs, is_on)
Takes a sequence of
Bulb
objects and turns them on or off.
Lazylights does not currently support any kind of remote access through the Lifx Cloud, though I have been using an SSH tunnel for this purpose for many months, with great success.
There currently are no public higher-level functions, or a command-line interface, though it's likely that those will be added over time (especially the latter).
pip install -r dev_requirements.txt
flake8 *.py && nosetests
The lifxjs
Protocol wiki page was particularly helpful in
the creation of this package.
Licensed under the MIT license. See the LICENSE file for the full text.