jdomeij / node-red-contrib-node-lifx

Node RED nodes for controlling Lifx lights
Apache License 2.0
7 stars 9 forks source link

Can't seem to turn on lights #9

Closed shanness closed 6 years ago

shanness commented 6 years ago

Hey there, looks like the best lifx library to me. My setup is below. I'm hitting it with curl 'http://localhost:1880/lights?on=on'

And the debug output is {"on":"on"} (when I copy it, shows { on : "on" } visually)

I've tried wrapping the first on above in " and nada. No debugging errors etc, and nothing in the node-red console.

[{"id":"513ad0d1.4e0ee","type":"http in","z":"cc115c33.f5692","name":"","url":"/lights","method":"get","upload":false,"swaggerDoc":"","x":127,"y":636,"wires":[["af8e9d1f.082a2","c47c6ac1.2f02b8","818d2598.f919c8"]]},{"id":"af8e9d1f.082a2","type":"node-lifx-in","z":"cc115c33.f5692","server":"9921bb36.d25ba8","name":"","lightID":"d073d511b4a3","x":455,"y":687,"wires":[],"inputLabels":["msg.payload"]},{"id":"c47c6ac1.2f02b8","type":"debug","z":"cc115c33.f5692","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":468,"y":595,"wires":[]},{"id":"818d2598.f919c8","type":"http response","z":"cc115c33.f5692","name":"","statusCode":"200","headers":{},"x":458,"y":638,"wires":[]},{"id":"9921bb36.d25ba8","type":"node-lifx-server","z":"","name":"Lifx Server","address":"","broadcast":"","lights":"","interval":"10000"}]
jdomeij commented 6 years ago

The problem is that "on" only accepts boolean values, all other values is ignored. My hue project have some code to accept more input types but i havn't ported it yet

shanness commented 6 years ago

Oh right. I was going off this comment of yours which said it took 'on' as well. Is that not live? https://github.com/jdomeij/node-red-contrib-node-lifx/issues/1#issuecomment-270752980

shanness commented 6 years ago

Just in case someone else has the same issue, here's a solution, basically a function to convert the HTTP params into booleans and ints. Probs not the most clean way, but it'll do.

[{"id":"513ad0d1.4e0ee","type":"http in","z":"cc115c33.f5692","name":"","url":"/lights","method":"get","upload":false,"swaggerDoc":"","x":127,"y":636,"wires":[["c47c6ac1.2f02b8","818d2598.f919c8","9f6e9fce.88aec"]]},{"id":"c47c6ac1.2f02b8","type":"debug","z":"cc115c33.f5692","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":468,"y":595,"wires":[]},{"id":"818d2598.f919c8","type":"http response","z":"cc115c33.f5692","name":"","statusCode":"200","headers":{},"x":458,"y":638,"wires":[]},{"id":"9f6e9fce.88aec","type":"function","z":"cc115c33.f5692","name":"convertObj","func":"var on=false;\nif (msg.payload.on == \"on\") {\n    on=true;\n}\nvar brightness=100\nif ( msg.payload.brightness ) {\n    brightness=parseInt(msg.payload.brightness);\n}\nvar oldPayload = msg.payload;\nmsg.payload = {\n    on: on,\n    brightness: brightness\n}\nnode.warn(\"Changed msg.payload[\" + oldPayload  + \"] to [\" + msg.payload + \"]\");\nreturn msg;","outputs":1,"noerr":0,"x":319,"y":694,"wires":[["af8e9d1f.082a2"]]},{"id":"af8e9d1f.082a2","type":"node-lifx-in","z":"cc115c33.f5692","server":"9921bb36.d25ba8","name":"","lightID":"d073d511b4a3","x":527,"y":694,"wires":[]},{"id":"9921bb36.d25ba8","type":"node-lifx-server","z":"","name":"Lifx Server","address":"","broadcast":"","lights":"","interval":"10000"}]

image

shanness commented 6 years ago

And just wanted to say thanks again, this library is great, so snappy :)

jdomeij commented 6 years ago

I have published an new version that handles more input types for the "on" property.