from time import sleep
from hueclient.api import hue_api
from hueclient.models.light import Light
# examples/blink_light.py
if __name__ == '__main__':
# Make sure we are authenticated with the hue bridge.
# You will be prompted if no username is found in ~/.python_hue
hue_api.authenticate_interactive(app_name='Blink Light Example')
# Get light ID 1
light = Light.objects.get(id=1)
# Loop forever
while True:
# Flip the on state from on -> off / off -> on
light.state.on = not light.state.on
# Save the state back to the bridge
# (Note: required in order for your changes to take effect)
light.state.save()
# Pause here for a couple of seconds to create a slow blink
# (Note: It is important to sleep here at least a little to
# avoid overloading the bridge with API requests)
sleep(2)