fix(load): add switch-load off-hysteresis and remove phantom first-cycle feedforward#11
Merged
Merged
Conversation
…cle feedforward Two switch-load correctness fixes: 1. Switch loads turned off at residual >= 0. After turn-on the residual sits at ~0 W by construction (the load consumes the surplus that triggered it), which is exactly the off threshold — any noise beyond the deadband flapped the load off again, up to two switch actions per minute with the default 30 s debounce. The off threshold is now 10% of the load's fixed power (SWITCH_LOAD_OFF_FRACTION), giving a real hysteresis band. 2. The numeric-load absorption fed forward to switch decisions was computed from a snapshot taken before loads are initialised from their entity state. On the first cycle that a running load is seen (e.g. an EV already charging at 16 A after a restart), the snapshot default of setpoint_min produced a fictitious absorption of thousands of watts, suppressing or mis-triggering switch loads. Absorption is now derived from the distribution return values, so initialisation cannot leak into the feedforward. https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
e3261e7 to
a9d6ba9
Compare
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.
Problem
residual ≥ 0. After turn-on the residual sits at ~0 W by construction (the load consumes exactly the surplus that triggered it), which is precisely the off threshold — any noise beyond the deadband flapped the load off again. With the default 30 s debounce that is up to two relay actions per minute on a boiler or pump.setpoint_minproduced a fictitious absorption of thousands of watts, suppressing or mis-triggering switch-load decisions in that cycle.Fix
SWITCH_LOAD_OFF_FRACTION), giving a real hysteresis band. Turn-on behaviour is unchanged (surplus ≥power_w)._load_sp_beforebookkeeping entirely.Tests
New: load stays on at 150 W import (below the margin), turns off at 400 W (beyond it), and the restart scenario — EV at 16 A unseen by the engine, 2500 W export — now correctly turns the boiler on where the phantom absorption previously suppressed it. Full suite: 242 passed.
https://claude.ai/code/session_01RUWpwxbGsgR3PoLHLq4Djz
Generated by Claude Code