joocer / node-red-contrib-magic-home

Do What The F*ck You Want To Public License
0 stars 1 forks source link

Changing colours causes whole flow to stop working #1

Open 877dev opened 5 years ago

877dev commented 5 years ago

Hi @joocer and thanks for the node. I admit I am relatively new to red node and have almost zero knowledge of javascript, I'm even sturggling with passing payloads on etc..

But I think I have this setup correctly, and it works fine with on/off commands. But when changing colour by one of the three inject nodes, the LED strip stops responding until I re-deploy.

Any info/insights/tips would be greatly appreciated!

The kit I purchased (running stock firmware): https://www.amazon.co.uk/gp/product/B07MM4G7PZ/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

My flow:

[{"id":"37acee0a.bbe3a2","type":"inject","z":"8bb23b43.f1a468","name":"ON","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":120,"wires":[["5227b36e.42645c"]]},{"id":"f52adcd7.f34c5","type":"inject","z":"8bb23b43.f1a468","name":"OFF","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":180,"wires":[["5227b36e.42645c"]]},{"id":"3ab14e07.e86872","type":"debug","z":"8bb23b43.f1a468","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":160,"wires":[]},{"id":"5227b36e.42645c","type":"change","z":"8bb23b43.f1a468","name":"Power","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.power","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":161,"wires":[["870e3ede.1062"]]},{"id":"870e3ede.1062","type":"MagicHome","z":"8bb23b43.f1a468","name":"","server":"69d1b800.953898","x":770,"y":160,"wires":[["3ab14e07.e86872"]]},{"id":"99ff57a2.c2e868","type":"inject","z":"8bb23b43.f1a468","name":"{ \"red\":255, \"green\":255, \"blue\":255 }","topic":"","payload":"{ \"red\":255, \"green\":255, \"blue\":255 }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":300,"wires":[["8af9dad9.d84d58"]]},{"id":"8af9dad9.d84d58","type":"change","z":"8bb23b43.f1a468","name":"Colour","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.color","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":260,"wires":[["870e3ede.1062","be8c2425.526538"]]},{"id":"22d41c78.7b24c4","type":"inject","z":"8bb23b43.f1a468","name":"{ \"red\":255, \"green\":255, \"blue\":0 }","topic":"","payload":"{ \"red\":255, \"green\":255, \"blue\":0 }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":380,"wires":[["8af9dad9.d84d58"]]},{"id":"631ba16e.16c86","type":"inject","z":"8bb23b43.f1a468","name":"{ \"red\":255, \"green\":0, \"blue\":255 }","topic":"","payload":"{ \"red\":255, \"green\":0, \"blue\":255 }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":340,"wires":[["8af9dad9.d84d58"]]},{"id":"be8c2425.526538","type":"debug","z":"8bb23b43.f1a468","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":260,"wires":[]},{"id":"69d1b800.953898","type":"MagicHome-config","z":"","name":"RGB","host":"192.168.1.214","interval":10}]
joocer commented 5 years ago

G'day 877. It looks like that controller doesn't have any WHITE channel; I have two different types of controllers, one with a single WHITE channel and one with two (COOL WHITE and WARM WHITE).

The inner working of the node has been pretty much put into this snippet (it's from a function node) https://github.com/joocer/node-red-nodes/blob/master/magic-home-ufo-controller.js

I don't have a unit to test on, but given the difference between a 5 and a 4 channel controller, there's a chance that updating this

if (STYLE == 'RGBWW') { checkbit = function(command) { command[8] = (command[0] + command[1] + command[2] + command[3] + command[4] + command[5] + command[6] + command[7]) % 256; return command; }; COLORCOMMAND = [49, 255, 255, 255, 255, 255, 240, 15, 255]; } else { checkbit = function (command) { command[7] = (command[0] + command[1] + command[2] + command[3] + command[4] + command[5] + command[6]) % 256; return command; }; COLORCOMMAND = [49, 255, 255, 255, 0, 0, 240, 15, 255]; }

to be like this

if (STYLE == 'RGBWW') { checkbit = function(command) { command[8] = (command[0] + command[1] + command[2] + command[3] + command[4] + command[5] + command[6] + command[7]) % 256; return command; }; COLORCOMMAND = [49, 255, 255, 255, 255, 255, 240, 15, 255]; } else if (STYLE == 'RGBW') { checkbit = function (command) { command[7] = (command[0] + command[1] + command[2] + command[3] + command[4] + command[5] + command[6]) % 256; return command; }; COLORCOMMAND = [49, 255, 255, 255, 0, 0, 240, 15, 255]; } else { checkbit = function (command) { command[6] = (command[0] + command[1] + command[2] + command[3] + command[4] + command[5]) % 256; return command; }; COLORCOMMAND = [49, 255, 255, 255, 0, 240, 15, 255]; }

it would support a 3 channel controller.