1#!/usr/bin/python
2
3from phue import Bridge
4
5b = Bridge('ip_of_your_bridge')
6
7# If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
8b.connect()
9
10# Get the bridge state (This returns the full dictionary that you can explore)
11b.get_api()
12
13# Prints if light 1 is on or not
14b.get_light(1, 'on')
15
16# Set brightness of lamp 1 to max
17b.set_light(1, 'bri', 254)
18
19# Set brightness of lamp 2 to 50%
20b.set_light(2, 'bri', 127)
21
22# Turn lamp 2 on
23b.set_light(2,'on', True)
24
25# You can also control multiple lamps by sending a list as lamp_id
26b.set_light( [1,2], 'on', True)
27
28# Get the name of a lamp
29b.get_light(1, 'name')
30
31# You can also use light names instead of the id
32b.get_light('Kitchen')
33b.set_light('Kitchen', 'bri', 254)
34
35# Also works with lists
36b.set_light(['Bathroom', 'Garage'], 'on', False)
37
38# The set_light method can also take a dictionary as the second argument to do more fancy stuff
39# This will turn light 1 on with a transition time of 30 seconds
40command = {'transitiontime' : 300, 'on' : True, 'bri' : 254}
41b.set_light(1, command)