Skip to content

fix(load): stop zeroing genuine load when import exceeds it for a bucket - #4471

Merged
springfall2008 merged 1 commit into
mainfrom
fix/inday-load-import-exceeds-load-zeroing
Aug 11, 2026
Merged

fix(load): stop zeroing genuine load when import exceeds it for a bucket#4471
springfall2008 merged 1 commit into
mainfrom
fix/inday-load-import-exceeds-load-zeroing

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

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.yaml replay - 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 zeros load_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

  • New unit test covers the fix directly (./run_all --test load_today_comparison)
  • ./run_all --quick - all tests pass
  • ./run_pre_commit - clean

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@springfall2008
springfall2008 merged commit cb1c2b1 into main Aug 11, 2026
3 checks passed
@springfall2008
springfall2008 deleted the fix/inday-load-import-exceeds-load-zeroing branch August 11, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-day load adjustment not working - predicted load continually changes

3 participants