Using Applescript and cURL to control your Philips Hue lighting system

I see that you can control the Philips Hue backlight with commands such as:

Make an HTTP POST request for the following (your hue website)

{"username": "YourAppName", "devicetype": "YourAppName"} If you did not click the button on the Hue Hub, you will get this error:

{"error": {"type": 101, "address": "/", "description": "link button not pressed"}} Click the link button on the hub and try again, and you should get;

{"success": {"name": "key"}} The key above will be the line md5, remember this, you will need this in all future requests

- but I'm not sure how to use Applescript to speak this language - I know that you can use the "do shell script" and maybe cURL there, but, I'm really falling apart for the code to work correctly.

Any thoughts?

+4
source share
3 answers

For a shell script, try the following:

curl -d "{\"username\": \"yourname\", \"devicetype\": \"yourhuename\"}" [not a link]http://hueIpAddr/api 
+1
source

I managed to get my python script to use a curl request to control lights through subprocess (which I think looks like a shell script) using:

 curl --request PUT --data \'{"on":true, "xy":[0.4370,0.3706],"bri":255}\' http://{url}/api/{username}/lights/1/state 

To create a user with a twist, you probably should change the code to look like this:

 curl --request POST --data \'{"devicetype":"your_devicetype", "username":"your_username"}\' http://{url}/api/ 

To be fair, I have not tried this with curl since I am working on switching to urllib2 in python. Hope this helps.

+1
source

Another shell script with a useful function for setting color through HSB and transition time.

 #!/bin/sh # # Register "patniemeyer" key with this bridge # # % curl -d '{"username": "patniemeyer", "devicetype": "Philips hue"}' http://192.168.1.179/api # [{"success":{"username":"patniemeyer"}}] # KEY='patniemeyer' IP='192.168.1.179' # # Light number, hue, saturation, brightness, transition time # # hue 0-65535 # sat 0-255? # transition time 1/10 seconds # lightNHSBT() { _lightNum=$1 _hue=$2 _sat=$3 _brightness=$4 _ttime=$5 curl --request PUT --data "{\"hue\":$_hue, \"sat\":$_sat, \"bri\":$_brightness, \"on\":true, \"transitiontime\":$_ttime}" http://$IP/api/$KEY/lights/$_lightNum/state/ } # # CIE 1931 X,Y colors # Light number, X, Y, brightness, transition time # # transition time 1/10 seconds # lightNXYBT() { _lightNum=$1 _x=$2 _y=$3 _brightness=$4 _ttime=$5 curl --request PUT --data "{\"xy\":[$_x,$_y], \"bri\":$_brightness, \"on\":true, \"transitiontime\":$_ttime}" http://$IP/api/$KEY/lights/$_lightNum/state/ } # for f in 1 2 3 4 5 6 do lightNHSBT $f 0 255 255 5 # full red done 
0
source

Source: https://habr.com/ru/post/1445170/


All Articles