Skip to content

fix(control): a battery boost makes the battery cover the boosted car - #2012

Merged
frahlg merged 4 commits into
masterfrom
fix/boost-covers-boosted-car
Dec 5, 2026
Merged

frahlg merged 4 commits into
masterfrom
fix/boost-covers-boosted-car

Conversation

@erikarenhill

@erikarenhill erikarenhill commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

While a battery boost is active, the charger reports the boosted car drawing (BatteryBoostEVChargingW above 100 W), and an online battery is above the boost's reserve, ComputeDispatch now:

  • lowers the battery target to at least grid zero for the house and the boosted car (currentTotal − gridW). gridW already leaves out car draw the boost does not cover.
  • keeps a plan target that discharges further.
  • lifts the plan's no-discharge rails for that tick: planHasNonDischargeIntent and the plan/exec sign floor. A battery manual hold already lifts them the same way.

The reserve clamp, battery limits, owner floor and the fuse guard still apply after this.

Second commit: the battery follows the car down as fast as it follows it up.

  • The reactive controller moves from the battery's live output. After the boosted car slowed or stopped, it eased the battery down by about 1 kW per 5 s tick (−9.5, −8.8, −7.9, −6.8 … kW) and exported the rest for up to a minute.
  • During a boost, and for 30 s after the car stops, a planner mode's reactive path now goes straight to its grid target. The energy path already sets an absolute target, so it is unchanged.
  • The cover also ends on the live EV reading, a tick before the loadpoint's copy of it.

Why

In planner_arbitrage, a boost was only a permission. On a live site the car drew 8.25 kW with the boost active, while an idle slot kept the battery at 0 W and a later charge slot charged it at +1.8 kW from the grid. The planner kept the battery for the evening's higher prices, which made the owner's "Boost for 1 h" do nothing. The UI tells the owner "Let the home battery feed the car for a while", and that is what this does.

Boundaries and safety

  • Never exports for the car: the target stops at grid zero from the meter. When the car stops but the charger still reports its draw, the battery covers only what the meter shows.
  • A battery at or below the boost's reserve has nothing to give, so the plan runs as before. That includes a planned grid charge in a cheap hour.
  • Above the reserve, a planned grid charge of the battery waits until the boost ends. This is the one golden change: seeded_ev_boost/043, planner_cheap, cheap slot, +5 kW grid charge → −3.2 kW, projected grid 8157 W → 0 W. That record is re-recorded; no other golden file changes.
  • No change without a boost, with a manual battery hold, or when the boosted car draws under 100 W.

Verification

  • New TestBatteryBoostFollowsTheCarBothWays: car 8 kW → 5 kW → stopped, over three ticks. It fails on the first commit (−7550 W instead of −5500 W when the car slows) and passes here. The second commit changes no golden record.
  • New TestBatteryBoostCoversCarWhatTheSlotSays covers idle and charge slots in arbitrage: no boost, boost with the car drawing, and the car stopped while the charger still reports it. It fails on master (idle slot gives 0 W) and passes here.
  • go test ./internal/control ./internal/loadpoint ./cmd/ftw ./internal/mpc, go vet ./internal/control.
  • Live on a Raspberry Pi site (Easee Cloud, Pixii 20 kWh, 3×16 A, planner_arbitrage):
Step Car Battery Grid Phases (A)
Before boost 8.25 kW 0 W +8.4 kW 11.4 / 14.8 / 10.9
Boost on, about 5 s later 8.25 kW −8.4 kW +0.1 kW −1.8 / −3.3 / −1.8
Car moved to 8 A 5.5 kW −6.2 kW after about 40 s −0.3 kW
Car back to 12 A 8.3 kW −8.8 kW −0.06 kW
Boost cancelled 8.3 kW plan resumes

Stopping the car with the second commit (same site):

Time Car (charger report) Battery order Grid
12:34:26 stop ordered 4.7 kW −6.8 kW −0.5 kW
12:34:36 car physically stops, not yet reported 4.4 kW −6.8 kW −4.7 kW
12:34:40 charger reports 0 0 +1.4 kW (plan's charge) −3.9 kW
12:34:46 0 +1.4 kW +4.2 kW

The battery now reacts within one tick of the charger's report. The export that remains, about 10 s, is Easee Cloud's reporting delay. With the first commit alone, the same stop left the battery easing down for about 50 s and exporting about 6 kW for 20–30 s.

Performance

A throwaway benchmark of ComputeDispatch on an arbitrage idle slot with a boosted car, 5 runs each, same machine:

  • master: 1335–1351 ns/op, 2304 B/op, 23 allocs/op
  • first commit: 1314–1323 ns/op, 2304 B/op, 23 allocs/op
  • second commit: 1321–1328 ns/op, 2304 B/op, 23 allocs/op

No measurable change.

Overlap

Draft #1789 (fuse protection as one function) rewrites parts of dispatch.go and touches seeded_ev_boost.json. It has conflicted with master since 27 Oct, so this PR is based on master. The change is one block after the path switch plus two boostCover checks.

Related: the boost was also stopped by a binding fuse. That is fixed separately in #2011.

Checklist

  • The diff implements one scope and does not add follow-on work.
  • I checked open pull requests that touch the same files (fix(control): fuse protection as one function #1789, above).
  • Tests cover the changed behaviour and its failure path.
  • No UI changed.
  • A Changeset is included.
  • Every commit has a DCO sign-off.

🤖 Generated with Claude Code

https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp

A boost was only a permission: in planner arbitrage or cheap modes an idle
or charging slot kept the battery at zero, or charging, while the boosted
car drew from the grid. While the charger reports the car drawing and a
battery is above the boost's reserve, the battery now discharges at least
to grid zero for the house and that car, never exporting for car draw the
meter no longer shows. A plan that discharges further keeps its target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp
Signed-off-by: Erik <758402+erikarenhill@users.noreply.github.com>
After the boosted car slowed or stopped, the reactive controller eased the
battery down from the boost's discharge by about 1 kW a tick, exporting the
rest for up to a minute. During a boost and for 30 s after the car stops, a
planner mode's reactive path now goes straight to its grid target. The live
EV reading also ends the boost's cover a tick before the loadpoint's copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp
Signed-off-by: Erik <758402+erikarenhill@users.noreply.github.com>

@frahlg frahlg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested. The tests are real: copied onto master, TestBatteryBoostCoversCarWhatTheSlotSays and the first leg of TestBatteryBoostFollowsTheCarBothWays fail there and pass here. A five-mode scratch matrix (self_consumption and the four planner modes, energy and legacy paths, idle/charge/discharge slots, car rising, steady, slowing, stopped, at reserve) projected no grid export below 0 W in any boosted case, and the only golden behaviour change is seeded_ev_boost/043. The full make verify passes on master with this PR merged.

One thing to change before merge:

  1. No-export modes lose their margin during a boost. planner_self, planner_cheap and planner_passive_arbitrage must never sell (batteryMayNotExport). The reactive path lifts their target to max(GridTargetW, GridToleranceW) for that reason (#1969). The cover aims at exactly grid zero (boostTotal = currentTotal - gridW, around dispatch.go 2231–2253), so with meter and charger lag those modes can export for a few seconds while a boost runs. Please use the tolerance-lifted target in those modes and add a test for them; the current tests cover only planner_arbitrage.

Smaller, your call:

  • The "car stopped" leg of TestBatteryBoostFollowsTheCarBothWays accepts −501…0 W and also passes on master.
  • Both tests set SlewRateW = 100000, so slew is not exercised.
  • Regenerating the whole golden file adds about 1e-6 W of float noise to unrelated records; re-recording only 043 would keep the diff to the one change.
  • boostCover is true when any one battery qualifies, so a sibling battery at its reserve also has its planned grid charge held back (then clamped, so no export).

@frahlg frahlg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude's review, posted at Fredrik's request. Read together with #2011.

This looks right.

  • The battery stops at grid zero from the meter, so it never exports for car power the meter no longer shows. The reserve, the battery's limits and the fuse guard still apply after it.
  • A boost now beats a planned cheap grid charge (golden seeded_ev_boost/043: +5 kW → −3.2 kW). That is a product change, and it matches what the owner asked for when they started the boost.
  • The description says a plan that discharges further keeps its target. That holds on the energy path. On the reactive planner path the battery goes straight to the plan's grid target during the boost, as the code comment says. Worth a word in the description.
  • The other hunks in the golden file are float noise under a watt from re-recording; only 043 changes.
  • boostCoverUntil is set inside ComputeDispatch. main.go is its only caller outside tests, so nothing else extends the hold.
  • There is no hysteresis at the 100 W threshold, but the 30 s hold covers a reading that flickers.

Checked locally with #2011 merged in: the same go vet and go test as there pass.

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Battery boost now covers the house plus the boosted car down to grid zero, lifts the plan's no-discharge rails while it does, and holds grid-zero for 30 s after the car stops so the battery drops to the house at once.

  • Read the dispatch.go diff in full. state is a pointer, so boostCoverUntil persists across ticks. boostCover needs a battery online, not discharge-blocked, with SoC above the reserve, so a battery at the reserve falls back to the plan.
  • boostCover skips applyPlanSignFloor, but reserve clamp, limits, owner floor and the fuse guard still run afterwards. That is what I'd want here.
  • Nit: during the 30 s hold a planner mode's reactive path ignores plan charge intent. It reads intended, and the comment says so. Worth a test for a boost ending exactly at a plan charge slot, if one isn't there already.
  • CI green, golden file updated.

Safe to merge from my read. Dispatch logic, so a human who knows the control loop should still sign off.

frahlg and others added 2 commits December 5, 2026 11:56
Conflict in the control State struct: master added BatteryBoostActive
next to the branch's boostCoverUntil. Both fields are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on #2012 (Fredrik, 14 Nov): planner_self, planner_cheap and
planner_passive_arbitrage never sell, but the boost cover aimed at
exactly 0 W and gave up the dead band the reactive path keeps (#1969).

- The cover and the 30 s hold use the same lifted aim as the reactive
  path, through one helper, noExportGridAimW. The reactive path now
  calls it too, so the two cannot drift.
- In those modes the cover goes no further than the latest meter and
  battery samples show, as the fast cut on export does (#2155).
  Without this the boost undid that cut while the smoothed meter
  caught up with a stopped car, and exported for three ticks.
- During a boost and the hold, a cut of discharge passes the slew
  limit, as the meter clamp's does. With the setup guide's 500 W slew
  the car's stop otherwise eased the battery down 500 W a tick, on the
  energy path in every mode.

Tests, with a 500 W slew where it matters:
- TestBatteryBoostKeepsTheNoExportBand: the three modes settle at the
  dead band, not 0 W; arbitrage keeps 0 W.
- TestBatteryBoostNoExportCutsAtOnceWhenTheCarStops: only the tick the
  car stops on exports, with and without charger lag.
- TestBatteryBoostFollowsTheCarBothWays: exact targets, a cover-load
  slot where the "car stopped" leg fails on master, and slew cases.
- TestBatteryBoostEndingAtAChargeSlotCharges: the hold does not hold
  back a planned charge, on the energy and legacy paths.

Golden: only seeded_ev_boost/043 is re-recorded, spliced into master's
file so the other records keep their values. planner_cheap, cheap
slot: -3157 W becomes -3097 W, projected grid 0 W becomes +60 W, the
record's GridToleranceW.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit bee4d8d into master Dec 5, 2026
22 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.

3 participants