feat: accept an external consumption forecast as a time-series entity - #437
Draft
johanzander wants to merge 4 commits into
Draft
feat: accept an external consumption forecast as a time-series entity#437johanzander wants to merge 4 commits into
johanzander wants to merge 4 commits into
Conversation
…#428) BESS optimizes against forecasts but never modelled loads itself — for consumption every existing strategy was either a constant or an in-house statistical model, none able to express a known, shaped load (an EV session, weather-driven aircon) the user can predict but a trimmed-mean baseline deliberately discounts as an outlier. Adds `ha_consumption_series`: a new strategy reading a user-authored HA entity with `raw_today`/`raw_tomorrow` timestamped {start, value} attributes, mirroring the existing price-manager pattern rather than solar's hour-indexed parser (which structurally can't represent sub-hourly data). Accepts 15- or 60-minute record spacing, normalized onto the DP's quarter-hour grid; a missing, stale, malformed, or horizon-short series is an explicit ConsumptionForecastUnavailableError, never a silent fallback to a flat profile — unlike ha_statistics's fixed-value fallback on insufficient data. Also renames the scalar `sensor` strategy's misleading "Consumption Forecast" UI category to "Consumption Average (48h Rolling)", since it was never a real forecast, and adds an example HA template so the seam is usable without starting from a blank YAML file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ption-forecast-series # Conflicts: # CHANGELOG.md
…ption-forecast-series # Conflicts: # CHANGELOG.md
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
ha_consumption_series: a new consumption-forecast strategy reading a user-authored HA time-series entity (raw_today/raw_tomorrowattributes of timestamped{start, value}records), mirroring the existing price-manager entity pattern rather than solar's hour-indexed parser (which can't represent sub-hourly data).ConsumptionForecastUnavailableError— this strategy never silently falls back to a flat profile, unlikeha_statistics's fixed-value fallback on insufficient data.sensorstrategy's misleading "Consumption Forecast" UI category to "Consumption Average (48h Rolling)" (it was never a real forecast) and adds a new "Consumption Forecast Series" category for the new entity.docs/USER_GUIDE.mdso the seam is usable without starting from a blank YAML file.Root cause
From the issue: every existing consumption strategy is either a constant or an in-house statistical model.
ha_statistics's trimmed mean deliberately discounts one-off spikes (the right call for outlier robustness) but as a side effect is permanently blind to a known, predictable load like an EV session — nothing puts that load back into the forecast. Solar has an external-forecast seam (Solcast); consumption had none.Fix
HomeAssistantAPIController.get_consumption_forecast_series()/get_consumption_forecast_series_tomorrow()(core/bess/ha_api_controller.py) — fetch and normalize the entity, mirroringprice_manager.py'sraw_today/raw_tomorrowparsing.BatterySystemManager._get_consumption_forecastdispatches to it for the new strategy;_extend_consumption_predictions(extracted from the existing tomorrow-horizon-extension logic) uses the entity's realraw_tomorrowdata instead of repeating today's pattern when the DP horizon spans midnight — the same treatment solar's_fetch_tomorrow_solar_forecastalready gets.sensor_collector.check_prediction_health) and the strategy-comparison endpoint (get_consumption_forecast_comparison) both cover the new strategy.HomeFormSection.tsx, sensor category rename + addition insensorDefinitions.ts, updatedSensorConfigSection.tsxdetection logic,ConsumptionForecastComparison.tsxchart labels/colors.Test plan
./scripts/quality-check.shpasses locally (fast suite: 1399 passed, 15 skipped; frontend: 103 passed; Black/Ruff/TypeScript/ESLint clean).venv/bin/pytest -m slowpasses (394 passed, 3 skipped)docker-compose.ci.yml(real backend + mock-HA): configured the new strategy and a shaped entity via the realPATCH /api/settingsAPI, confirmedGET /api/consumption-forecast-comparisonreturns the correct shaped hourly profile (EV hour at 16.0 kWh vs 1.2 kWh baseline) through the live system, confirmed the health check reportsOKwith the exact shaped series and then a clearERROR(no silent fallback) when the entity'sraw_todaydata was removed, and confirmed the new frontend strings are present in the actual served JS bundleCloses #428