26 December, 2015

Intrduction to the Philips HUE API

The first impressions using the app from Philips was nice. But even better: there are tons of apps out there. Even better: you can hack your own interface using the fine API from Philips. Here are some starting points:

Json
You can program Philips Hue via the Json based API and methods like GET, POST and PUT. The bridge has a nice API interface on:

http://192.168.0.xyz/api/YOUR-NUMBER-HERE/lights/1/state

Here you'll get a testing GUI to use when experimenting with the API methods.

Experiment with JavaScript and Json

Copypasted a json sample from W3 Schools, and console.logged the result. Surprisingly the console got the json object.

console.log result
From this I should be able to figure out how to write the content to the screen.


Python: Idle session




Python 2.7.9 (default, Apr  2 2015, 15:33:21)
[GCC 4.9.2] on linux2

>>> import requests
>>> import json

>>> taend = json.dumps({"on":False})

>>> r = requests.put("http://192.168.0.xxx/api/your-secret-code/groups/0/action", data=taend)

All lamps went out out, so a success it was.

Bash Experiment

curl -X PUT -d "{\"on\":true}" http://192.168.0.xxx/api/your-secret-code/groups/0/action

Since it's possible to use curl in PHP the same thing must be possible in PHP.


No comments: