Repository navigation
fix(mpc): active arbitrage can grid-charge beside a surplus-only EV - #953
Conversation
Surplus-only already keeps the car off the grid and blocks battery→EV. The extra site-wide ban on home-battery import while the charger is occupied made Pixii sit at evening SoC instead of buying the cheap hours. Persist last-known spot into unpublished prices so the climatology does not invent an overnight crash, and raise the load twin's overnight prior from 300 W to 650 W. Co-authored-by: Fredrik Ahlgren <[email protected]>
The warm-up loop added 300+7i days, which landed on a different hour-of-week than the Monday 03:00 prediction. It only passed while the prior was 300 W, close to the 350 W target. Co-authored-by: Fredrik Ahlgren <[email protected]>
The lift of the home-battery import ban must not let the car import when it has a deadline and no PV. Unpublished prices must also leave the last-known spot over the horizon, not only in the first hour. Co-authored-by: Fredrik Ahlgren <[email protected]>
…y EV The EV-reserve charge ceiling is a PV-sharing cap. On a slot the planner already committed to importing, applying it at night (no surplus → ceiling 0 W) cancelled the Pixii charge while the car sat plugged and idle. Skip the ceiling on deliberate grid-charge slots. Co-authored-by: Fredrik Ahlgren <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cefde55350
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| hour := hourOfWeek % 24 | ||
| isWeekend := weekday >= 5 // Saturday (5), Sunday (6) | ||
| base := 300.0 // overnight baseload | ||
| base := 650.0 // overnight baseload — typical Swedish house today, not 2010 |
There was a problem hiding this comment.
Preserve valid low-load buckets after raising the prior
When an existing site's learned overnight mean is between roughly 75 W and 162.5 W, loading the model now classifies it as poisoned because repairPoisonedBuckets compares against typicalPrior * 0.25. It then replaces the learned value with 650 W and resets its samples, even though the adjacent comment explicitly treats a 150 W household as valid. Raising the prior therefore destroys legitimate persisted learning on restart; keep the repair cutoff at its previous absolute range or otherwise decouple it from this cold-start prior.
Useful? React with 👍 / 👎.
Accepted text proposal
Issue or Discussion: Slack thread 2026-08-18 (xorath: active arbitrage has not bought from the grid for 1–2 months).
Maintainer comment that accepted this scope: evaluate with parallel agents, merge, then beta. Version Packages #946 already has LAN-auth / mDNS / GitHub-outage patches; after this lands it should pick up the arbitrage changeset too.
What changed
Planner and dispatch were refusing home-battery import while a surplus-only EV was plugged in.
Planner. Surplus-only (including auto
deferGridPlan) forbade(battery charge AND site import)for the whole horizon. Removed from Go DP, Python optimizer, andValidatePlan. The car still cannot import; the battery still cannot feed the car.Dispatch (found in evaluation). Even after the planner said “import 5 kW”, the EV-reserve charge ceiling treated “no live PV surplus” as a 0 W cap and zeroed Pixii on the tick. That ceiling now applies only to PV-soak slots, not to deliberate grid-charge (
PlannedGridW ≥ 100 W).Unpublished prices persist the last known spot and e-fold toward climatology over ~6 h, so midnight does not fake a 200→70 öre crash.
Load-twin overnight prior 300 W → 650 W for cold start / repaired night buckets.
Why
xorath: v2, active arbitrage, EV takes most PV, Pixii ~35 % by evening, no grid buy for 1–2 months. Default optimizer path is HiGHS; Core
ValidatePlanthen rejected any grid-charge plan and fell back to Go DP which had the same ban. Dispatch would have zeroed it anyway at night. Three locks, same symptom.Boundaries and safety
TestEnergyDispatchAbsorbsSurplusBeyondEVReserveActualDraw).source="forecast"rows. Day-ahead untouched.After merge: wait for Version Packages #946 to include this changeset, merge it, then dispatch both
beta.yml(v2.1.0-beta.1) andoptimizer-release.yml(1.4.0-beta.4) from that commit. Core-only is not enough for the CVXPY fallback path; the HiGHS default is unblocked by Core alone.Verification
cefde553.go test ./internal/mpc ./internal/control ./internal/loadmodelpass, includingTestEnergyDispatchHonoursPlannedGridChargeWithIdleSurplusOnlyEV(the evaluation probe that failed before the dispatch fix).pytest optimizer/tests/test_model.py— 120 passed.Checklist