Applescript for Tradfri bulbs on Hue Bridge

hey gang…

I set up 9 new tradfris on my hue bridge yesterday and all work great when using iOS apps to change colors, run routines, etc…

however, I also script for my bulbs and im noticing the tradfris do not react the same… using this script to change a bulb color…

global BridgeAddress
global apiKey
set BridgeAddress to "192.168.1.9"
set apiKey to "newdeveloper"
global turnOn
set turnOn to the quoted form of "{\"on\": true,\"hue\":47125, \"sat\": 253,\"bri\":10,\"transitiontime\": 30}"
do shell script "curl --request PUT --data " & turnOn & " http://" & BridgeAddress & "/api/" & apiKey & "/lights/15/state/"

… the tradfri bulbs will turn on and brightness will be affected, but the colors “hue” do not change … rather they retain their last color…
can any one help ? is there a parameter I’m leaving out?

thanks!

IKEA TRÅDFRI lights do not support hue/sat commands. You will need to use XY instead.

When you choose a colour in Hue Essentials it should show the XY values that you can use. Once you have the XY values, your request body needs to look something like this:

{"on":true,"xy":[0.17,0.06],"bri":10,"transitiontime":30}

Now you might notice that either the brightness or colour does not change. This is because of another issue with the IKEA lights, they do not always understand multiple values in one command (brightness + colour). If that happens in your case, would need to send two separate commands, one with the brightness, and another one with the colour.

extremely helpful! - will work with this tonight - thanks!

ok - “xy” works great for ikea and keeping “hue” for hue…
…since I have your attention, I’ve always had questions about transition time - I can’t seem to get this parameter to work - for instance if I want the lights to come top to a certain color and brightness over a 5 minute period of time, wouldn’t [“transition time”: 300000] (5mins expressed in MS) do the trick?.. it doesn’t - 300000 isn’t even an allowed value - any help here?

Great to hear you have it working.

The transitiontime is not in milliseconds but a multiple of 100ms. The default value for transitiontime is 4 (which is 400ms = 0.4 seconds). So for example if you would like your lights to fade for 5 minutes, the value would need to be 3000.

This is mentioned in the Hue API documentation as well: Login - Philips Hue Developer Program