From 66bf7728c22b17f4cb22355c0815eb21c56c67fe Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Wed, 28 Oct 2026 20:10:08 +0100 Subject: [PATCH] core: shorten horizon for short consumption forecasts instead of failing 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 --- src/batcontrol/core.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/batcontrol/core.py b/src/batcontrol/core.py index 4b496371..13bff666 100644 --- a/src/batcontrol/core.py +++ b/src/batcontrol/core.py @@ -76,7 +76,6 @@ TIME_BETWEEN_EVALUATIONS = EVALUATIONS_EVERY_MINUTES * 60 TIME_BETWEEN_UTILITY_API_CALLS = 900 # 15 Minutes MIN_FORECAST_HOURS = 1 # Minimum required forecast hours -FORECAST_TOLERANCE = 3 # Acceptable tolerance for forecast hours CONTROL_SOURCE_API = 'api' CONTROL_SOURCE_OPTIMIZER = 'optimizer' @@ -777,10 +776,9 @@ def _run_once(self): consumption_forecast = self.fc_consumption.get_forecast( requested_slots) if len(consumption_forecast) < requested_slots: - # Accept a shorter forecast horizon if not enough data is - # available - if len(consumption_forecast) < max( - fc_period - FORECAST_TOLERANCE, MIN_FORECAST_HOURS): + # A shorter consumption forecast reduces the forecast horizon, + # like it does for prices and production + if len(consumption_forecast) < MIN_FORECAST_HOURS: # Note: string formatting to avoid f-string multiline issues in <=Python3.11 raise RuntimeError( "Not enough consumption forecast data available, requested %d, got %d" % (