Author Topic: How to send PUT HTTP command to Philips Hue bridge ?  (Read 368 times)

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
How to send PUT HTTP command to Philips Hue bridge ?
« on: August 28, 2017, 06:57:09 am »
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: http://HUEBRIDGEIP/api/HUEBRIDGEUSER/lights/1/state
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.

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #1 on: August 28, 2017, 07:59:44 am »
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:

Code: [Select]
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.

Code: [Select]
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.

Code: [Select]
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.

Code: [Select]
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.



Offline Bill Scruggs

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +4/-0
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #2 on: August 28, 2017, 08:28:09 am »
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.

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #3 on: August 28, 2017, 08:36:36 am »
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.

Thank you so much I think this will work fine.

Let me test it out a bit.

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #4 on: August 28, 2017, 08:45:22 am »
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.

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #5 on: August 28, 2017, 09:14:15 am »
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

Code: [Select]
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.

Offline cw-kid

  • Hero Member
  • *****
  • Posts: 1247
  • Karma: +7/-2
    • Phaze1 Digital
Re: How to send PUT HTTP command to Philips Hue bridge ?
« Reply #6 on: August 28, 2017, 09:40:16 am »
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.

Code: [Select]
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.