[SOLVED] Issue using webhooks with Philips Hue lights and Photon

I’ trying to write some simple firmware that will control my Philips Hue lights in the house using a Photon. The way I want to approach this is by using a web hook with the JSON code required by the Philips Hue API.

Here’s what my web hook looks like:

    "event": "hue_command",
    "url": "http://hueserver/api/user/lights/3/state",
    "requestType": "PUT",
    "json": {

      "on": false

Here, the hueserver and user are specific to my setup.

Now here’s how my Photon firmware looks like:

 String value = "false";

void setup()


void loop()
  Serial.print("\nGetting ready to send...\n");

  Spark.publish("hue_command", value, 60, PRIVATE);

  Serial.print("\nLight command sent...");


So everything compiles and flashes to the Photon correctly. The web hook is created successfully. In serial monitor everything looks good, but when the command is sent, I get a response that basically says the command is not properly formatted.

particle subscribe mine

here’s what I get:

{"name":"hook-response/hue_command/0","data":"[{\"error\":{\"type\":7,\"address\":\"/lights/3/state/on\",\"description\":\"invalid value,  false }, for parameter, on\"}}]","ttl":"60","published_at":"2015-09-18T18:44:53.736Z","coreid":"\u0000\u001b�c+"}

So apparently my command is not formatted properly when it is being received by my Hue bridge.

The weird part is that according to the Philips Hue API everything is being sent correctly.

Here’s how the Philips Hue API says the command should be formatted:

URL: http://<bridge ip address>/api/username/lights/1/state
Body: {"on":false}
Method: PUT

Everything checked out, but the command is not received properly…something must be changing along the way, and I cannot figure out what…

Any ideas?

Thank you in advance for your input.


Sorry guys, it was human error…

The webhook posted here is correct…and that’s how it should be…

However I probably got mixed-up somewhere, and what I was creating as a webhook did not look like the webhook posted here. :unamused:

:point_right: IMPORTANT:

Managed to learn something new. When trying to send commands to your Philips Hue bridge…You CANNOT use passed on variables in your webhook, such as "{{SPARK_EVENT_VALUE}}", because this will send the Philips Hue command in quotations.

Received data [b'{"on":"true"}']

The Hue bridge WILL return an error of the “unknown command” sort if you use "{{SPARK_EVENT_VALUE}}", so don’t. :eyes:

The solution is to create a webhook that has the command that you want to send in it (like the one in this post). Thus, if you want to change the command you have to use a different webhook. :ok_hand:

At the same time, the Spark.publish() command can be re-written like:

Spark.publish("webhook_name");   //where webhook_name is the name of your webhook

:point_up: Also worth mentioning, "noDefaults":true is a must. As without it the webhook will inject additional data from your Spark.publish call into your request (just as mentioned in the webhook documentation). So, this will send extra parameters to the Hue bridge which will result in an error being received back.

That’s it. I hope that this helps other people who are trying to control their Philips Hue Lights with their Photon/Core.

OH! “One more thing…”

While trying to troubleshoot why i wasn’t able to control my Philips Hue Lights, i reached out to my cousin, who is in my humble opinion a “world class programmer” !!

He made this server app in Python that can be used to troubleshoot HTTP requests.

So, if you guys need to see how your HTTP request looks like at the other end…give this a try!

Here’s a link to the GitHub repository loggingServer

When this app is run, and we send the request to it, the output looks something like this:

Starting to serve requests on 8000 at Sun Sep 20 14:13:57 2015
Sun Sep 20 14:14:31 2015 - wrote:
Line 0: [b'PUT /api/user/lights/3/state HTTP/1.1\r\n']
Checking if header put /api/user/lights/3/state http/1.1 is known
Line 1: [b'User-Agent: SparkBot/1.0 (http://docs.spark.io/webhooks#bot)\r\n']
Checking if header user-agent is known
Line 2: [b'host: myServer:8000\r\n']
Checking if header host is known
Line 3: [b'accept: application/json\r\n']
Checking if header accept is known
Line 4: [b'content-type: application/json\r\n']
Checking if header content-type is known
Line 5: [b'content-length: 11\r\n']
Checking if header content-length is known
Header was known, saving value [11]
Line 6: [b'Connection: keep-alive\r\n']
Checking if header connection is known
Line 7 was empty, headers finished.
Current parsed headers are {'content-length': '11'}
Trying to read 11 bytes of data...
Received data [b'{"on":true}']
Request Finished

This makes it easy to see if your request got received properly.

A big…


to sabin512 for this awesome contribution to my project. :clap:

is your setup consisting of a static ip forwarded to the hue bridge?

Hi @vbusnita , I was trying to recreate that, but I can’t use the Particles online webhook tools, since they don’t accept a static IP address.
I unsuccessfully experimented with the Spark HTTP client library.
How did you make it work?