Skip to content

Extend dynamic load high-load baseline into next slot on sustained spikes#4269

Merged
springfall2008 merged 2 commits into
mainfrom
fix/dynamic-load-extend-next-slot
Jul 19, 2026
Merged

Extend dynamic load high-load baseline into next slot on sustained spikes#4269
springfall2008 merged 2 commits into
mainfrom
fix/dynamic-load-extend-next-slot

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Summary

  • dynamic_load()'s high-load branch (used by switch.predbat_metric_dynamic_load_adjust) only floored the near-term load forecast through the end of the current plan interval, so an observed spike (e.g. a car charging outside any known/Octopus dispatch slot) was briefly "forgotten" by the plan right at each slot boundary until the next cycle re-evaluated it.
  • If load has been "high" for two consecutive checks in a row, the floor now also extends into the following slot, mirroring the existing two-reading debounce already used by the low-load car-slot cancellation branch just above it.
  • The floor is applied via max() against the regular load estimate in step_data_history(), so this never double-counts load that was already forecast that high.

Test plan

  • Added test_dynamic_load_high_load_baseline (apps/predbat/tests/test_dynamic_load.py) covering: car charging outside all known slots, car recognised in a fully-covering slot (with/without car_energy_reported_load), and the new two-consecutive-checks extension into the next slot.
  • Verified each new assertion actually catches a regression by temporarily reverting the corresponding logic and confirming the test fails, then restoring it.
  • ./run_pre_commit passes (ruff, black, cspell, markdownlint, full quick test suite).

🤖 Generated with Claude Code

…ikes

When metric_dynamic_load_adjust detects high load (e.g. a car charging
outside any known/Octopus slot) it only floored the load forecast for
the remainder of the current plan interval, so the plan briefly reverted
to the historical estimate right at each slot boundary until the next
cycle re-evaluated. If load has been high for two consecutive checks in
a row, also extend the floor into the following slot, mirroring the
existing two-reading debounce already used by the low-load car-slot
cancellation branch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 17, 2026 20:45

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 improves Predbat’s dynamic_load() high-load handling so that when sustained load spikes occur (e.g., unexpected car charging outside known/dispatch slots), the load floor used for near-term planning is carried across the slot boundary rather than being “forgotten” at the end of the current plan interval.

Changes:

  • Extend the high-load baseline into the following plan slot when high load is detected on two consecutive checks.
  • Add a dedicated unit test covering high-load baseline behavior across several car-slot attribution scenarios, including the two-check extension.
  • Update documentation describing the dynamic-load behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
docs/customisation.md Documents the sustained high-load extension into the next slot.
apps/predbat/unit_test.py Registers the new dynamic-load high-load baseline test in the unit test runner.
apps/predbat/tests/test_dynamic_load.py Adds test_dynamic_load_high_load_baseline validating baseline behavior and the new two-check extension.
apps/predbat/plan.py Implements the two-consecutive-high-checks extension for the dynamic load baseline window.

Comment thread docs/customisation.md Outdated
Comment thread apps/predbat/plan.py
Comment on lines 133 to 136
# When dynamic load is enabled we try can do two things
# 1. Increase the load prediction in the current self.plan_interval_minutes minute period to match the actual load (if the load is higher than expected)
# 1. Increase the load prediction in the current self.plan_interval_minutes minute period to match the actual load (if the load is higher than expected),
# extending into the following period too once the load has been high for two consecutive checks in a row (mirrors the low-load debounce below)
# 2. If the load is low and car charging is predicted then cancel off future car slots
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008
springfall2008 merged commit 75683b0 into main Jul 19, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/dynamic-load-extend-next-slot branch July 19, 2026 14:36
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