A short time ago I bought myself a Philips Hue starter pack and installed the three globes in my lounge room.
I must say that I love the way you can set the colour and brightness of these things. Having installed and played with the iPhone app it came to me that I should have a bit of a hack and see what I could do.
My first need was to find a way to turn the lights down as the evening gets late. I thought that would be a nice way to remind myself it was getting late and to think about going to bed.
I decided Python was the way to go since I can run it on both my server, the iPhone and iPad. I discovered a nicely usable library for Python and quickly wrote the required script. Then I just installed it as an item in the root crontab so now the lights get turned down to half power at 10:30 every night. The script required is tiny:
#!/usr/bin/python from phue import Bridge b = Bridge('192.168.1.17') b.set_light([1,2,3], 'bri', 127, transitiontime=300)
Next was to see if I could get the library installed on my iPad and working to do something there. Getting the library on the iPad is not obvious but is simple once you know how.
- Download the library - Unzip - Copy phue.py to Dropbox - Open phue.py on iPad in text editor (Textastic) - Copy entire file - Open Pythonista and create new file - Paste - Change name to 'phue'
Once you’ve done that you now have the library available to import, though Pythonista appears not to support importing just part of a library.
The script I wrote for the iPad allows me to type a number in Drafts and then set the brightness of the Hue to that number:
# set the hue lights to a particular power or half import phue, webbrowser, sys try: brightness = int(sys.argv) except: brightness = 127 b = phue.Bridge('192.168.1.17') b.set_light([1,2,3], 'bri', brightness) webbrowser.open('Drafts://')
This works well. The script above is saved in Pythonista as ‘Hue’ and then I wrote a URL action for Drafts, “pythonista://Hue?action=run&args[[draft]]”. Then I just open a new note, type the number and select the custom action.
On the iPhone I use Launch Center Pro and it’s even neater. In the script above change the open at the end to “launchpro://” then create a URL action. Launch Center Pro knows about Pythonista so create a new action, find Pythonista in the Installed Apps, select “Run Script w/ Arguments”. Change the name to something like “Hue”, set the script name to ‘Hue’ and under Arguments you want an Input Prompt with the Number Pad. Now when you touch the icon in Launch Center Pro it will open up a window with the number pad, you enter a number between 1 (almost off) and 255 (full bright). If you leave it blank it sets the brightness to half power.
My next hack is to come up with a system to set the colour and brightness. There are three modes for defining the colour, hue and saturation, colour temperature and the x and y of a point in the CIE colourspace. After doing some testing it seems that if a bulb is in one mode it will ignore a setting in one of the other two colour modes. This means that you must set the colour mode of the bulb before setting the colour to make sure that it works.
The iPhone app allows you to have a number of presets it calls “scenes” and I would like to do the same thing in Python. To this end I wrote a script to discover the current settings and write them out.
import phue b = phue.Bridge('192.168.1.17') # range over the three lights for i in range(1, 4): print "Light: " + str(i) # Get the color mode of the light [hs|xy|ct] mode = b.get_light(i, 'colormode') bri = b.get_light(i, 'bri') if mode == 'hs': hue = b.get_light(i, 'hue') sat = b.get_light(i, 'sat') print "Mode: " + mode + " Hue: " + str(hue) + " Sat: " + str(sat) + " Bright: " + str(bri) elif mode == 'ct' : colortemp = b.get_light(i, 'ct') print "Mode: " + mode + " ColorTemp: " + str(colortemp) + " Bright: " + str(bri) else: xy = b.get_light(i, 'xy') print "Mode: " + mode + " XY: " + str(xy) + " Bright: " + str(bri)
I’m going to keep on playing and see what more I can discover.
- huectl 0.1 (pypi.python.org)
- How Philips Hue Light Bulbs Are Highly Hackable (gizmodo.co.uk)
- Philips to expand its Hue line with LightStrips and Bloom bulbs (idownloadblog.com)
- Philips Friends of Hue Bloom Lamp (pcmag.com)