Skip to content

Balanced: forecast-aware real-time battery reserve (#73) - #76

Open
MonsterD1 wants to merge 1 commit into
InventoCasa:mainfrom
MonsterD1:feat/73-balanced-forecast-reserve
Open

MonsterD1 wants to merge 1 commit into
InventoCasa:mainfrom
MonsterD1:feat/73-balanced-forecast-reserve

Conversation

@MonsterD1

@MonsterD1 MonsterD1 commented Nov 13, 2026 •

Copy link
Copy Markdown

Problem

With Balanced, the configured target SoC and target time only reach the planner. In real-time control, _power_for_optimizer() reserves battery charging only for Battery First, so Balanced (with Plan Influence = None) hands the whole charging power to appliances, even on a dull winter day with the battery far below target and almost no export. On such a day a low-priority load can run for hours on power that would otherwise have charged the battery, and briefly on battery discharge until its switch interval expires.

Change

Balanced now uses the existing Battery First reservation in real time, but only when the forecast is not enough:

needed_kwh = (target_soc - soc) / 100 * battery_capacity
usage_kwh  = hours_until_target_time * 0.5 kW   # planner default base load
reserve    = remaining_today_kwh - needed_kwh - usage_kwh < 0.5 kWh
  • Sufficient forecast: no reservation, appliances keep the full surplus (unchanged behavior, battery status forecast_sufficient).
  • Insufficient forecast: battery_first_budget() is applied unchanged (charge cap, live limit, measured charging).
  • Hysteresis: once reserving, the margin must exceed 1 kWh before release.
  • No available forecast (not configured / pending / unavailable): Balanced behaves exactly as before. Missing SoC with an available forecast uses the Battery First safety path.
  • Planner Balanced split and Appliance First are untouched.

Code: power_policy.forecast_reserve_needed() (pure function), coordinator._balanced_forecast_reserve(), two constants in const.py, docs in docs/energy-policy.md.

Open for discussion

The 0.5 kW base load and 0.5 kWh buffer are constants. If you prefer, I can expose them as options or make the behavior opt-in instead of default for Balanced.

Validation

  • New regression tests in tests/test_power_policy.py: decision table, missing inputs, insufficient/sufficient forecast, no forecast unchanged, missing SoC fallback, hysteresis.
  • Full suite on the HA 2025.8 / Python 3.13 stack: 1308 passed. scripts/check_public_tree.py: 0 findings.

Closes #73

Balanced now reserves battery charging in real time, like Battery First,
when the remaining PV forecast cannot cover the missing energy to the
target SoC plus the expected house load until the target time. With a
sufficient forecast, appliances keep the full surplus. Without an
available forecast, Balanced behaves as before.
@MonsterD1
MonsterD1 force-pushed the feat/73-balanced-forecast-reserve branch from 335aea9 to bb036b4 Compare November 13, 2026 13:15
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.

Feature request: forecast-aware battery reserve in real-time control (Balanced)

1 participant