fix(mpc): self-consumption terminal SoC price = mean import, not spread - #299
Merged
Merged
Conversation
Live regression (2026-05-25): planner picked "idle — export PV surplus" for every slot, leaving the fleet at 7.5 % SoC while exporting 4+ kWh of free PV mid-day. selfConsumptionTerminalPrice was returning mean(import) − mean(export) — the arbitrage spread. On realistic SE tariffs (mean import 210 öre/kWh, mean export 100 öre/kWh) that's ~110 öre/kWh, half the documented "mean import" value. DP cost comparison per kWh of PV in slot 0 with spread terminal: charge: +η × terminal = 0.95 × 110 = 104 öre (value of stored SoC) export: +spot = 98 öre (immediate revenue) Win for charge is ~6 öre — well inside the DP's action-quantization noise, so it picks export. With mean-import terminal (~210 öre): charge: +η × terminal = 0.95 × 210 = 200 öre export: +spot = 98 öre Solid +100 öre win for charge per kWh. Operator's "fill the battery when surplus exists" intuition restored. Grid-charging is not encouraged by the bigger terminal credit because mpc.go's strict self-consumption bias (line 583) triples the cost of HOUSE-driven grid import, including the implicit import required to grid-charge. PV-fed charging stays free and dominates; import-fed charging stays uneconomic. mpc/CLAUDE.md already documented the intended formula as "mean import price over horizon so the planner is SoC-neutral" — this fix aligns the implementation with the docs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Live regression — root cause
Active right now on homelab-rpi: 4 kWh of PV exported today while batteries sit at 7.5 % SoC. The planner picked "idle — export PV surplus" for every slot.
`selfConsumptionTerminalPrice` returned mean(import) − mean(export) (the arbitrage spread). On SE retail tariffs that's ~110 öre/kWh — half the value mpc/CLAUDE.md documents ("mean import price over horizon so the planner is SoC-neutral").
DP cost comparison per kWh of PV in slot 0
Spread's 6 öre margin sits inside the DP's action-quantization noise — it picks export. Mean-import gives a solid +100 öre/kWh preference for charging from PV surplus.
Why this doesn't open the door to grid-charging
`mpc.go` line 583 already triples the cost of HOUSE-driven grid import for self-consumption mode. That includes implicit imports required for grid-charging:
PV charging stays free and dominates; import charging stays uneconomic.
Tests
🤖 Generated with Claude Code