Repository navigation
core: shorten horizon for short consumption forecasts instead of failing - #476
Conversation
A consumption forecast shorter than requested only raised an error when it was more than FORECAST_TOLERANCE slots short. The Home Assistant provider is capped at 48h, while price and production forecasts can reach further, so the run failed and the inverter fell back to Allow Discharging. Reduce the forecast horizon to the available consumption data, as is done for prices and production. Only an empty forecast is an error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
An unresolved active finding flags that the broadened reduced-horizon forecast path lacks regression test coverage, leaving the fix unverified.
1 open issue
What changed in this PR
This PR makes batcontrol more resilient when the consumption forecast is shorter than the price/production forecast horizon. Previously, if the Home Assistant consumption provider (capped at 48h) returned fewer slots than the ~52.5h price/production horizon and the shortfall exceeded a fixed FORECAST_TOLERANCE of 3 slots, the control cycle raised RuntimeError and the inverter fell back to Allow Discharging. The change aligns consumption handling with how prices and production are already harmonized: a short forecast simply shortens fc_period rather than aborting the cycle.
Changes:
- A consumption forecast shorter than requested now reduces
fc_periodto the available data instead of failing. - Only an effectively empty forecast (
len < MIN_FORECAST_HOURS) still raises an error. - Removes the now-unused
FORECAST_TOLERANCEconstant.
| File | Description |
|---|---|
src/batcontrol/core.py |
Replaces the tolerance-bounded error check with an unconditional horizon reduction for short consumption forecasts, keeps the empty-forecast error branch, and drops the unused FORECAST_TOLERANCE constant. |
Review effort: Balanced

Problem
With the Home Assistant consumption forecast the run failed:
The HA provider is capped at 48h (
MAX_FORECAST_HOURS, 192 slots at 15 min, minus 1 for the shift to the current interval). Price and production forecasts reached ~52.5h. The shortfall was larger thanFORECAST_TOLERANCE(3 slots), so the run raised and the inverter fell back to Allow Discharging.Change
fc_periodto the available data, as already done for prices and production.MIN_FORECAST_HOURS) is still an error.FORECAST_TOLERANCE.Testing
Existing tests pass (
tests/batcontrol, web tests and tests needingpytest-mocknot run locally). No new test added.🤖 Generated with Claude Code