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",
"noDefaults":true,
"mydevices":true,
"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()
{
Serial.begin(9600);
delay(2000);
}
void loop()
{
Serial.print("\nGetting ready to send...\n");
delay(5000);
Spark.publish("hue_command", value, 60, PRIVATE);
Serial.print("\nLight command sent...");
delay(10000);
}
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":"hue_command","data":"false","ttl":"60","published_at":"2015-09-18T18:44:52.045Z","coreid":"myCoreID"}
{"name":"hook-sent/hue_command","data":"undefined","ttl":"60","published_at":"2015-09-18T18:44:52.050Z","coreid":"\u0000\u001b�c\f"}
{"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.