Skip to content

fix(battery): explain calibration and suspend manual control - #2017

Merged
frahlg merged 7 commits into
srcfl:masterfrom
segran2:fix/pixii-calibration-status
Nov 26, 2026
Merged

frahlg merged 7 commits into
srcfl:masterfrom
segran2:fix/pixii-calibration-status

Conversation

@segran2

@segran2 segran2 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

When Pixii calibrates its batteries, it can continue to charge while the FTW setpoint remains at 0 W. This is normal device-managed operation. Show Calibrating under Are we in control?, keep measurements live, and suspend power dispatch and planning for the calibrating battery.

Disable Install hold for that battery and explain why. Reject the same scoped request at the API. An all-batteries override can still apply to other eligible batteries.

The Pixii driver change is in srcfl/device-drivers#228. The bundled driver pin can follow once that change lands.

Validation

  • On a Raspberry Pi with the local Core and driver patches, Pixii reported Modbus running-service code 116. FTW reported an informational calibration state with fresh telemetry and issued no further Pixii power commands after detection.
  • The scoped-hold API regression test verifies that a calibrating battery rejects a hold and is surfaced in the manual-hold status. The control-feedback test verifies that clearing calibration makes the battery eligible for control again.
  • The Pi journal shows zero Pixii power setpoints from 01:24:42 until the calibration exit at 03:00:11 CET on 15 November 2026. The same FTW process resumed dispatch automatically and issued a 463 W charge setpoint via Modbus at 03:00:12, followed by an idle setpoint at 03:00:17. A later live API check showed calibration cleared, fresh battery telemetry and no active manual hold. This verifies that Core resumed writing setpoints. The brief 463 W request was not independently verified as delivered power.
  • All 927 web tests and make verify passed locally. GitHub's web, Go, race and full-stack jobs passed on the updated PR head.

Driver restart during calibration

Commit 1177097 keeps the calibration guard across driver replacement until the replacement driver reports that calibration has ended.

  • Registry regression: Before the fix, the replacement Lua instance received a battery command before reporting calibration status in three of three runs. After the fix, the regression passed three runs with the Go race detector, covering restart by name and configuration reload. Fresh telemetry alone leaves the guard in place.
  • Simulated Modbus using the box's Pixii 2.1.8 Lua override: The installed Core build blocked a 1,000 W charge order at service code 116, during restart with both status registers returning the unavailable sentinel, and after the replacement driver reported 116 again. Battery telemetry resumed while status was unknown. The only setpoint writes during restart were three 0 W writes to registers 39905–39906 from shutdown default, cleanup and startup default. When the simulator reported service code 102, the guard cleared and the next 1,000 W charge order reached Modbus (native setpoint −1,000 W). This test passed with the Go race detector.
  • Hardware smoke test: On 22 November, the local v0.167.0-beta.1 build containing the fix restarted only the Pixii driver through the driver restart API. Live measurements returned in about five seconds, Core resumed sending its ordinary setpoint, and all four drivers reported normal health. Pixii reported service code 102 during the test.
  • Hardware coverage still open: Restart during active calibration and the device's response to the 0 W restart writes have yet to be verified on physical Pixii hardware.

@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.

Adds a device-managed calibration state: new set_calibrating host call, DriverHealth.Calibrating, dispatch/planning suspended for that battery, scoped manual hold rejected with 409 (and the UI disables Install hold). Tests cover the API rejection and the feedback state. Security screen: nothing found (no new deps, hosts, secrets or authz changes).

  • IsOnline() now returns false while calibrating. Fine for dispatch, but every other consumer of IsOnline (health endpoint, driver inventory, support report, any offline alerting) will now read a calibrating battery as offline. The new test asserts this on purpose; worth a quick grep that nothing pages on it.
  • The flag has no timeout. If a driver sets set_calibrating(true) and then stops calling (crash, bad poll), control stays suspended until stale-status logic marks it offline anyway. Probably acceptable, but say so if intended.
  • battery_calibrating is added to controlVerificationLost's exclusion list, good: no false 'lost control' during calibration.

Safe to merge from my read, with the first point as a check rather than a blocker.

@segran2

segran2 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

A battery under calibration is unavailable for control. The device manages its own charge and discharge during calibration, and FTW setpoints or manual holds could interrupt that process. The battery can still report telemetry, but planning and dispatch must exclude it from controllable capacity until the device reports that calibration is complete.

@frahlg

frahlg commented Nov 21, 2026

Copy link
Copy Markdown
Member

Thanks for the note on why a calibrating battery is left alone. Two review points still need an answer. First, IsOnline() now returns false during calibration, so health, the driver list and the support report show the battery as offline. Please list what reads IsOnline() and say if that is what you want. Second, the flag has no timeout. If a driver sets it and stops, control stays off until the status goes stale. Please say if that is intended, and add a test or a comment.

Driver inventory and status, support reports, app-link snapshots and
Home Assistant availability read IsOnline. Non-battery health gates
also use it for site-meter, EV, V2X, PV and vehicle telemetry.

Use CanControl for battery dispatch, planner eligibility, scoped holds,
self-tune and EV battery boost. Reject queued battery commands that
reach the driver after calibration started.

Calibration has no independent expiry. The telemetry watchdog still
marks a silent battery offline. Fresh telemetry restores online status
and explicit completion from the driver restores control eligibility.

@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.

Adds a device-managed "calibrating" state for batteries (Pixii). Calibrating batteries keep live telemetry but are dropped from dispatch, planning and scoped manual holds, and the UI shows "Calibrating" instead of a fault. A new host.set_calibrating Lua call and CanControl() (online and not calibrating) carry this through.

Findings

  • Medium, go/internal/telemetry/store.go (SetDriverCalibrating): calibration only ends when the driver reports it. If a Lua driver restarts or crashes mid-calibration and doesn't call set_calibrating(false) on init, the battery stays uncontrolled indefinitely (your test confirms recovery of telemetry deliberately doesn't re-enable control). Does the registry reset Calibrating on driver stop/reload? I didn't see it in the diff. Worth a reset on driver (re)start or a test for it.
  • Low, api_battery_manual.go (handleBatteryManualHoldGet): CalibratingDrivers is built by ranging over a map, so the order varies between calls. Sort it. Also check AllHealth() entries are safe to read without the store lock, since IsOnline() reads Status.
  • Low, scope: the energy-history-integration.test.mjs change is a separate CI-flake fix (fixed clock). Fine, but it would read better as its own commit.
  • Security screen: no secrets, no new deps or hosts. set_calibrating is scoped to the calling driver's own name, so a driver can only suspend control of itself.

The IsOnline() to CanControl() swaps look complete across control, mpc and loadpoint paths, and the new tests cover dispatch, API and feedback. Safe to merge from my read once the restart-reset question is answered.

Signed-off-by: Segran <goran@andersson-stehag.se>
Signed-off-by: Segran <goran@andersson-stehag.se>

@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.

Adds a Calibrating health state: telemetry stays live, CanControl() replaces IsOnline() at the dispatch, planner and manual-hold decision points, the UI shows it as informational, and the scoped hold API returns 409 for a calibrating battery. It depends on srcfl/device-drivers#228 for the driver side.

  • Design reads right. Keeping calibration separate from DeviceFault avoids the false "blocked" signal, and keeping IsOnline() for diagnostics while CanControl() gates control is a clean split. The tests cover the watchdog and recovery path and the restart carry-over.
  • Worth a thought (low): calibration can only be cleared by the driver reporting it. The state is carried across a Reload/Restart (RemoveForReplacement), so if the replacement driver never calls set_calibrating (for example a catalog downgrade to pixii 2.1.9 mid-calibration), the battery stays control-suspended until the driver is removed. It fails safe and is visible in the UI, but a note in the docs or a max-age on the carried state would make it less surprising.
  • Same shape for a device that reports 116 indefinitely: no timeout, which I think is the right default, but it means a stuck unit needs a human to notice.
  • Not verified from the diff: I read the changed IsOnline() call sites, and I haven't grepped the rest of the tree for any remaining battery-control path that still uses IsOnline().
  • Security screen: no secrets, no new dependencies, no new network destinations. The new endpoint field is read-only status; the 409 is a tightening.

Safe to merge from my read, once #228 lands and the 2.1.10 hardware run passes.

Signed-off-by: Segran <goran@andersson-stehag.se>
@frahlg
frahlg merged commit dbc311e into srcfl:master Nov 26, 2026
22 checks passed
frahlg added a commit that referenced this pull request Nov 27, 2026
Moves the driver pin from srcfl/device-drivers b07a409b to 8aeecee3. Only
tibber and pixii change:

- tibber 1.1.3 (srcfl/device-drivers#282) declares
  ws_hosts = { "websocket-api.tibber.com" }, so a box set up from the UI
  opens the live stream (#1822).
- pixii 2.1.10 (srcfl/device-drivers#228) reports calibration with
  host.set_calibrating (#2017).
- pixii 2.2.0 (srcfl/device-drivers#281) reports max_soc_fract
  (#2083).

Two Core tests ran the bundled Pixii and expected calibration as a device
fault, as pixii 2.1.9 reported it. They now expect Calibrating set, control
off, no fault and the driver still online, which is what 2.1.10 reports on
a Core with host.set_calibrating.

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

3 participants