Skip to content

fix(battery): plan and charge no higher than the battery's own ceiling - #2083

Open
frahlg wants to merge 2 commits into
masterfrom
pixii-ceiling
Open

frahlg wants to merge 2 commits into
masterfrom
pixii-ceiling

Conversation

@frahlg

@frahlg frahlg commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Problem and result

Refs srcfl/device-drivers#175

A Pixii Home 20 kWh stops charging at 90 % while the planner's ceiling is 95 % and the site has no battery soc_max. The plan said "90 → 95 %, 1.0 kWh", and dispatch kept ordering charge the battery never took. Pixii documents its upper SoC limits on the same scale as its SoC, so the paired driver PR, srcfl/device-drivers#281 (pixii 2.2.0), reports the device's own ceiling as max_soc_fract on the battery reading. That is the @srcful/data-models name for a battery's own maximum SoC. The SoC is not remapped.

Core now takes the lower of that ceiling and the configured one:

  • Telemetry. The store carries the ceiling on the battery reading (SoCCeiling, read through SoCCeilingNow), the way it carries SoC. A reading that leaves the ceiling out, for example after one failed limit read, keeps the last one for up to 10 minutes; the Pixii driver retries a register that missed three polls after 5 minutes. The ceiling drops with a stale reading (BatterySoCMaxAge) or a removed driver. A value below 50 % is taken as a misread, logged once and ignored: real ceilings sit around 80–100 %, and a misread must not stop charging.
  • Dispatch. The full-battery stop uses it: charge orders stop at the device ceiling and resume one point below, as with soc_max (fix(control): ship SOC ceilings and Charge restart recovery #1870). fuseTargetBounds closes the charge side there too. The API's battery_full reason and resume level follow. A ceiling at or below the battery's SoC floor is not used and is logged once.
  • Planner. onlineFleetParams caps each battery's MaxEnergyWh at its device ceiling and sets the fleet's SoCMax to the capacity-weighted result, so the Go DP and Energyplan plan to the same limit and the storage totals still match. A ceiling at or below the planner's SoC floor is not used. Only MaxEnergyWh changes on a storage.

A missing, zero, non-finite or out-of-range value changes nothing. A device ceiling never lifts a lower configured one.

Scope and safety

  • Lowers a ceiling only. Discharge, the SoC floor, fuse relief and manual discharge are unchanged.
  • The two guards (below 50 %, at or below the floor) mean a misread can at worst leave charging as it is today, never stop it on a half-empty battery.
  • Not changed: a battery's configured soc_max still reaches dispatch only, not the planner, which plans to the planner's soc_max. That gap is older than this PR. PV curtailment headroom still uses its fixed 99 %.

Overlapping open PRs, checked with git merge-tree against each head:

Verification

Local, macOS:

  • go test ./internal/control/ ./internal/mpc/ ./internal/telemetry/ ./internal/api/ ./internal/drivers/: ok.
  • GOFLAGS=-p=4 make verify: vet, tests and build clean. The bundled Energyplan worker is not built for macOS, so its execution tests skip.
  • New tests:
    • telemetry: parsing; the hold across a reading without the ceiling, and its end after 10 minutes; drop with a stale reading; a value below 50 % ignored without replacing a held one and logged once; no carry-over after Remove.
    • control.TestDeviceSoCMax*: the device ceiling stops charging in every mode with no soc_max configured, resume at 0.89. An absent or higher value keeps the configured ceiling. A ceiling of 0.05 with floor 0.10, and 0.55 with floor 0.60, does not stop charging and does not close the fuse bound. One missed limit read keeps the stop; 11 minutes without one releases it. A stale reading drops it. A raised ceiling releases the stop on the next tick.
    • mpc: per-battery MaxEnergyWh, weighted fleet SoCMax, validateStorageSpecs still passes; unusable ceilings change nothing; only MaxEnergyWh changes.
    • mpc.TestPlanNeverTargetsAboveTheDeviceCeiling: the field case through Replan with the Go DP. A 20 kWh battery at 90 % with cheap then dear hours. Without the ceiling the plan peaks at 94.6 %, the "90 → 95 %" finding. With max_soc_fract: 0.9 it never goes above 90 % and never charges at 90 %.
  • Against master code, the device-ceiling tests in control and mpc fail, as expected.

Not yet shown on hardware. The field check is in the driver PR: which of Pixii registers 40128 and 40130 reads 90 on the #175 site, and that the plan, the battery-full state and the measured power then agree.

Checklist

  • The change follows VISION.md and one selected scope.
  • I checked overlapping PRs and coordinated shared files/contracts.
  • 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, or the change is exempt.
  • Every commit has a DCO sign-off.

🤖 Generated with Claude Code

A Pixii can stop charging at 90 % while the planner's ceiling is 95 %. The
plan booked "90 → 95 %, 1.0 kWh" and dispatch ordered charge the battery
never took (srcfl/device-drivers#175).

Drivers now report the device's own ceiling as max_soc_fract on the battery
reading, the `@srcful/data-models` name. Core takes the lower of it and the
configured ceiling:

- dispatch marks the battery full there, stops charge orders and resumes
  one point below, and the fuse bounds close the charge side;
- the planner caps each battery's MaxEnergyWh at it and sets the fleet's
  SoCMax to the capacity-weighted result, so the Go DP and Energyplan plan
  to the same limit. A device ceiling at or below the SoC floor is ignored.

A missing, zero or out-of-range value changes nothing.

Refs srcfl/device-drivers#175

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 Nov 25, 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-11-25T07:41:53.653227Z 280420c 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.

Review findings on the device ceiling:

- Dispatch used any reported ceiling, so max_soc_fract 0.05 with a floor of
  0.10 marked a half-empty battery full. Dispatch now ignores a ceiling at
  or below the battery's SoC floor, as the planner does, and logs it once.
- Telemetry ignores a ceiling below 50 % and logs it once: real ceilings sit
  around 80-100 %, and a misread register must not stop charging.
- One reading without the ceiling, from a failed limit read, released a full
  battery for a poll. The store now carries the ceiling on the reading, like
  SoC, for up to ten minutes (the Pixii driver retries a missed register
  after five) and drops it with a stale reading or a removed driver.
- A test pins that the planner changes only MaxEnergyWh on a storage, so
  per-battery limits added beside it pass through.

Refs srcfl/device-drivers#175

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
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