Extend dynamic load high-load baseline into next slot on sustained spikes#4269
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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 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>
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
dynamic_load()'s high-load branch (used byswitch.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."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.max()against the regular load estimate instep_data_history(), so this never double-counts load that was already forecast that high.Test plan
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/withoutcar_energy_reported_load), and the new two-consecutive-checks extension into the next slot../run_pre_commitpasses (ruff, black, cspell, markdownlint, full quick test suite).🤖 Generated with Claude Code