Skip to content

Fix Dynamic load baseline: exclude car energy - #4708

Open
nickgee31 wants to merge 4 commits into
springfall2008:mainfrom
nickgee31:fix-car-charging-high-load
Open

Fix Dynamic load baseline: exclude car energy#4708
nickgee31 wants to merge 4 commits into
springfall2008:mainfrom
nickgee31:fix-car-charging-high-load

Conversation

@nickgee31

Copy link
Copy Markdown
Contributor

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:

  • Converts the measured load into kWh per prediction step.
  • Removes measured car energy from the latest five-minute period.
  • Uses planned car energy as a fallback when the sensor is unavailable or has no increment.
  • Handles lagging or partial sensor readings conservatively by using the larger credible car-energy value.
  • Carries only the residual household load into the next slot.
  • Preserves the original sustained high-load behaviour for genuine household load.

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.

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.

🟡 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.

Comment thread apps/predbat/plan.py Outdated
Comment thread apps/predbat/tests/test_dynamic_load.py Outdated
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.

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.

🟡 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

Comment thread apps/predbat/tests/test_dynamic_load.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.

🟢 Approval recommended

The implementation addresses the boundary case with focused regression coverage and no unresolved issues.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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.

2 participants