Fix Dynamic load baseline: exclude car energy - #4708
Open
nickgee31 wants to merge 4 commits into
Open
Conversation
Convert dynamic load baselines to kWh-per-PREDICT_STEP and remove car energy from the carried baseline when possible. Measured car-energy increments are summed and subtracted from the last-period baseline; if unavailable, the planned slot power is used after converting to kWh. Logging updated to reflect kWh units. Added tests covering measured exclusion, planned-slot fallback conversion, and handling of lagging sensor readings to ensure the residual baseline represents house load only.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The fallback samples the current slot rather than the measured trailing period, and the tests leak shared state.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates dynamic-load baselines to exclude EV charging energy from measured household load.
Changes:
- Converts recent load and planned car charging to per-step kWh.
- Uses measured car energy with planned-energy fallback.
- Adds regression scenarios for measured, missing, and lagging sensor data.
File summaries
| File | Description |
|---|---|
apps/predbat/plan.py |
Excludes EV energy from dynamic-load baselines. |
apps/predbat/tests/test_dynamic_load.py |
Adds EV-energy baseline tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fix car energy fallback by computing planned car energy as the summed per-minute kW over the trailing PREDICT_STEP minutes (converted to kWh), which correctly handles partial slot overlaps and avoids using an instantaneous slot power as before. Make car_load_planned a float and adjust dynamic_load logic comments. Update tests: add copy import, save/restore test state to avoid leakage, adjust car slot start times and expected comments/strings to match the new trailing-period calculation. This corrects inaccurate kW→kWh conversion and stabilises tests.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The measured-sensor test can pass using only the planned-energy fallback.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Issue
PR #4269 correctly extended a sustained high-load prediction into the following slot. However, the new logic recalculated car charging from the future slot rather than using the actual car energy measured during the last five minutes.
When the planned car slot ended, car subtraction became zero, so the full measured load—including the car—was carried into the next slot. This inflated the predicted import.
The configured car_charging_energy sensor was already used for historical load filtering, but was missed in this new dynamic-load path. PR #4269
Fix
The follow-up change: