Skip to content

fix: debounce grid sensor dropouts and make the failsafe direction configurable - #4

Merged
bvweerd merged 1 commit into
devfrom
fix/grid-failsafe-handling
Jul 3, 2026
Merged

fix: debounce grid sensor dropouts and make the failsafe direction configurable#4
bvweerd merged 1 commit into
devfrom
fix/grid-failsafe-handling

Conversation

@bvweerd

@bvweerd bvweerd commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

  1. A single 5 s grid-sensor dropout (an MQTT broker restart, a P1 reader hiccup) immediately reset the PID and slammed all PV limits to maximum. One bad poll caused a full export spike and lost controller state.
  2. The failsafe direction was hardcoded to "PV to max". For installations with a zero-export requirement from the grid operator, failing open is exactly the wrong direction — the failsafe itself violates the export limit.
  3. After an outage the EWM filter resumed from its stale pre-outage value, biasing the first cycles after recovery.

Fix

  • Dropout debounce: up to 3 consecutive unavailable grid reads (GRID_UNAVAILABLE_TOLERANCE_CYCLES) hold the current actuator state with the integrator frozen. The failsafe and the repair issue only engage when the outage persists; a successful read resets the counter.
  • Configurable failsafe behaviour (new option in setup + options flow, EN/NL translations included):
    • maximize (default, unchanged behaviour) — PV to full output, for self-consumption setups.
    • curtail — PV to minimum, for zero-export installations.
      The mode applies both to grid-sensor outages and to the controller being disabled via the enable switch.
  • EWM reset on outage: the filter re-seeds from the first fresh reading after recovery.

Tests

tests/test_grid_failsafe.py: hold-then-failsafe sequencing, counter reset on recovery, curtail mode on outage, curtail mode on disable, and filter re-seeding. Full suite: 131 passed.

https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz


Generated by Claude Code

@bvweerd
bvweerd force-pushed the fix/grid-failsafe-handling branch from 2a89548 to 6b2f0ca Compare July 3, 2026 17:27
@github-actions github-actions Bot added documentation Improvements or additions to documentation enhancement New feature or request bug Something isn't working labels Jul 3, 2026
@bvweerd
bvweerd force-pushed the fix/grid-failsafe-handling branch from 6b2f0ca to 86ae0ba Compare July 3, 2026 17:37
…nfigurable

A single 5 s sensor dropout (e.g. an MQTT reconnect) immediately reset
the PID and slammed all PV limits to maximum. For zero-export
installations, failing to maximum is exactly the wrong direction.

- Hold the current actuator state (integrator frozen) for up to 3
  consecutive unavailable grid reads before entering failsafe; the
  repair issue is only raised when failsafe actually engages.
- New "Failsafe behaviour" option: maximize (default, unchanged
  behaviour, for self-consumption setups) or curtail (PV to minimum,
  for zero-export requirements). Applies both to grid-sensor outages
  and to the controller being disabled.
- Reset the EWM filter on a full outage so the first cycles after
  recovery are not biased by stale pre-outage state.

Rebased onto dev after the battery-layer (#5) and calibration-guard
(#3) merges.

https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
@bvweerd
bvweerd force-pushed the fix/grid-failsafe-handling branch from 86ae0ba to 4995b1e Compare July 3, 2026 17:38
@bvweerd
bvweerd merged commit 1b71ad7 into dev Jul 3, 2026
9 checks passed
@bvweerd
bvweerd deleted the fix/grid-failsafe-handling branch July 3, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant