Phue Examples


It is quite easy to control your Hue lights using the Hue API. I use the Phue Python library. This library makes it easy to control your lights. Besides the standard on/off, you'll be able to easily group your lights and control them without having to rely on a "scene" or picture.

To use phue you need Python.

Once you have Python installed, you will need to download the phue library. I used pip for this:

python -m pip install phue

A link to the Phue GetHub.

Python and Phue in action:

Code Example:

from phue import Bridge
import time

#replace "IP HERE" with the IP of your bridge. Leave the single quotes as is.

b = Bridge(IP)

#test command. Gets the info for light number 3. Prints the details
test = b.get_light(3)

print (test)

#additional command examples:
#uncomment out and change to test. I'd recommend commenting out the "test = ..." and "print..." statements above if you do so.

#Creates group 'All'.

#Tun of lights 10 and 28
#b.set_light([10,28], 'on', False)

#create group 'lights', ID number '5', using lights 2,5,6,7,12,28
#b.set_group(5, 'lights',[2,5,6,7,12,28])

#get information for group ID 4
#test = b.get_group(4)

#turn on the all lights in group 1
#b.set_group(1, 'on', True)

#sleep one second.

#Set multiple values at one time:
#the command that will be executed is 'command_on2' in this case.
#sets transition time to 0, turns the light on, and sets brightness to 125
#command_on2 = {'transitiontime' : 0, 'on' : True, 'bri' : 125}

#executing the command:
#b.set_light(30, command_on2)

#Multiple value example with color:
#sets transition time to 0, turns lights on, sets color to a specific color.
#command_on2 = {'transitiontime' : 0, 'on' : True, 'xy' : [0.1768, 0.0557], 'sat' : 243, 'hue' : 47050}

#the command is run for group ID 5
#b.set_group(5, command_on2)

This is an AmazingR4b Production.