marstek-venus-rs485-node-red icon indicating copy to clipboard operation
marstek-venus-rs485-node-red copied to clipboard

Feedback for Home Battery Control: performance on a small NAS

Open satscan1 opened this issue 2 months ago • 3 comments

Feedback for Home Battery Control: performance on a small NAS Short report of what we measured on HBC v4.15.1 and what made it fast again. Happy to share raw measurements or the patched flow.

Hardware / software

Host Synology DS224+ (Intel Celeron J4125, 4 cores), 18 GB RAM Home Assistant HA OS VM, 4 vCPU, ~6 GB RAM, HA 2026.9.1, ~2,400–3,200 entities Node-RED Community add-on, Node-RED 5.0.6, Node.js 24.18.1 HA palette node-red-contrib-home-assistant-websocket 0.80.3 Setup HBC v4.15.1, 2 × Marstek Venus over ESPHome/RS485, P1 every 5 s, Self-consumption

Symptom Strategy evaluation gradually went from ~0.5 s (spring) to 1.1–1.7 s (red, “High load, cooling down”), without any change to HBC or Node-RED. Debug mode was off and the link-call timeout was 30 s. Node-RED used 21–26 % CPU continuously.

Root cause: cost per HA node call, not HBC logic node-red-contrib-home-assistant-websocket 0.80.3 (and main) deep-clones the entire HA state cache on every current state node and every action node: getStates() → cloneDeep(this.states), plus getServices() for actions. The cost scales with the number of HA entities, not with what the flow uses.

Measured here (2,715 entities, 1.4 MB state):

Call Median current state node, fixed entity id (cache read only) 43 ms action node (system_log.write) 100–126 ms Same websocket call from a browser 2 ms

Our HA grew from ~1,000 to ~3,200 entities over the summer, which is exactly why HBC became slower over time on the same flow.

Load in HBC v4.15.1 per evaluation cycle (every P1 update, ~5 s) Flow current state action Home Battery Start 26 (16 static config + 10 per battery × 2 = 20) 11 Strategy Self-consumption 8 12 Home Battery Master Switch 2 2

At ~43 ms per read, the reads alone account for well over 1 s per cycle on this hardware.

What we changed (local patch, HBC logic untouched) Change Effect Disabled unused strategy tabs (Timed, Charge, Dynamic, Partials, Sell, PID presets); Master Switch, Start, Self-consumption and Full stop stay enabled Node-RED CPU 21–25 % → 0.5–4.7 % Replaced the 36 active current state nodes with function nodes reading a global.hbc_state_cache, maintained by one events: state node subscribed to the 41 entities HBC actually reads (with outputInitially) Strategy evaluation 0.85–1.7 s → 0.006–0.56 s, 100 % green Also disabled ~420 unused diagnostic entities in HA State size −13 % entities

Behaviour is unchanged: grid stays within ±50 W, Collect completions reports 2/2, no error states.

Suggestions for HBC Cache the static configuration reads. 16 of the 26 reads in Home Battery Start are helpers that only change when the user changes a setting (house_battery_count, cutoff capacities, power limits, strategy selects, debug mode). An events: state node on those helpers plus flow context would remove them from every cycle. Three helpers are even read twice in the same cycle (house_battery_count, house_battery_control_prioritize_battery, house_battery_control_priority_change_interval). Consider caching the per-battery reads too. 10 reads × number of batteries per cycle. Values such as max_charge_power, max_discharge_power, battery_total_energy and the cutoff capacities rarely change; only battery_power, SoC and inverter_state are genuinely live. Both are already proven on this installation. A similar cache patch in August took p50 from 337 ms to 170 ms; the full patch now gives green evaluations. The fix could also come from the palette side. We are reporting upstream that getStates() should not be deep-cloned when the entity id contains no template, and that getServices() should not be cloned per action call. If that lands, HBC needs no caching at all — but caching helps every user on modest hardware today. Optional: make the P1 rate limiter actually filter. With thresholds of 20 W and 2 %, CPU power saved reported 0.00 % (0/501) here — grid power fluctuates more than that almost every cycle, so every P1 update triggers a full evaluation. Note on updates The cache patch lives in the flow, so a HBC re-import overwrites it — same as the link-call timeout note in the update runbook. If some form of caching were shipped upstream, that maintenance would disappear.

satscan1 avatar Sep 11 '26 20:09 satscan1

Did you make an github issue of this somewhere at node-red-contrib-home-assistant-websocket? If so could you share the link?

wauswaus avatar Sep 12 '26 17:09 wauswaus

Not yet, I'm preparing one. I'll post the link here once it's filed. The measurements are on a Synology DS224+ (Celeron J4125) with ~2,700 HA entities (~1.4 MB of state):

current-state node with a fixed entity id: 43 ms median (cache read only, no HA traffic) action node (system_log.write): ~100–126 ms the same websocket call from a browser: 2 ms

Cause: CurrentStateController and ActionController call getStates() (and getServices()), which return cloneDeep(...) of the entire state cache on every execution, even when the entity id contains no template.

Replacing HBC's 36 active current-state nodes with a small global cache took Strategy evaluation from 0.85–1.7 s to 0.006–0.56 s, and Node-RED CPU from 21–25 % to under 5 %.

Upstream issue for the palette side is now filed: https://github.com/zachowj/node-red-contrib-home-assistant-websocket/issues/2058

satscan1 avatar Sep 12 '26 17:09 satscan1

Update: the cache patch needs a resync — found a safety issue after an HA restart

A caveat on the global.hbc_state_cache patch described above.

What happened

Today the EV was charging (wallbox ~5.6 kW) while HBC was in Dynamic / Self-consumption and discharged MT2 (−790 W) into the car. The EV stop trigger should have forced Full stop. The EV chain itself was fine: binary_sensor.ev_actief_laden → input_text.house_battery_strategy_ev_sensor_entity_id → sensor.ev_is_charging = on in HA. In the cache, however, sensor.ev_is_charging was still off.

Cause

The sensor flipped to on during a Home Assistant restart, while Node-RED was disconnected. The events: state node (with outputInitially) did not re-emit the current states after the websocket reconnected. The cache kept the pre-restart value until the next change of that entity. This applies to all 41 cached entities: strategy selects, cutoff capacities, master mode, EV trigger. Without the cache, HBC read live values and this could not happen.

Fix (running here now)

Added a resync next to the event-driven cache: an inject every 60 s (and 30 s after Node-RED start) → a render template node that returns state, attributes, last_changed and last_updated for the 41 entities via expand() → a function that updates hbc_state_cache only where state or last_changed differs. It never overwrites with an older last_updated. The event-driven path stays as it was, so the performance gain is unchanged. The resync is one template render per minute. Worst case after a reconnect is now ~1 minute stale instead of "until the next state change".

Suggestion If caching ever ships in HBC, it needs a resync on reconnect, or a periodic one. Otherwise a stale EV or strategy value can silently override the intended behaviour. A resync on the HA client ready event would be even more precise than a fixed interval.

Happy to share the three nodes.

satscan1 avatar Sep 21 '26 14:09 satscan1