fix(load): stop zeroing genuine load when import exceeds it for a bucket - #4471
Merged
Merged
Conversation
load_today_comparison() zeroed a whole 5-minute bucket's house load out of both the actual and predicted totals whenever grid import for that bucket was >= the raw load, intended to exclude deliberate battery charging - but the house's own consumption during that minute still happened regardless of how much extra was imported to charge the battery, so only the import beyond the load should have been excluded, not the load itself. On any install that routinely grid-charges overnight (pulling more from the grid than the house draws), this silently dropped a large chunk of real consumption from both the Actual and Predicted in-day-adjustment totals, and made Predicted drift throughout the day as which buckets tripped the filter shifted with the charge window. Fixes batpred#4154, #2537. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Output.load_today_comparison() so that genuine household load is no longer zeroed out in 5‑minute buckets where grid import exceeds (or equals) the raw house load—an important correction for installations that routinely grid-charge (e.g., overnight), which previously caused both “Actual” and “Predicted” in-day totals to drift downward.
Changes:
- Adjusted
load_today_comparison()to keep counting real load in all buckets, while only tracking the excess import (import − raw load) for the diagnostic “import ignored” figure/logging. - Added a regression unit test that simulates sustained import > load and asserts the “so far” totals still include genuine consumption (per #4154 / #2537).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/predbat/output.py | Stops zeroing load when import >= raw_load; instead tracks excess import for diagnostics while keeping load in actual/predicted totals. |
| apps/predbat/tests/test_load_today_comparison.py | Adds regression test to ensure genuine load remains counted during heavy-import buckets. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
load_today_comparison()had a heuristic (output.py) meant to exclude deliberate battery charging from the in-day load totals: for any 5-minute bucket where grid import was >= the raw house load, it zeroed that whole bucket's load out of both the Actual and Predicted totals - not just the import that exceeded the load.The house's own consumption during that minute happened regardless of how much extra was imported to charge the battery, so only the import beyond the load should have been excluded, not the load itself. On any install that routinely grid-charges overnight (pulling more from the grid than the house draws at that moment - the normal case), this silently dropped a large chunk of real consumption from both totals, and made Predicted drift throughout the day as which buckets tripped the filter shifted with the charge window's start/stop/rate.
Root-caused via a reporter-supplied
predbat_debug.yamlreplay - see the investigation on #4154 for the full trace, including the log evidence (Today's predicted so far 7.8kWh ... 2.26kWh import ignored) showing roughly a quarter of both totals being dropped on a real capture.Changes
output.py: the import>=load branch now only tracks the excess import (import_value_today - load_value_today_raw) for the diagnostic log line, and no longer zerosload_value_today/load_value_pred- both flow into the totals as before.tests/test_load_today_comparison.py: new regression test constructing a scenario where import consistently exceeds raw load, asserting the genuine load is still counted (via the function's own diagnostic log line, since the published dashboard totals blend "so far" with a predicted-for-the-rest-of-today tail and aren't a clean readout of the specific total this changes).Fixes #4154, #2537.
Test plan
./run_all --test load_today_comparison)./run_all --quick- all tests pass./run_pre_commit- clean🤖 Generated with Claude Code