Repository navigation
Off-grid shadow scan guard - #48
Merged
Merged
Conversation
Shadow scan misbehaves while the inverter is off-grid. With OFF_GRID_SHADOW_SCAN_GUARD=on it is turned off as soon as the inverter goes off-grid, and the previous value is put back once the grid has stayed up for OFF_GRID_SHADOW_SCAN_COOLDOWN_MIN (default 15): outages come in bursts, and in the history the grid dropped again up to ~15 min after returning. Independent of CONTROL_MODE. The pending restore is persisted in shadow_scan_guard.json so a restart mid-outage still restores it. Writes are verified by read-back, retried, and back off when the register never takes the value; the guard never raises into the poll loop. Off-grid detection moved to control.is_off_grid() so both features use the same rules. Tests blank the new env key like the other production-only ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main.py builds the guard at import, before logging is configured, so the state load's "resumed" line was lost. Load it on the first step instead, like ControlRuntime does in attach(). "turning shadow scan off" was logged even when it was already off; say "holding" instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Shadow scan (the PV global MPPT scan) misbehaves while the inverter is off-grid. With
OFF_GRID_SHADOW_SCAN_GUARD=on:shadow_scanvalue is read and remembered, then 0 is written. If it was already 0, nothing is written.OFF_GRID_SHADOW_SCAN_COOLDOWN_MIN(default 15), the remembered value is written back. A new drop during the cooldown restarts it.CONTROL_MODE, so it works with battery control off.Why a 15 min cooldown
In the 1-year history, outages come in bursts. On 2025-09-23 the grid dropped again 123–904 s after returning, and on 2026-05-05 after 182 s. The battery control's 60 s off-grid release is fine for currents, but would toggle shadow scan on every flap.
How
shadow_scan_guard.py: a small state machine stepped from the 1 Hz poll loop with the current goodwe object, so reconnects are handled.shadow_scan_guard.json(git-ignored): saves the pending restore, so a restart mid-outage still puts the value back. After a restart the cooldown starts over.control.is_off_grid(): off-grid detection moved out ofSample.from_runtime, so the guard and the battery control use the same rule.tests/__init__.pyblanks the new key, and the env-isolation test covers it, so a test run in the Pi's live checkout can't touch the real inverter.Test plan
python -m unittest discover -s tests: 584 pass, 20 of them new intests/test_shadow_scan_guard.py. They cover:OFF_GRID_SHADOW_SCAN_GUARD=onand restart. Check the next outage in the log (Off-grid: holding shadow scan off…shadow scan back to 1).🤖 Generated with Claude Code