This page looks best with JavaScript enabled

Simple triggering of Hue lights from a PC

 ·  ☕ 3 min read · 👀... views

Recently I read an article by my friend about how he connected his Philips Hue lights to software which dimmed his lights when watching a film. I have Hue lights, and this inspired me to solve a different problem - turning on my study light from my computer when it gets dark.

I already use a spare key on my Corsair keyboard to run a custom program - one which puts my computer to sleep. This is possible through the iCUE software which runs in the background and processes customisable triggers. So, the plan is to use the same method with the other spare key to trigger the light turning on.

iCUE Setup

This part is really easy. Inside the software you can simply click on a keyboard key and then set up actions. The image below shows the overview, with the drop-down list of actions displayed. The “Launch Application” action is what we’re after, which does what it says on the tin!

iCUE software, showing an action being configured for the keyboard.

You can then select the path to the application. I am using a batch file, but it is possible to write a python script or compiled program from C/C++/C#/Java etc and run it from here instead.

The contents of the launch application path

Hue API

The HTTP API for Philips Hue is well documented with a great tutorial. Essentially, there is a debug sandbox hosted by the Hue bridge at https://<bridge ip address>/debug/clip.html which lets you explore the API. You will need a key, which can be easily generated via the API itself. The key is then used in the request URL for all subsequent HTTP requests.

Once I ran the command to discover all the lights in the house (which should be three - and it was!), I could then form the correct request to command the light in the study to turn on. I didn’t need to worry about turning it off, as I usually turn all my lights off together using my Google Home voice device in the bedroom. I’m happy using one while I live in the house alone, but as soon as I start living with someone else again I think I will disconnect them as I don’t like the idea of our conversations being analysed.

The correct request for turning on the light was found to be a HTTP PUT request to http://<bridge ip address>/api/<api key>/lights/1/state, with a JSON payload of {"on":true}. The simplest way to send this request on windows was using the cURL command-line program. As of Windows 10, this is included in the operating system installation, so I can call it from a batch file without having to install anything else. The batch file contents is therefore (scroll right to see all)

  curl -X PUT -H "Content-Type: application/json" http://<bridge ip address>/api/<api key>/lights/1/state -d "{\"on\":true}"

which is quite a neat one-liner. It is important to escape the double-quotes in the JSON payload. The cURL command is useful to debug directly in the terminal as the response from the Hue bridge gives information on any errors.

Result

The working button.

This was a simple project which altogether took about half an hour to complete. There is a lot more that you can do with the Hue API, playing with colours and groups of lights. I recommend the lights, as back when I was doing entertainment industry work Philips always had the best LED colour performance, and the Hue range is no exception. I have had them for a year and although they make an ominous whining sound close to the bulb, and are very hot, they seem quite reliable.

Share on

Laurence Stant
WRITTEN BY
Laurence Stant
RF and Electronic Engineer. PhD.