Foddy / node-red-contrib-huemagic

Philips Hue node to control bridges, lights, groups, motion sensors, temperature sensors and Lux sensors using Node-RED.
https://flows.nodered.org/node/node-red-contrib-huemagic
Apache License 2.0
200 stars 67 forks source link

Error: Request failed with status code 503 #295

Open Brewj opened 2 years ago

Brewj commented 2 years ago

Describe the bug Since upgrading NodeRed and the HueMagig node I'm getting the following error: Request failed with status code 503 for about half of my lights when deploying / restarting the flow or NodeRed. "Executing Command" displays under the fixture node not the status.

Toggling the fixture on and off from the NR Dashboard or the Hue app restores the functionality but the "Executing Command" frequently returns.

Flow to Reproduce

[{"id":"bb65725da3f2f1a3","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"6cd67217f6774d88","type":"hue-light","z":"bb65725da3f2f1a3","name":"Wall 1 Alley1","bridge":"8b347d00.5d7e4","lightid":"4bd7e0fb-a132-40ed-90f9-6a343b56ec2e","colornamer":false,"skipevents":false,"initevents":false,"x":1090,"y":140,"wires":[["cdf3b3d7b2cfa250"]]},{"id":"2e65c69a7161e5a9","type":"hue-light","z":"bb65725da3f2f1a3","name":"Wall 2 Alley2","bridge":"8b347d00.5d7e4","lightid":"b92c5980-702d-4475-ae2a-0eda1925bfc4","colornamer":false,"skipevents":false,"initevents":false,"x":1090,"y":200,"wires":[["cdf3b3d7b2cfa250"]]},{"id":"3193c9708ad48ef4","type":"hue-light","z":"bb65725da3f2f1a3","name":"Wall 3 Alley3","bridge":"8b347d00.5d7e4","lightid":"365141c1-e7ab-405c-917b-6c71b1385cf5","colornamer":false,"skipevents":false,"initevents":false,"x":1090,"y":260,"wires":[["cdf3b3d7b2cfa250"]]},{"id":"9dbe7e5be103432b","type":"ui_slider","z":"bb65725da3f2f1a3","name":"","label":"","tooltip":"","group":"2a8db6685c266b1d","order":3,"width":5,"height":1,"passthru":false,"outs":"end","topic":"","min":0,"max":"100","step":"5","x":310,"y":260,"wires":[["c332ea04ec2dc8ed","416e45efc22f7aa4"]]},{"id":"c332ea04ec2dc8ed","type":"function","z":"bb65725da3f2f1a3","name":"Brightness","func":"return {payload: { brightness: msg.payload } };","outputs":1,"noerr":0,"x":470,"y":260,"wires":[["0e6ee26ea26e643d"]]},{"id":"abdb70a16e939837","type":"ui_switch","z":"bb65725da3f2f1a3","name":"","label":"","tooltip":"","group":"2a8db6685c266b1d","order":2,"width":1,"height":1,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":430,"y":180,"wires":[["0e6ee26ea26e643d"]]},{"id":"a4b5790196064ab1","type":"function","z":"bb65725da3f2f1a3","name":"splitter","func":"return [\n    { payload: msg.payload.on },\n    { payload: msg.payload.brightness }\n];","outputs":2,"noerr":0,"x":310,"y":220,"wires":[["abdb70a16e939837"],["9dbe7e5be103432b","416e45efc22f7aa4"]]},{"id":"cdf3b3d7b2cfa250","type":"link out","z":"bb65725da3f2f1a3","name":"Alley Loop Out","links":["eec5435760d0cce0"],"x":1215,"y":180,"wires":[]},{"id":"eec5435760d0cce0","type":"link in","z":"bb65725da3f2f1a3","name":"Alley Loop In","links":["cdf3b3d7b2cfa250"],"x":215,"y":220,"wires":[["a4b5790196064ab1"]]},{"id":"416e45efc22f7aa4","type":"ui_text","z":"bb65725da3f2f1a3","group":"2a8db6685c266b1d","order":1,"width":0,"height":0,"name":"Level","label":"Alley","format":"{{msg.payload}}","layout":"row-spread","x":490,"y":220,"wires":[]},{"id":"0e6ee26ea26e643d","type":"function","z":"bb65725da3f2f1a3","name":"Alley Dashboard","func":"var state = msg.payload\nvar level = msg.payload.brightness\n\nmsg.payload = {\n    on: state,\n    brightness: level,\n    trigger:\"dashboard\",\n    room: \"Alley\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":180,"wires":[["99ee931e30a02183"]]},{"id":"99ee931e30a02183","type":"function","z":"bb65725da3f2f1a3","name":". ","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":915,"y":180,"wires":[["ce435e499f99284b","6cd67217f6774d88","2e65c69a7161e5a9","3193c9708ad48ef4"]],"l":false},{"id":"59aa653ea0491655","type":"link in","z":"bb65725da3f2f1a3","name":"Alley Off","links":["e574572e.875028","b0364f9b.d53bd"],"x":640,"y":300,"wires":[["3eaf1208f09fafc7"]],"l":true},{"id":"3a5bc77e1284e6b7","type":"link in","z":"bb65725da3f2f1a3","name":"Alley High","links":["dde6ae8a.5b6438","748a5a22.c1c86c","e3ea013d.1bb108"],"x":640,"y":220,"wires":[["8f2803a832d65b57"]],"l":true},{"id":"9ae8751b115f7b4a","type":"link in","z":"bb65725da3f2f1a3","name":"Alley Low","links":["c8a6b7bc.24da88","f1caa003.40409","f7b92263.392c7"],"x":640,"y":260,"wires":[["f831b8c90df37ac3"]],"l":true},{"id":"8f2803a832d65b57","type":"function","z":"bb65725da3f2f1a3","name":"@100/0","func":"var trig = msg.payload.trigger\n\nmsg.payload = {\n    on: true,\n    brightness:100,\n    transitionTime:0,\n    trigger:trig,\n    room: \"Alley\",\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":220,"wires":[["99ee931e30a02183"]]},{"id":"f831b8c90df37ac3","type":"function","z":"bb65725da3f2f1a3","name":"@40/5","func":"var trig = msg.payload.trigger\n\nmsg.payload = {\n    on: true,\n    brightness:40,\n    transitionTime:5,\n    trigger:trig,\n    room: \"Alley\",\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":260,"wires":[["99ee931e30a02183"]]},{"id":"3eaf1208f09fafc7","type":"function","z":"bb65725da3f2f1a3","name":"Off/5","func":"var trig = msg.payload.trigger\n\nmsg.payload = {\n    on: false,\n    brightness:0,\n    transitionTime:5,\n    trigger:trig,\n    room:\"Alley\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":300,"wires":[["99ee931e30a02183"]]},{"id":"ce435e499f99284b","type":"debug","z":"bb65725da3f2f1a3","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":320,"wires":[]},{"id":"8b347d00.5d7e4","type":"hue-bridge","name":"Beaver Hue","bridge":"10.1.1.108","key":"txr199imLMnsQRFZW6t8szTvUFbAh0KxxT1Wn4zV","worker":"10","disableupdates":false},{"id":"2a8db6685c266b1d","type":"ui_group","name":"Alley","tab":"e403be4.fc56ec","order":6,"disp":false,"width":"6","collapse":false},{"id":"e403be4.fc56ec","type":"ui_tab","name":"Lighting","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Expected behaviour Nodes should connect as previously.

Screenshots Screenshot 2022-01-21 at 19 53 25

Please complete the following information:

Brewj commented 2 years ago

Have rolled back to 3.0.0 and normal behaviour has been restored, so I wonder what specific action added into 4.0.0 is effecting it.

Schmetterfliege commented 2 years ago

@Brewj with 4.1.0 so called "workers" have been added, so prevent hitting the limit of the hue API. Updating to 4.1.0 should fix your issue. But make sure to go into the bridge config and set the amount of workers!

h-va commented 2 years ago

I have similar problems, tried several things, including update to 4.1.0 as mentioned above. Finally I rolled back to my working setup with node-red version 10.3.0 and huemagic 3.0.0. Hopefully a solution will come soon.

MPowerData commented 2 years ago

I'm also facing similar issues. After upgrading to 4.1.0, I've configured 7 workers. However, several commands are not executed, while this was not a problem before...

NBonline commented 2 years ago

Same issue here. Upgrade to 4.1.0 is a disappointment, everything worked ok before. Commands are not queued and executed correctly. Hope an update can fix this issue.

MPowerData commented 2 years ago

Same issue here. Upgrade to 4.1.0 is a disappointment, everything worked ok before. Commands are not queued and executed correctly. Hope an update can fix this issue.

In the end I moved all my functionality to using home assistant nodes. No issues yet. But not sure if that would work for you...

NBonline commented 2 years ago

Same issue here. Upgrade to 4.1.0 is a disappointment, everything worked ok before. Commands are not queued and executed correctly. Hope an update can fix this issue.

In the end I moved all my functionality to using home assistant nodes. No issues yet. But not sure if that would work for you...

I would considor that. If no solution happens soon.

spudje commented 2 years ago

Same here, although iirc via Home Assistant it was trickier to do blinking (alert), that's why I moved to Huemagic.

MarcAroni81 commented 2 years ago

I have similar problems, tried several things, including update to 4.1.0 as mentioned above. Finally I rolled back to my working setup with node-red version 10.3.0 and huemagic 3.0.0. Hopefully a solution will come soon.

Same here - can you tell me how to rollback?

h-va commented 2 years ago

I run samba backup every night. Rolling back was restoring a backup.

MarcAroni81 commented 2 years ago

for me its not working with 4.1 either. Any suggestions what the best amount of workers should be?

NBonline commented 2 years ago

I have tested with 4 to 7, same problem. Something wrong in the logic. Have to set delay for even get it to work. Hope a solution comes soon.

GeorgeCastanza commented 2 years ago

I'm having this issue as well. Have reduced workers to <10.

Thanks Foddy for all your work.

Brewj commented 2 years ago

I have similar problems, tried several things, including update to 4.1.0 as mentioned above. Finally I rolled back to my working setup with node-red version 10.3.0 and huemagic 3.0.0. Hopefully a solution will come soon.

Same here - can you tell me how to rollback?

from the command line on my pi I just ran the following, you can specify which ever version you desire. Then stop, restart Node Red. npm install node-red-contrib-huemagic@3.0.0

neptrio commented 2 years ago

Same here. Reducing workers to 1 solved the issue for me.

HannesHo commented 2 years ago

@neptrio That worked for me thanks, but now I have a delay when operating more than one light with an event. So this is only a temporary fix until it is fixed in hue magic itself.

BlaM commented 2 years ago

Confirmed, 1 worker works, 2 workers does not.

andesse commented 2 years ago

There is a general limit on how many tasks you can perform on the HUE clip API v2 This is the official documentation from HUE developers.

image

Knowing this, it isn't really a problem with the HueMagic Contrib.

Edit: "grouped_lights" means that these are several lights in containers like groups/rooms/zones If you exceed the limit you'll be always getting the 503 error. It "might" be triggered... or not ;)

Edit2: if you deploy full/flows that contain light / group nodes it is obvious that the error occurs. I'd recommend to deploy always changed nodes

andesse commented 2 years ago

Having "node-red-contrib-philipshue-events" in your flows, that works perfectly with api v2 (it reads all data from the bridge and need to switched for desired commands) in combination HueMagic works pretty zero issues for me at the moment. I had similar problems. You might give it a try. It use it for all events that normally come out of grouped-lights and lights.

MrTeal commented 2 years ago

I'm also getting a lot of 503's since the update to 4.1.0, unfortunately I'm running it in docker and I cannot seem to roll back to 3.0.0 easily.. but it messed up 30% of my flows, which were working fine on 3.0.0

andesse commented 2 years ago

@MrTeal try to follow my recommendation and set the worker in the config to 5. Don't trigger multiple lights, trigger scenes instead and you should be fine.

MrTeal commented 2 years ago

Thanks for the quick response. I’ll need to do some modifications and create some extra scenes to get my previous setup working in this new way.

FredBlo commented 2 years ago

I have this same issue and it is indeed related to having at least one 'HUE Group node' in a flow which also triggers other 'single light point' HUE nodes.

Solution I found to workaround this issue :

Technically, I guess it would require the HueMagic engine to handle workers differently : as soon as a group request is processed, it must always wait at least 1 second before sending next command, regardless of the number of workers set... (?)

MrTeal commented 2 years ago

I have this same issue and it is indeed related to having at least one 'HUE Group node' in a flow which also triggers other 'single light point' HUE nodes.

Solution I found to workaround this issue :

  • either replace your group node by multiple light nodes (this is actually what the HUE bridge itself does when receiving a group command, it will split it and send multiple commands). But this quickly gets quite blurry in flows when having many lights per group :-(
  • either set number of workers to 1

Technically, I guess it would require the HueMagic engine to handle workers differently : as soon as a group request is processed, it must always wait at least 1 second before sending next command, regardless of the number of workers set... (?)

What I did, I created "zones" in the Hue app for the light groups I used to address individually (which worked in the pre 4.1 version). so before I had 2 situations where a different set of lights needed to turn on which I all addressed individually, now I had to create 2 groups/zones (which might somewhere be more efficient I guess) containing these lights to achieve the same. but then it does work. image

andesse commented 2 years ago

Guys, if you want to get the Bridge Response ultimately quick and without errors use the "node-red-contrib-philipshue-events"

It reads the API V2 properly and you get an unreal amount of status updates from the bridge, like 10 in one second, when you trigger a scene with 10 lights.

The output of this node can be switched to the flows where the status updates are needed. On the other hand, don't trigger multiple lights, use scenes. (It's still fine to trigger a single light, but avoid multiple at once)

When both things are done you get zero issue hue running in node red. HueMagic for the scenes, for sensors, buttons. The other contrib for responses. I have the worker on 5.

If scenes are not working correctly at the moment for you, look for my posted Issue, I found a solution. There is just one command wrong in the file. You can change it by yourself.

johnekarlsson commented 2 years ago

On the other hand, don't trigger multiple lights, use scenes. (It's still fine to trigger a single light, but avoid multiple at once)

For me (and many others) it's not possible to do that since the command to the light depends on the input (brightness, color, light temperature etc.) Also this is working perfectly fine with a version <4, so it is most certainly a bug. I hope it gets some focus since this makes it impossible for me and others to upgrade. Thanks!

andesse commented 2 years ago

@johnekarlsson i strongly recommend to use scenes to turn lamps / groups on and off. It's fine to turn of lamps individually.

Even using API v2 https request, for me it isn't possible to send more than 2 (maybe 3) http request at once, what seems to be a node red problem. The developer information published says following:

""We can’t send commands to the lights too fast. If you stick to around 10 commands per second to the /light resource as maximum you should be fine. For /grouped_light commands you should keep to a maximum of 1 per second. The REST API should not be used to send a continuous stream of fast light updates for an extended period of time, for that use case you should use the dedicated Hue Entertainment Streaming API.""

I using https request now for 2-3 weeks and had never a problem