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

Outlook for Mac Notification Center New Message Alert

Using MacPorts, there is a program called “Terminal Notifier” that can send alerts to Notification Center in Mountain Lion based off of a command line entry and thus an Applescript. Obviously, you can have a lot of fun with that – but I specifically found it so that I could send a new message alert from Outlook because Microsoft only has such a notification appear on the active desktop and I use several of them in Mission Control. I compiled this information from these sites:

http://osxdaily.com/2012/08/03/send-an-alert-to-notification-center-from-the-command-line-in-os-x/
https://github.com/alloy/terminal-notifier

https://github.com/goosetav/Microsoft-Outlook-Growl-Notifications/blob/master/Register%20Outlook%20with%20Growl.applescript

To get this to work isn’t so bad once you have MacPorts installed, which I’ve referenced earlier.

  • Assuming MacPorts is already installed, run the selfupdate command (also listed in that earlier post).
  • Install Terminal Notifier:
    sudo port install terminal-notifier
  • Download and put this AppleScript into your Documents/Microsoft User Data/Outlook Script Menu Items (you don’t have to put it there, but just for organizational sake, might as well). Sure it says Growl in everything below as that is what I originally used it for but then changed it to accommodate Notification Center instead:Improved Growl New Mail.scpt
  • In Outlook, create a new rule that will run the script based on your criteria. Here’s mine:
    blog_outlookrulesnotificationcenter

That’s all there is to it.

-j