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

Already running" script overlap on select_option/set_value writes for multiple batteries (m1–m4)

Open tdolder opened this issue 3 months ago • 4 comments

via claude.ai Setup

  • Home Battery Control (v4.13.0)
  • Flows 4.13.0
  • 4x Marstek batteries (M1–M4) over Modbus
  • Grid sensor: sensor.p1_meter_power (DSMR P1)
  • Node-RED battery strategy flow (tab id 5513c146eceff5e7), triggered on state_changed of sensor.p1_meter_power with outputOnlyOnStateChange: false

Problem Home Assistant logs repeated WARNING entries like: "Marstek m2 Forcible Charge/Discharge select_option: Already running" "Marstek m4 Forcible discharge Power set_value: Already running"

These come from homeassistant.helpers.script for the select_option/set_value calls the "Set Batteries" node issues per battery. They indicate a new write cycle is triggered before the previous one (across up to 4 batteries) has finished, causing overlapping Modbus writes.

What we tried Increased the DSMR polling interval for the P1 sensor from 1s to 3s, since the whole strategy flow re-runs on every P1 update. This resolved the overlaps overnight (low, infrequent battery activity), but the warnings returned the next afternoon during active/fluctuating solar production, now affecting all 4 batteries (m1–m4) instead of just m1/m2, with higher counts than before (e.g. 47 occurrences for m2 select_option in one day).

Observation on the built-in Rate Limiter While inspecting the flow, the "Rate Limiter" group (0.333 msg/s power-saving / 1 msg/s responsive / high-load cool-down, as described in docs/06-advanced-features.md) appears to sit on a separate branch that only feeds the "CPU power saved" debug/dashboard update — not the main path into "Get batteries information" → "Strategy selection" → "Set Batteries". If that's correct, the adaptive rate limiter may not currently be throttling the actual per-battery write cycle, which would explain why overlaps still occur under load even with the built-in limiter present. Would appreciate a maintainer look at whether the rate limiter's output is meant to gate the Set Batteries loop directly, or whether serializing/queuing the per-battery writes (e.g. waiting for the previous select_option/set_value to complete before starting the next battery, or debouncing based on actual write duration rather than just P1 update frequency) would be a more robust fix than throttling the P1 sensor.

Suggestion A queue/lock around the Set Batteries write sequence (skip or coalesce a new strategy run if the previous one hasn't finished writing) would likely fix this regardless of P1 update rate or number of batteries.

tdolder avatar Aug 19 '26 08:08 tdolder

Can confirm — seeing the same pattern here, independently.

Setup

  • Home Battery Control (v4.15.0)
  • 2x Marstek Venus E V3 (M1/M2) over Modbus TCP (direct Ethernet, not RS485)
  • Grid sensor: HomeWizard P1 (sensor.p1_meter_power)
  • Home Assistant 2026.9.1

Observed Same repeated WARNING entries: Marstek m1 Forcible Charge/Discharge select_option: Already running Marstek m2 Forcible Charge/Discharge select_option: Already running occurring roughly every 5s, continuously, not just during high-load/fluctuating solar — this was still going on hours later at a steady, low grid-power reading.

Additional data point: at the same time this was happening, a direct TCP connection test to port 502 on both battery IPs returned an immediate "connection refused" — from a completely separate host on the same LAN, with ping to both units confirmed healthy (<1ms). So this isn't just a script/log-level overlap warning — the Modbus TCP server on the unit itself was refusing new connections while the previous write was still in flight. Ruled out an IP conflict on our own network as the cause (had one of those before, unrelated, fully verified it wasn't that this time).

Also noticed Node-RED sitting at a sustained ~25% CPU during this, which lines up with the flow re-triggering continuously rather than settling.

Mitigation tried (partial, HA-side only, not a flow change): increased the Home Assistant Modbus poll interval for our own inverter_state_number sensor from 5s → 15s per battery (that sensor was our own most frequent poller, separate from HBC's own writes). Too early to say if this fully resolves it or just reduces the frequency — will report back.

Agree with the diagnosis above that the built-in Rate Limiter doesn't appear to be gating the actual "Set Batteries" write path (only feeds the debug/dashboard counter branch, as far as I can tell from the flow). A queue/lock around the per-battery write sequence — skip or coalesce a new run if the previous one hasn't finished writing — still seems like the right fix regardless of P1 update rate, number of batteries, or how far apart the writes get spaced out. Happy to test a patch against a 2-battery setup if one gets proposed.

natuurwaarnemer avatar Sep 07 '26 12:09 natuurwaarnemer

Ik ben even aan het meekijken. I'm looking into it. Please be advised that AI still has some trouble analyzing Node-RED / HA flows correctly. I see some erroneous assumptions about the rate limiter not working in your comments.

what is going on

The warning comes from this part: https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/script.py#L1919 Your HA->Modbus queue is overfilling. This lies just beyond HBC itself. It is the interface between HA en Modbus devices.

HA is polling all batttery sensors based on the Fonske config, and HBC is pushing new commands onto the bus for HA to send via Modbus. They all compete for the same bus time. So if things pile up, both reading and writing start timing out and you get this message.

There are two solutions:

  1. Fewer HBC updates and a lower refresh rate.
  2. Slower polling or less sensor readouts (adjust your Fonske configs)

Because the error appears outside of HBC, I can't detect if the modbus-hub is full or timing out. I can add a "calm" mode, you can select if you have persistent problems or we can ask Fonske to have a look at the configs and optimize them for less load on the modbus hub or you can experiment with different configs yourself ofcourse.

gitcodebob avatar Sep 08 '26 19:09 gitcodebob

Ok I'll come back on this. There seems to be a way to await the call service and via there guess how busy the ha-modbus-bus is.

gitcodebob avatar Sep 08 '26 20:09 gitcodebob

Dear Bob,

Thanks for looking into this, and for the correction — understood that the Already running originates in HA's select_option script call, i.e. the HA→Modbus hub queue overfilling, not the HBC rate limiter. That matches the picture: reads (Fonske sensor polling) and writes (HBC commands) competing for the same bus time, both starting to time out once it piles up.

One piece of context that's relevant before tuning configs: both our units are on EMS firmware v150. There are several independent community reports (e.g. Tweakers user sygys, also 2× Venus E3.0) that v150 specifically destabilises the Modbus interface on the Venus E3.0 — unit dropping offline roughly every ~20 min with a full restart cycle — and that reverting to v148 restores normal behaviour. We've requested a downgrade to v148 on both units via Marstek support.

Our plan, in order:

  1. Get both units back to v148.
  2. Measure the Already running + pymodbus-timeout rate per hour, before vs after, with the current v150 state as baseline.
  3. Only then decide whether config tuning is still needed.

HA-side mitigation already in place (not a flow change): we lowered the poll interval of our own inverter_state_number sensor from 5s → 15s per battery — that was our most frequent poller. PID preset is "Very safe", no Astrameter/CT emulation.

If the noise persists after v148 + the reduced polling, the opt-in "calm" mode you mentioned sounds like the right next lever for us. Would you rather see the v148 before/after numbers first, or should we loop in Fonske in parallel to look at the Modbus-TCP configs? Happy to test a calm-mode build against a 2-battery setup either way.

natuurwaarnemer avatar Sep 08 '26 20:09 natuurwaarnemer