[codex] Change battery actions to policy states - #15
Merged
Conversation
LordMike
commented
Apr 22, 2026
LordMike
marked this pull request as ready for review
April 22, 2026 13:09
LordMike
commented
Apr 22, 2026
LordMike
commented
Apr 22, 2026
LordMike
commented
Apr 22, 2026
LordMike
commented
Apr 22, 2026
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.
Issue
WattPlan exposed battery action states that looked like raw flow states (
hold,discharge,charge_pv,charge_grid_pv). That madeholdespecially misleading: the planner could mean "no modeled battery flow", while inverter automations often interpret it as "block discharge". In a real system, PV may cover forecast load while the battery should still be allowed to cover unexpected load spikes.Fix
This changes the public battery action contract to inverter-control policy states:
preserve: prevent battery discharge because the model shows spending energy now is bad or infeasible.self_consume: normal operation; allow battery discharge for real load and do not request grid charging.grid_charge: request/allow grid charging and avoid spending the battery while charging.PV charging remains implicit/normal behavior. PV export is intentionally not represented as a battery action state and is deferred for future site-level policy design.
What Changed
gc,p, andscfor the three policy states.prefer_pv_surplus_chargingconfiguration/docs where it conflicted with the policy model, leaving it documented only as internal/deferred optimizer behavior.battery_preservesignal to optimizer state and warm-start reuse.preserve; otherwise it defaults toself_consumeunless grid charging is active.Validation
./scripts/run_tests.sh135 passed in 4.65sCaveats
preservenow requires additional counterfactual solver calls for candidate battery slots.preserve; they only affect preserve through model constraints/objective impact.