Skip to content

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

Open
segran2 wants to merge 5 commits into
srcfl:masterfrom
segran2:fix/pixii-calibration-status
Open

segran2 wants to merge 5 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>
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