How to send PUT HTTP command to Philips Hue bridge ?

Hello

I have a gen 1 Philips Hue bridge connected to two LED strip lights.

I would like to be able to turn on / off the Color Loop effect via a Vera scene.

However the Philips Hue bridge using a Rest API and requires the PUT method and a message body.

How can I do this in LUA code in a Vera scene ?

Target: [b]http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state[/b]
Method: PUT (POST doesn’t seem to work)
Content Type: application/json
Message Body: {“effect”:“colorloop”} Starts the Color Loop and {“effect”:“none”} Stops the Color Loop

I’ve searched the forums but was unable to find anything that really helped me.

Many thanks.

I found this webpage here about controlling Philips Hue via command line using CURL.

This command turns on the light strip sets it to full brightness and starts the Color Loop effect:

curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":255,"effect":"colorloop"}' http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state

This command turns off the light strip.

curl -H "Accept: application/json" -X PUT --data '{"on":false}' http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state

Or this command just stops the Color Loop but leaves the light still turned on.

curl -H "Accept: application/json" -X PUT --data '{"effect":"none"}' http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state

All the above command lines work from my PC using Curl command prompt.

I thought you could use os.execute to use Curl on Vera?

e.g.

os.execute('curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":255,"effect":"colorloop"}' http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state')

But it doesn’t seem to work for some reason.

I also read using os.execute might not be the best idea anyway and can cause problems on Vera.

I pulled this out from some of my old notes.

luup.call_action(“urn:micasaverde-com:serviceId:PhilipsHue1”, “SetHueAndSaturation”, {Hue=“64879”;Saturation=“253”;Effect=“colorloop”}, 248)

Replace the 248 with your device ID.

[quote=“Bill Scruggs, post:3, topic:197048”]I pulled this out from some of my old notes.

luup.call_action(“urn:micasaverde-com:serviceId:PhilipsHue1”, “SetHueAndSaturation”, {Hue=“64879”;Saturation=“253”;Effect=“colorloop”}, 248)

Replace the 248 with your device ID.[/quote]

Thank you so much I think this will work fine.

Let me test it out a bit.

Using that luup.call_action, it does indeed start the color loop effect ;D

However the brightness of the LED strip is quite low when the light strip is turned on using this command.

But its a start, I will see if I can tweak the command a bit and add in the “bri”:255 somehow for full brightness etc.

Thanks again.

It seems this part of the command {Hue=“64879”;Saturation=“253”} turns the color red before starting the color loop effect.

Wonder how you work out the Hue and Saturation numbers for other static colors ?

For example you can run this command with Effect=“colorloop” part taken out of the command

luup.call_action("urn:micasaverde-com:serviceId:PhilipsHue1", "SetHueAndSaturation", {Hue="64879";Saturation="253"}, 151)

And it turns on the light strip and sets the colour to static red etc.

Anyhow back to the Color Loop, I now have this Vera scene working OK.

In the “Also, execute the following Luup code” section of the scene, I have two luup.call_action calls, one to first turn the brightness of the LED strip up to 100% and then the second to start the Color Loop effect.

luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"},151) luup.call_action("urn:micasaverde-com:serviceId:PhilipsHue1", "SetHueAndSaturation", {Hue="64879";Saturation="253";Effect="colorloop"}, 151)

This seems to be working well now.