logic: add forecast grid charge target strategy#361
Conversation
58656a4 to
21c2e72
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in forecast strategy for determining the effective minimum grid-charge SoC target at runtime, while keeping the default fixed behavior unchanged. The effective target is computed from forecasted net demand during upcoming expensive price slots (with optional PV forecast discounting) and is then passed into the logic layer and exposed via MQTT.
Changes:
- Introduces
batcontrol.logic.grid_charge_target.calculate_effective_grid_charge_soc()withfixedandforecaststrategies. - Adds core config parsing and per-run computation of
effective_min_grid_charge_soc, passing it intoCalculationParametersand publishing it via MQTT. - Extends MQTT API + discovery and adds unit/integration-style tests for the new behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/batcontrol/logic/grid_charge_target.py |
New module implementing effective grid-charge SoC target calculation strategies. |
src/batcontrol/core.py |
Parses new config, computes effective target each run, publishes it to MQTT, and feeds it into logic parameters. |
src/batcontrol/mqtt_api.py |
Publishes the effective target and exposes it via Home Assistant MQTT discovery. |
tests/batcontrol/logic/test_grid_charge_target.py |
Unit tests for fixed/forecast target computation and capping behavior. |
tests/batcontrol/test_core.py |
Validates config parsing and verifies core passes/publishes the effective target. |
tests/batcontrol/test_mqtt_api.py |
Tests MQTT publishing + discovery for the new effective target sensor. |
config/batcontrol_config_dummy.yaml |
Documents the new optional config keys in the dummy config. |
| if isinstance(values, dict): | ||
| if not values: | ||
| return [] | ||
| return [values[index] for index in range(max(values.keys()) + 1)] |
There was a problem hiding this comment.
Addressed in f5261de: sparse/non-consecutive forecast dict indices now raise a clear ValueError, covered by a regression test.
21c2e72 to
f5261de
Compare
|
Addressed the two Copilot comments in f5261de: forecast dict indices now fail with a clear ValueError/regression test, and grid_charge_target_strategy parsing now strips whitespace before lowercasing. |
f5261de to
e054693
Compare
| else: | ||
| self.avoid_discharging() | ||
|
|
||
| def __calculate_effective_min_grid_charge_soc( |
There was a problem hiding this comment.
I tried to move all these calculations over to the logic/ packages and have core.py more like a wiring and function router place.
With this context, does it make sense to have it here in the code, or not?
There was a problem hiding this comment.
Good point. Addressed in 690a32a: the grid-charge target config parsing and effective-target resolver now live in batcontrol.logic.grid_charge_target; core.py only builds CalculationInput, calls the logic helper, publishes the effective target, and passes it into CalculationParameters.
e054693 to
690a32a
Compare
690a32a to
7b2bd3c
Compare
|
Ok, I did another review and try to understand what you did there. |
Adds an opt-in
forecastgrid-charge target strategy while keeping the defaultfixedbehavior unchanged.With
forecast,min_grid_charge_socremains a floor, and batcontrol raises the effective target from forecasted expensive-slot net demand, capped bymax_charging_from_grid_limit.Also publishes the runtime effective target via MQTT/Home Assistant discovery.
I’ll add the corresponding wiki documentation after merge.