Philips Hue Control From AppleScript (For Use in iCal and Calendar)

UPDATE:I created this entry before an API came along that made all this easier. Some great documentation on how to do all of the below is listed here http://www.developers.meethue.com/documentation/getting-started

The Hue Series LED bulbs from Philips are very hackable and can be controlled via simple HTML Put commands. I have assembled a few things to get you started in some simple preset control via AppleScripts. I’m using this method to create an appointment in Calendar to automatically turn on and off these lights.

Before you start with all this, you should know/set the IP address of your base station. You can set the IP address of your bridge using the Hue app on iOS.  Go to the settings in the Hue app and then click on My Bridge/Network Settings. Turn off the DHCP switch and then set your IP below.  Click Save.

So now that you know your IP address, you’ll need to configure your bridge to accept commands. Go to this site (http://www.developers.meethue.com/documentation/getting-started) and follow the first page of steps up past where you create the user “newdeveloper”.

You’ll need to know which Hue Lamp you wish to control. The order that the lamps appear in the myhue website or the iphone app, is the same order that they are numbered. I’ve put markers into the scripts where you’ll paste and enter this info.

The first script you can use to see what your lamp is doing. This is useful to get the values of the color you have selected through the app that you can then paste those values into the other scripts to recreate the values that you set.  So first, using the app, set your lamp to the desired color and intensity.  After editing the script to include your IP address, API Key, and correct lamp; Run this first script to see the lamp values:

Get Bulb Status

set pollBulb to do shell script "curl http://10.0.1.111/api/newdeveloper/lights/REPLACEWITHLAMPNUMBER"

The important bits you’ll need from this are the Brightness (bri), Hue (hue), and Saturation (sat). Here are some sample values

{\"on\": true,\"bri\": 254,\"hue\": 12813,\"sat\": 219,\"xy\":[0.5196,0.4141],\"ct\":484}

To turn the lamp on at the value you found, you’ll change this next script to reflect what you found:

Lamp On

set turnOn to the quoted form of "{\"on\": true,\"bri\": 254,\"hue\": 15331,\"sat\": 121}"
do shell script "curl --request PUT --data " & turnOn & " http://10.0.1.111/api/newdeveloper/lights/REPLACEWITHLAMPNUMBER/state/"

Finally, here is a script to turn the lamp off:

Lamp Off

set turnOn to the quoted form of "{\"on\": false,\"bri\": 254,\"hue\":15331,\"sat\":121}"
do shell script "curl --request PUT --data " & turnOn & " http://10.0.1.111/api/newdeveloper/lights/REPLACEWITHLAMPNUMBER/state/"

So there ya go. Applescript yourself away.

Source for the above info from http://hackthehue.com/

-j

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.