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
201 stars 67 forks source link

Error requesting from the bridge #350

Open ralfhille opened 2 years ago

ralfhille commented 2 years ago

After the update I get the following entries in the node-red log:

22 Mar 10:00:29 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
22 Mar 10:00:29 - [info] [hue-bridge:Hue Wohnung] Initializing the bridge (192.168.178.15)…
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Connected to bridge
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Processing bridge resources…
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Initial emit of resource states…
22 Mar 10:00:31 - [info] [hue-bridge:Hue Wohnung] Keeping nodes up-to-date…
22 Mar 10:00:31 - [info] [hue-bridge:Hue Wohnung] Subscribing to bridge events…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Initializing the bridge (192.168.178.15)…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Connected to bridge
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Processing bridge resources…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Initial emit of resource states…
22 Mar 10:00:52 - [info] [hue-bridge:Hue Wohnung] Keeping nodes up-to-date…
22 Mar 10:00:52 - [info] [hue-bridge:Hue Wohnung] Subscribing to bridge events…
22 Mar 10:01:01 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
HueMagic: Connection to bridge lost. Trying to reconnect again in 30 seconds… Event {
  type: 'error',
  status: 503,
  message: 'Service Temporarily Unavailable'
}

HUE Bridge Version BSB002 / 1.50.1950111030 Node Red Version 2.2.0

All scenes and/or lamps can only be switched sporadically.

Is it now a mistake or did I go about it the wrong way?

The previous version with the workaround worked stable for me. Whereby I use exclusively the switching of scenes and groups.

ptweety commented 2 years ago

@davidcreager:

are you familiar with npm workspaces? If no, I would recommend looking into this and try to setup a local dev environment using the same.

davidcreager commented 2 years ago

Ooh. That sounds interesting. I will have a look

ptweety commented 2 years ago

@davidcreager: I've created a repo to help you getting started: https://github.com/ptweety/node-red-development.

Just get npm@v8, clone this repo, navigate to the packages subfolder, also clone node-red-contrib-huemagic inside there and back in the root execute npm i

davidcreager commented 2 years ago

Wow thanks.....appreciate the help

sanderboele commented 2 years ago

I too have this problem and basically makes HueMagic unusable. I've tried downgrading the npm package by simply entering the container and ` docker exec -it nodered_node-red_1 bash

npm install node-red-contrib-huemagic@4.2.1 `

I think that downgraded it but now I have other weird problems where flows don't seem te be processed properly anymore and I'm wondering if there is some error introduced in my flow or it's HueMagic that is broken. Now trashing the container and starting fresh, but would like to get pointers. When it works it's great, so much faster than other things I've tried.

andesse commented 2 years ago

@sanderboele i highly recommend using direct https requests to the bridge. Works flawless, just the Hue event contrib needed. (It would work without it too, using a http node for the event stream, but more convenient)

sanderboele commented 2 years ago

thank you @andesse I will check this out

ralfhille commented 2 years ago

@sanderboele i highly recommend using direct https requests to the bridge. Works flawless, just the Hue event contrib needed. (It would work without it too, using a http node for the event stream, but more convenient)

Hi,

I use the node-red server side event node.

node -red sse

You find a sample to start and stop the server side event communication. It works perfectly with the hue bridge.

sanderboele commented 2 years ago

For me as a beginner and just learning to understand how node-red works, it's much easier to understand HueMagic. I use events for example to detect a button push on a friends-of-hue switch and it's real easy to just drag in lights, groups, scenes and everything well documented so I can create something in little time that just works! It would take me days to figure out how to pull all data I need from the bridge and to everything from http event streams, or am I missing something trivial here?

image

example of what I'm doing now. This is Dutch language btw 👍

ralfhille commented 2 years ago

After the update I get the following entries in the node-red log:

22 Mar 10:00:29 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
22 Mar 10:00:29 - [info] [hue-bridge:Hue Wohnung] Initializing the bridge (192.168.178.15)…
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Connected to bridge
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Processing bridge resources…
22 Mar 10:00:30 - [info] [hue-bridge:Hue Wohnung] Initial emit of resource states…
22 Mar 10:00:31 - [info] [hue-bridge:Hue Wohnung] Keeping nodes up-to-date…
22 Mar 10:00:31 - [info] [hue-bridge:Hue Wohnung] Subscribing to bridge events…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Initializing the bridge (192.168.178.15)…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Connected to bridge
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Processing bridge resources…
22 Mar 10:00:51 - [info] [hue-bridge:Hue Wohnung] Initial emit of resource states…
22 Mar 10:00:52 - [info] [hue-bridge:Hue Wohnung] Keeping nodes up-to-date…
22 Mar 10:00:52 - [info] [hue-bridge:Hue Wohnung] Subscribing to bridge events…
22 Mar 10:01:01 - [info] [hue-bridge:Hue Wohnung] Error requesting info from the bridge. Reconnect in some secs. undefined
HueMagic: Connection to bridge lost. Trying to reconnect again in 30 seconds… Event {
  type: 'error',
  status: 503,
  message: 'Service Temporarily Unavailable'
}

HUE Bridge Version BSB002 / 1.50.1950111030 Node Red Version 2.2.0

All scenes and/or lamps can only be switched sporadically.

Is it now a mistake or did I go about it the wrong way?

The previous version with the workaround worked stable for me. Whereby I use exclusively the switching of scenes and groups.

Feel happy,

I can only share your opinion and I have also used the hue node for a relatively long time. But after an update on the hue bridge, I had massive problems with the hue node. But since I only turn lights on and off or set scenes, I decided for the moment to solve it via http request and server side events.

andesse commented 2 years ago

@sanderboele you are absolutely right about that, it's a convenient contrib. Managing everything trough https took me a whole day to setup.

Seeing your flow makes me want to share a hint. When you trigger 2 lamps/ groups simultaneously, add a one second delay to the second one. It will help the bridge not struggling with too many requests at once. The official Hue api Guide says, not more than one group request in a second.

sanderboele commented 2 years ago

Thanks for the tip @andesse I will add this delay and hope huemagic is fixed soon so my family doesn't kick me out of the house

andesse commented 2 years ago

@sanderboele i highly recommend using direct https requests to the bridge. Works flawless, just the Hue event contrib needed. (It would work without it too, using a http node for the event stream, but more convenient)

Hi,

I use the node-red server side event node.

node -red sse

You find a sample to start and stop the server side event communication. It works perfectly with the hue bridge.

@ralfhille i keep that one in mind, thanks. If the other one isn't working that would be another option.

sanderboele commented 2 years ago

I installed the same stuff but now in my mac mini m1, also just the standard container from docker hub, but now I get some interesting stuff:

(node:20) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'status' of undefined
    at /data/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:102:37
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use 'node --trace-warnings ...' to show where the warning was created)
(node:20) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag '--unhandled-rejections=strict' (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 10)
(node:20) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I'm hoping to have fixed the issue by copying api.js straight to the container.

diff ./api-bak.js ./api.js
102c102,109
<               reject({ status: error.response.status, errors: error.response.data.errors ? error.response.data.errors : error.response.data});
---
>               if (error.response)
>               {
>                   reject({ status: error.response.status, errors: error.response.data.errors ? error.response.data.errors : error.response.data});
>               }
>               else
>               {
>                   reject({ status: error.code, errors: error.message});
>               }
278c285

In hindsight I could have understood this from the thread, but I didn't :(

I now created a crontab that restarts node-red then my stuff kinda works

*/9 *  *  *  *  /usr/local/bin/docker container restart nodered_node-red_1
sanderboele commented 2 years ago

instead of restarting every 9 minutes, I now wrote a tiny and crude monitoring script

#! /usr/bin/env python

from sh import tail
from sh import docker

errorMessage = "Error requesting info from the bridge"

for line in tail("-f", "/data/docker/docker-data/containers/9abf662a938852f09c5cd925cf812b50ea95eb2dccaed8e1db46527f21a0a471/9abf662a938852f09c5cd925cf812b50ea95eb2dccaed8e1db46527f21a0a471-json.log",_iter=True):
    print(line)
    if errorMessage in line:
        print("restarting container...")
        docker("container", "restart", "nodered_node-red_1")
andesse commented 2 years ago

@sanderboele just change to https requests. The HUE api has changes on every bridge firmware release, HueMagic might cannot keep up so fast with updates. But using the standard V2 commands for lights / groups / motion / button endpoints just works great. If you need help to setup a flow, I can help out.

sanderboele commented 2 years ago

@andesse I'd rather fix the code than go through this tedious process of figuring out all ID's and how exactly to interact with them through http. I looked into it and I managed to turn a light on and off, but frankly I'd rather go do something else :P

My container has pretty long uptimes (I've had more than 24hrs), so the problem doesn't occur very often and it often happens a couple of minutes after I deploy a change on node-red. My script now immediately restarts the container and you don't notice it as it happens quickly. This behaviour leads me to believe it may be some kind of rate limit on the bridge. Before I completely move away from HueMagic an go through the motions of deploying with plain http it has to fail in a more dramatic way

On Fri, May 20, 2022 at 6:37 PM andesse @.***> wrote:

@sanderboele https://github.com/sanderboele just change to https requests. The HUE api has changes on every bridge firmware release, HueMagic might cannot keep up so fast with updates. But using the standard V2 commands for lights / groups / motion / button endpoints just works great. If you need help to setup a flow, I can.

— Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/350#issuecomment-1133106417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC5HKQ7QG46VRTEO4EMYXDVK65VVANCNFSM5RKHKHDQ . You are receiving this because you were mentioned.Message ID: @.***>

andesse commented 2 years ago

@sanderboele The bridge has a limit indeed. From the developer documentation:

"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."

In my https setup I don't use single lights, just use different scenes for rooms that are for daytime / evening / night & morning. As I have an apartment with 5 rooms, so around 15-20 scenes. Additional a button or two for every room, a motion sensor and the endpoint for groups themself. All at once that are ~40-45 http request (or just reading in eventstream) to configure, so it took not too long, I am using only API V2 that is incredible fast, and don't have a need for a contrib. I just use HueMagic to have a visual feedback for motion sensors for example.

VisualReversal commented 2 years ago

@sanderboele just change to https requests. The HUE api has changes on every bridge firmware release, HueMagic might cannot keep up so fast with updates. But using the standard V2 commands for lights / groups / motion / button endpoints just works great. If you need help to setup a flow, I can help out.

I've managed to figure out how to do everything except how to enable and disable my motion sensors. Any tips would be greatly appreciated.

andesse commented 2 years ago

@VisualReversal image

Find out your motion sensor endpoint Id and do it like this Hope this helps

andesse commented 2 years ago

Here my repository for https HUE API V2. It's just a flow with everything you need. https://github.com/andesse/node-red-hue-api.v2-flows

VisualReversal commented 2 years ago

This is great! Thank you!!!

isaac-the-newt commented 2 years ago

This issue persists with intermittent operation of Node Red with HUE Using Home Assistant with Node-Red add on; Current version: 13.3.1

From Node-Red logs on restart

11 Aug 08:37:03 - [info] Node-RED version: v3.0.2 11 Aug 08:37:03 - [info] Node.js version: v16.16.0 11 Aug 08:37:03 - [info] Linux 5.15.55 x64 LE 11 Aug 08:37:04 - [info] Loading palette nodes

Stream of errors - log level set to TRACE

11 Aug 08:33:31 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Aug 08:33:31 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Aug 08:33:31 - [info] [hue-bridge:Philips hue] Initial emit of resource states… 11 Aug 08:33:32 - [info] [hue-bridge:Philips hue] Keeping nodes up-to-date… 11 Aug 08:33:32 - [info] [hue-bridge:Philips hue] Subscribing to bridge events… 11 Aug 08:34:13 - [info] [hue-bridge:Philips hue] Error requesting info from the bridge. Reconnect in some secs. undefined 11 Aug 08:34:13 - [info] [hue-bridge:Philips hue] Initializing the bridge (192.168.0.150)… 11 Aug 08:34:13 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Aug 08:34:14 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Aug 08:34:14 - [info] [hue-bridge:Philips hue] Initial emit of resource states… 11 Aug 08:34:14 - [info] [hue-bridge:Philips hue] Keeping nodes up-to-date… 11 Aug 08:34:14 - [info] [hue-bridge:Philips hue] Subscribing to bridge events… 11 Aug 08:35:14 - [info] [hue-bridge:Philips hue] Error requesting info from the bridge. Reconnect in some secs. undefined 11 Aug 08:35:14 - [info] [hue-bridge:Philips hue] Initializing the bridge (192.168.0.150)… 11 Aug 08:35:14 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Aug 08:35:15 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Aug 08:35:15 - [info] [hue-bridge:Philips hue] Initial emit of resource states… 11 Aug 08:35:16 - [info] [hue-bridge:Philips hue] Keeping nodes up-to-date… 11 Aug 08:35:16 - [info] [hue-bridge:Philips hue] Subscribing to bridge events…

andesse commented 2 years ago

@isaac-the-newt come to me :)

isaac-the-newt commented 2 years ago

Hi Andreas,

Thanks for your offer to assist with working around the issues with HUEMAGIC.

I’ve had a look at the files from your GitHub repository and decided I would resolve this issue via an alternate method.

I have been able to remove HUEMAGIC completely from my system and insert functionally equivalent I/O interfaces to the HUE system using Node-RED blocks from the Home Assistant core library for Node-RED.

I’ve added some simple one-line automation scripts within Home Assistant core to replicate the TAP switch and other HUE button sensor inputs and everything is working reliably.

I exported my previous HUEMAGIC flows for posterity should that project ever get resolved and stable.

HUEMAGIC offered great integration opportunities but was not reliable and I spent many, many months trying to understand if my issues were caused by Wi-Fi interference, or access point placement, or other networking issues.

At this time, everything is solid. 😊

Thanks again for your support of the HUE user community.

regards,

Greg Belcher

From: Andreas @.> Sent: Thursday, 11 August 2022 15:54 To: Foddy/node-red-contrib-huemagic @.> Cc: isaac-the-newt @.>; Mention @.> Subject: Re: [Foddy/node-red-contrib-huemagic] Error requesting from the bridge (Issue #350)

@isaac-the-newt https://github.com/isaac-the-newt come to me :)

— Reply to this email directly, https://github.com/Foddy/node-red-contrib-huemagic/issues/350#issuecomment-1211577528 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AWY7QEZBWPLCCSEUQSHYLXTVYSIRBANCNFSM5RKHKHDQ unsubscribe. You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWY7QE5KPWT2N55LWV7EAZLVYSIRBA5CNFSM5RKHKHD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOJA3TJOA.gif Message ID: @.***>

andesse commented 2 years ago

@isaac-the-newt Thanks! nice that it worked out like that for you. Is HA offering the whole API V2 Integration, or are parts still relying on V1?

Greetings Andreas

isaac-the-newt commented 2 years ago

Hi Andreas,

V2 with legacy support for V1.

regards,

Greg Belcher

From: Andreas @.> Sent: Monday, 15 August 2022 15:19 To: Foddy/node-red-contrib-huemagic @.> Cc: isaac-the-newt @.>; Mention @.> Subject: Re: [Foddy/node-red-contrib-huemagic] Error requesting from the bridge (Issue #350)

@isaac-the-newt https://github.com/isaac-the-newt Thanks! nice that it worked out like that for you. Is HA offering the whole API V2 Integration, or are parts still relying on V1?

Greetings Andreas

— Reply to this email directly, https://github.com/Foddy/node-red-contrib-huemagic/issues/350#issuecomment-1214628320 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AWY7QE24SAY5BGCXXPHDFSLVZHHMTANCNFSM5RKHKHDQ unsubscribe. You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWY7QEZ2XWITGBXWXBVCXODVZHHMTA5CNFSM5RKHKHD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOJBS4DYA.gif Message ID: @.***>