node-red-contrib-home-assistant-websocket icon indicating copy to clipboard operation
node-red-contrib-home-assistant-websocket copied to clipboard

~20% CPU without ANY flow

Open karl007 opened this issue 6 months ago • 3 comments

Describe the bug

I recognized (months ago) that my server use much more resources than normal. Today I'm able to debug it complete down to this NR Plugin.

Without any Flow or Node, NR needs from ~0% without this plugin to 15-30% of my servers CPU (not a Pi, a real 8-core server).

To Reproduce

  1. start an empty (no config files) docker container with latest(4.0.9) NR
  2. add this Plugin in NodeRed (node-red-contrib-home-assistant-websocket 0.75)
  3. create a HA node (any - does not matter)
  4. klick + to add ConfigNode
  5. set URL and Token to a HA instance
  6. check CPU and click save

Expected behavior

Don't require CPU without any node/action to do.

Screenshots

No response

Example Flow


Environment Information

Version: 0.75.0

Home Assistant version: 2025.5.3
Companion version: 4.1.2

Node-RED version: 4.0.9
Docker: yes
Add-on: no

Node.js version: v20.19.0 x64 linux
OS: Linux 6.1.64-Unraid x64

HA as DockerContainer, but same issue as HA addon in HA SUpervisor installation

Additional context

NR Log with level trace from saving the HA settings where the CPU rise:

30 May 19:31:15 - [info] Started flows
30 May 19:31:15 - [trace] runtime event: {"id":"runtime-deploy","payload":{"revision":"6739ca3fcb07002dbc384a2cb397926564874e2928926a260e9868656b097af9"},"retain":true}
30 May 19:31:15 - [info] [server:Home Assistant] Connecting to http://homeassistant:8123
30 May 19:31:15 - [info] [server:Home Assistant] Connected to http://homeassistant:8123
30 May 19:31:15 - [debug] [server:Home Assistant] States Loaded
30 May 19:31:15 - [debug] [server:Home Assistant] Services Loaded
30 May 19:31:15 - [debug] [server:Home Assistant] Integration: loaded
30 May 19:31:15 - [debug] [server:Home Assistant] HA State: running
30 May 19:31:15 - [debug] [server:Home Assistant] Registries Loaded
30 May 19:31:27 - [metric] {"level":99,"event":"runtime.memory.rss","value":170041344,"timestamp":1748626287503}
30 May 19:31:27 - [metric] {"level":99,"event":"runtime.memory.heapTotal","value":105906176,"timestamp":1748626287503}
30 May 19:31:27 - [metric] {"level":99,"event":"runtime.memory.heapUsed","value":70870328,"timestamp":1748626287503}
30 May 19:31:42 - [metric] {"level":99,"event":"runtime.memory.rss","value":172916736,"timestamp":1748626302504}
30 May 19:31:42 - [metric] {"level":99,"event":"runtime.memory.heapTotal","value":108167168,"timestamp":1748626302504}
30 May 19:31:42 - [metric] {"level":99,"event":"runtime.memory.heapUsed","value":68599552,"timestamp":1748626302504}
[...]

karl007 avatar May 30 '25 17:05 karl007

When the Home Assistant server configuration is deployed, the integration establishes a persistent WebSocket connection to Home Assistant. At that point, several event listeners are registered to monitor things like state_changed events, and updates to the registry (devices, entities, areas, etc.).

This happens even if you don’t have any nodes in your flow—because the connection setup is part of the server configuration itself, not individual nodes. These listeners are necessary to provide real-time updates and autocomplete features in the editor, and they will consume some CPU depending on the number of entities and frequency of events in your Home Assistant instance.

zachowj avatar May 31 '25 01:05 zachowj

Yes, but NodeRed requires more CPU % than the whole Hassio VM - this is not really in relation to the work the both do. :(

If the Problems are the websockets, maybe mqtt is better for the realtime events?

Or can this be reduced to a list of only some entities to listen to?

karl007 avatar May 31 '25 19:05 karl007

Hello folks,

I can confirm this behavior. A simple flow by just subscribing one light entity with "events: state" or "poll state" node (doesn't matter which) adds 15-20% cpu usage alone. That's not acceptable.

When I used "raw" WebSocket nodes, implementing the same flow, the cpu usage was almost zero. Huge difference.

WebSocket Out node: sends the raw JSON for authentication ({type:"auth", access_token:"…"}) and later a subscription ({type:"subscribe_events", event_type:"state_changed"}). Both are configured to send payload only.

WebSocket In node: receives the raw event stream from HA. -> JSON node: parses the incoming string into a proper object. -> Function node(s): filter on msg.payload.event.data.entity_id etc. -> Debug / Switch / Call Service nodes: act on the parsed events.

Specs:

node-red 4.1.0 (runs in docker container) node-red-contrib-home-assistant-websocket 0.78.1 (same docker container)

HA Core 2025.10.2 (runs in docker container)

The docker containers run in different LXC on different proxmox nodes, but that doesn't really matter since the "raw" websocket flows proved the culprit.

Regards

rmi1974 avatar Oct 14 '25 18:10 rmi1974