Skip to content

feat(plan): give each charger its planned slots, cost and expected level - #2185

Merged
frahlg merged 2 commits into
masterfrom
car-plan-slots
Dec 5, 2026
Merged

frahlg merged 2 commits into
masterfrom
car-plan-slots

Conversation

@frahlg

@frahlg frahlg commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

What

HannesB's new charging screen for iPhone 1.2 draws a car's charge quarter by quarter: power, how much comes from the grid, the car's level and what the charge costs. The plan the box sends had only joined windows and a Wh total, so an app would have had to guess the rest or plan again on its own.

This gives each charger in the plan (plan.chargers[]) three new fields, all read from the plan the box acts on, whether Core's or Energyplan's. No second plan is made.

slots?: [{ startMs, durationMs, w, gridW, socPermille? }]
costMinor?: number
socEstimate?: true
  • slots are the windows' slots, the running slot first and counted whole, as totalWh counts it. Only slots with power are sent, and back-to-back slots with the same w, gridW and level (or no level) are one run whose durationMs is their sum. Without levels a long charge is one or a few entries; with levels each quarter is its own, since the level moves.
  • w is the slot's planned power, an average. A Core reserve or Energyplan plan can pulse the car at full power for part of a slot.
  • gridW is the import the charge adds while the rest of the plan stays as planned. The rest is the site's own power. With the default rule (the battery never feeds the car) that is sun; if the owner lets the battery cover the car, or boosts it, it may be battery too.
  • costMinor uses the plan's own cost function (SlotGridCostOre): import at the slot's price, the site's own power at the export price it gives up (spot + bonus − fee, or the flat price), and spill and curtailment free. Each pulse state counts on its own, as reserveSlotCost prices them. Energy only, no power fee. Rounded once; absent when a price is not known.
  • socPermille counts from the car's level now plus planned energy × 0.9 / capacity, capped at 100 %. It is sent only when the box knows both: never from a level assumed at plug-in, for a visitor's car, or with the default capacity. socEstimate marks it as the box's estimate.
  • The window fields do not change. planChargersVector keeps its bytes: a charger without the new fields encodes as before.

What is trimmed first

The battery plan keeps priority over car detail. When a plan is too large for its 16 KB bulk bucket:

  1. The plan's own slots are cut, the far quarter at a time, only while the plan would not fit even without the chargers' slots and cost. So plan.slots and the windows come out exactly as they did before this PR, for a plan that fits (it keeps every slot) and for one that does not (in the test, a 193-quarter plan keeps 144). Older apps see the same plan slots.
  2. Each charger's slots end with the plan's last slot; a run that goes past it is cut there.
  3. Each charger's slots lose their far quarter until the plan fits, down to none if they must. With no slots, socEstimate goes too.
  4. costMinor goes next.
  5. Last, as before, the chargers' far windows, keeping one each.

totalWh and costMinor cover the whole plan, so the slots can sum to less. An app with no slots draws the windows.

No registry names change: these are plan fields, as windows are.

Tests

  • go test ./internal/mpc ./internal/appproto ./cmd/ftw, and go test ./... in go/protocol
  • make verify, once, before pushing
  • New in internal/mpc: grid, sun, mixed, spill at the export limit, a limit crossed without the car, curtailment, one pulse priced per state, an outdated plan and an unknown charger. One test per planner: Core DP (the older single shape), Core reserve and Energyplan (a reserve plan through toPlan and ValidatePlan). The native worker test runs under make native-solver-test and skips without FTW_NATIVE_SOLVER. On this Mac it skipped, because no worker is bundled for the host.
  • New in cmd/ftw: a car with a goal (slots, cost 865 öre, levels 433/474/489‰), a charger with no car (nothing), a level assumed at plug-in, a visitor and no capacity (slots and cost, no levels), and a car's own level from the cars runtime.
  • New in internal/appproto: a wire vector, planCarSlotsVector, for the apps to copy. TestTheCarsSlotsNeverCostThePlanASlot pushes a 96-quarter plan (fits) and a 193-quarter plan (does not) with two chargers charging every quarter, and checks that plan.slots and the windows equal those of the same plan without car fields, while the chargers' slots are the nearest ones and end with the plan. Cutting plan slots first, as the first version of this PR did, fails it: 54 of 96 and 60 of 144 plan slots. TestACarsRunEndsWithThePlansLastSlot covers the cut of a run.
  • New in cmd/ftw: two grid quarters alike without a level are one 30-minute run.

Paired work

Release

The changeset is minor, as the earlier plan level field was: the plan carries new data the apps will show. The owner approves a minor here.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T14:03:01.696426Z b420b97 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b420b97e71

ℹ️ 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".

Comment thread go/cmd/ftw/app_link.go
Comment on lines +681 to +682
hours := max(0, s.End.Sub(from).Hours())
level += s.PowerW * hours * loadpoint.DefaultChargeEfficiency / st.VehicleCapacityWh

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Account for delivered pulse energy in the running slot's level

When the running slot uses a partial-duty charge, multiplying its average power by the remaining wall-clock time adds energy that may already have been delivered. loadpoint.Controller.computeCommandForBudget runs at the pulse ceiling until the energy budget is spent, rather than spreading delivery evenly. For example, a 15-minute slot averaging 3,667 W can deliver its entire budget at 11 kW in the first five minutes; reading the plan ten minutes into that slot still adds another 306 Wh here, although the current car level already includes the whole charge. This overstates that slot's expected level and every subsequent level. Calculate the running slot's remaining energy from its budget and delivery/pulse progress instead of assuming uniform delivery.

Useful? React with 👍 / 👎.

frahlg and others added 2 commits December 5, 2026 16:14
The plan an app reads or is pushed now carries, per charger, the slots the
plan charges in: the average power, the part bought from the grid, and the
car's expected level at each slot's end when the box knows the car's level
and capacity. It also carries what the charge should cost, in the plan's
own accounting. All of it comes from the plan the box acts on, Core's or
Energyplan's. Back-to-back slots with the same power, grid part and level
are one run.

A plan too large for its bucket cuts its own slots, and each heat zone's
with them, only while it would not fit without the chargers' slots and
cost, so it keeps the slots it kept before chargers carried them. The
chargers' slots end with the plan's, then lose their far end until the
plan fits; the cost goes next, then far windows and heat slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit 5569b39 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.

1 participant