zachowj / node-red-contrib-home-assistant-websocket

Node-RED integration with Home Assistant
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/
MIT License
505 stars 95 forks source link

Nodered disconnects from Home Assistant #1425

Open schwickster opened 4 months ago

schwickster commented 4 months ago

Describe the bug

Hey,

The latest Nodered version (4.0.1) seems to constantly disconnect Home Assistant which prevents events from triggering. In the logging I do see a disconnection and it reconnects.. but.. it still does not seem to properly reconnect. Reverting back to Nodered 4.0.0 seems to work for now. So I don't know if it's a bug within Nodered or a bug within this addon in combination with the latest version.

To Reproduce

Seems random.. so can't reproduce. Nodered 4.0.1 just seems to disconnect events from Home Assistant. Restarting nodered seems to temporary resolve the issue. Downgrading to Nodered 4.0.0 seems to work for now.

Expected behavior

No response

Screenshots

See next response

Example Flow

No response

Environment Information

I'm not at my home computer right now. But using docker version 4.0.1 (and now 4.0.0 for the workaround) of nodered using the latest version of this addon (0.65.1). Home Assistant is also running on docker using version 2024.6.4

Additional context

No response

schwickster commented 4 months ago

IMG_2048

here's some logging.

juampe commented 4 months ago

Maybe the problem is related to a deprecated alias in HA

`2024-06-27 11:56:50.110 WARNING (ImportExecutor_0) [homeassistant.helpers.typing] HomeAssistantType was used from nodered, this is a deprecated alias which will be removed in HA Core 2025.5. Use homeassistant.core.HomeAssistant instead, please report it to the author of the 'nodered' custom integration

bogorad commented 4 months ago

Same issue here. However, the "NR websocket disconnect from HA" issue has been with us for a very, very long time, and nothing is being done, unfortunately. I ended up implementing a 30 second timer in HA, triggering it from NR, and waiting for 60 sec. If nothing happens, I just restart NR (via a webhook).

schwickster commented 4 months ago

The problem keeps coming back even though I am still on nodered 4.0.0. I enabled the heart beat option in the addon which does help somewhat. I can't put my finger on the problem. The problems are also random in terms of timing.

Bond246 commented 3 months ago

Hello, i want to join in to this problem. For me it is the same issue but i don't know if the problem came up with node-red 4.0 because i started just some weeks ago with that plugin and use homeassistant just for one device.

It seems to me that restarting node-red helps BUT only ~18-23 hours. Than reconnects come back sometimes 10-20 per second. In my case i get confused about high CPU-load on my server which brings me to take a look at the cpu-load of node-red and home assistant to check if the problem is back again.

Is there a way to get more detailed logs for that plugin?

bogorad commented 3 months ago

so I ended up with this dirty little fix:

  1. in HA I created a helper of the type button.
  2. in HA I created an automation: every 10 seconds press input button.
  3. in NR I wait 60 sec since the button was last "pressed" and restart NR via a http-call to a webhook running on host.

too bad the author doesn't consider this to be a problem.

image image image

HendrikKirsch commented 2 months ago

Hello,

i have the same issue here ... after a restart it works for a time ...

17 Aug 15:54:56 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:54:56 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:54:58 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:54:58 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:54:58 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:00 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:00 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:01 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:03 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:03 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:03 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:05 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:05 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:05 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:07 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:08 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:08 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:10 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:10 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:10 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:12 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:12 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:13 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:15 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:15 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:15 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:17 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123 17 Aug 15:55:17 - [info] [server:Home Assistant] Connection closed to https://192.168.101.100:8123 17 Aug 15:55:17 - [info] [server:Home Assistant] Connecting to https://192.168.101.100:8123 17 Aug 15:55:19 - [info] [server:Home Assistant] Connected to https://192.168.101.100:8123

bogorad commented 2 months ago

try my hack https://github.com/zachowj/node-red-contrib-home-assistant-websocket/issues/1425#issuecomment-2269688113

HendrikKirsch commented 2 months ago

Hello,

I use a new long time token at this time and the connection is stable... for 4 days... after that the connection is lose...

steff75 commented 2 months ago

Does this problem also cause a permanently high CPU load for you when you use the Node-RED addon in HAOS?

I have noticed a sluggish behavior of Node-RED for some time now and have now been able to identify this node as the cause by exclusion.

The addon's info page permanently shows me ~25% CPU load. My system is the current HAOS on an Odroid-M1 (arm64) with 8 GB RAM. All other addons work without any problems.

Since several new connections to the server were also displayed in the log, I thought there might be a connection with your problem.

Screenshot 2024-09-09 090619

Screenshot 2024-09-09 090538

bogorad commented 2 months ago

It could cause high CPU usage if node-red is constantly trying to re-connect. However, I don't use nr-addon, so can't be sure.

steff75 commented 2 months ago

It would be helpful, if the node would then write something in the debug sidebar or in the container log.

bogorad commented 2 months ago

haha, it's been requested many times. better yet, it'd be great if it failed, and we could use the catch node ;)

zachowj commented 1 month ago

Try updating to the latest release, v0.47.0, and see if it resolves the issue.

bogorad commented 4 weeks ago

seems to be working! thanks!