Skip to content

fix(mpc): give Energyplan 1.5 s when a car is plugged in - #1515

Merged
frahlg merged 1 commit into
masterfrom
fix/energyplan-ev-budget
Oct 4, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix/energyplan-ev-budget

Conversation

@frahlg

@frahlg frahlg commented Oct 4, 2026

Copy link
Copy Markdown
Member

Problem

Core gives the Energyplan planner 0.5 s unless the model is large, demand charges apply or PV curtailment is active. Since #1440 most homes with one car fall under 0.5 s. On the home Pi 4 that sits just below the point where the planner can improve on its first plan for the car.

Two plans with the car on the home box (v0.139.3-dev test build with Energyplan 0.5.0, 3 Oct, 112-113 slots) came back about 11% above the proven HiGHS optimum: 6 800.21 against 6 115.16 öre and 6 770.17 against 6 098.44 öre. Replaying the same requests on a laptop, the planner reaches the optimum at about 30-35 ms there, which is about 0.6-0.7 s on the Pi. Below that it returns its first plan.

Change

Requests with an active loadpoint get 1.5 s (energyplanEVBudget). Battery-only requests keep 0.5 s; large fleet, demand-charge and curtailment requests keep 5 s. The remaining time of the first slot still caps every budget, as before.

Evidence

  • The 116 real requests with the car from the box's 0.5 s class (1-2 Oct), run with Energyplan 0.5.0 at the laptop equivalent of 0.5 s and of 1.5 s on the Pi: the summed gap to the proven optimum falls from 7 676 to 3 249 öre, plans within 0.5% of it rise from 111 to 114, 4 requests get cheaper and none get dearer. Short-charge deficits do not change.
  • On the box with this branch, the first plan with the car used the 1.5 s budget (1 516 ms).

Known limitation

The same morning request showed a case where more time does not lower the bill: a car 253 Wh short of its target, less than one five-minute run at the lowest step. With more time the planner proves that a plan without a short run exists and then requires one, and the search found such a plan at 924 öre where the optimum is -116.89 öre. With less time it returned -110.8 öre with a 191 s short run. The charging-period preference ranks above cost by design, and v0.4.10 behaves the same. Whether a need smaller than one minimum run should count as met is an open product decision for Energyplan.

Verification

  • TestEVGetsLongerBudgetThanBatteryAlone (new) and TestBatterylessEVBudgetDoesNotInventStorage (updated) fail without the change and pass with it.
  • make native-solver-test and make verify pass.
  • Installed and running on the home Pi 4 box as v0.139.3-dev.c33c2c4a (same change on top of chore(optimizer): bundle Energyplan 0.5.0 #1512).

Checklist

  • The change follows VISION.md and one selected scope.
  • I checked overlapping PRs and coordinated shared files/contracts. No open PR touches go/internal/mpc/energyplan.go.
  • Relevant checks cover the changed behaviour and failure paths.
  • A human reviewed changed UI in a browser, or no UI changed. No UI changed.
  • A Changeset is included (patch), or the change is exempt.
  • Every commit has a DCO sign-off.

🤖 Generated with Claude Code

On the home Pi 4, two plans with the car came back 11% above the proven
optimum at Core's 0.5 s budget. On the same requests the planner reaches
the optimum with about 0.6-0.7 s of Pi time, so 0.5 s sat just below the
point where it can improve its first plan. Requests with an active
loadpoint now get 1.5 s; battery-only requests keep 0.5 s, and fleet,
demand-charge and curtailment requests keep 5 s. The remaining time of
the first slot still caps every budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T03:19:10.871105Z f594f1f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg merged commit 4dce1ff into master Oct 4, 2026
15 checks passed
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.

1 participant