Skip to content

Instantly share code, notes, and snippets.

@gidj
Last active October 6, 2016 16:34
Show Gist options
  • Save gidj/ca2ecde509b4c04189392b151d51b173 to your computer and use it in GitHub Desktop.
Save gidj/ca2ecde509b4c04189392b151d51b173 to your computer and use it in GitHub Desktop.
LifxBulb Example
import pylifx
""" First you need to create a controller object using the controller group address """
controller_group_address = "MAC Address of controller group goes here"
gateway_controller = pylifx.LifxController(site_addr=controller_group_address)
""" Now, you have two options: controlling it via the gateway_controller object created above using the MAC address of the
bulb itself, or creating an individual LifxBulb object and controlling it directly.
The first way:"""
# You first have to call the find_bulbs method to populate the list of all bulbs (this may or may not have to be called, there is some work being done in another module I don't want to dig into):
gateway_controller.find_bulbs()
# Then you can control a particular bulb via its own MAC Address:
bulb_address = "MAC Address of an individual bulb goes here"
# Turns the bulb on
gateway_controller.on(bulb_addr=bulb_address)
# and this turns it off
gateway_controller.off(bulb_addr=bulb_address)
""" This is the second way, in case you want to create your own LifxBulb objects and control them directly,
instead of via a method on the controller. You still need to have created the gateway_controller,
as it should be the first argument to your LifxBulb object: """
# Same as before:
controller_group_address = "MAC Address of controller group goes here"
gateway_controller = pylifx.LifxController(site_addr=controller_group_address)
# Create a LifxBulb object:
bulb_address = "MAC Address of an individual bulb goes here"
individual_bulb = pylifx.LifxBulb(gateway_controller, bulb_addr=bulb_address)
# Now you can turn the bulb on and off directly:
individual_bulb.on()
individual_bulb.off()
# or change its color, yada yada yada:
individual_bulb.set_rgb(255, 255, 255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment