Skip to content

feat(control): read the inverter stream and say when its grid headroom is gone - #2070

Merged
frahlg merged 3 commits into
masterfrom
inverter-stream
Nov 22, 2026
Merged

frahlg merged 3 commits into
masterfrom
inverter-stream

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

The driver contract (srcfl/device-drivers docs/WRITING-A-DRIVER.md, "What a battery can do now", and spec/host-api-profile.json, streams_vs_ders) defines an inverter emit stream. A battery or hybrid driver sends its AC stage on host.emit("inverter", {...}): W, VA, Hz, per-phase values, rated_W, and available_import_W / available_export_W, how much more the inverter will take from or give to the grid now. Blixt L1 already reads these.

Core's host refused the stream. emitTelemetry passed the type to telemetry.ParseDerType, which knows only the six DER types, so host.emit("inverter", …) returned an error string and the reading was lost. The Solis C&I drivers (50-125k-svk, -slew, -ac-slew) and konja-261-svk already emit it on each poll whose AC read answers.

#2068 judges a battery against what it can do now, but only from the battery's own available_*_W and learned plateaus. An inverter that reports no grid headroom left is the same kind of evidence, from the device itself.

What

The stream reaches Core, apart from site power.

  • host.go: an inverter emit is routed before the DER envelope to a new emitInverter. It follows the poll rules of a DER emit (for a driver whose polls must read fresh, a poll whose reads failed drops it with the rest), but it is not a sign of life: it never calls RecordDriverSuccess, so it cannot keep a driver's held battery reading live in dispatch.
  • The host numbers every driver poll (one counter for the process, so a restarted host never reuses a number), and stamps each reading of that poll with it, including readings held until the poll ends. DerReading.Poll and InverterReading.Poll carry it; Store.Update is unchanged and stamps 0.
  • telemetry/inverter.go: InverterReading holds the latest reading per driver in its own map on the store, not in readings. So ReadingsByType, ReadingsByDriver, the SumOnline* helpers, the live and history measurement, dispatch, the fuse guard and the energy ledgers never see it, and it writes no samples to history. Remove clears it.
    • ParseInverterReading reads each field on its own, by Blixt's exact names (W, or the catalog's w; available_import_W; available_export_W). A field that is not a finite number, a null, or a headroom outside 0 to 100 kW is left out and the rest kept. In Lua, a NaN or infinite value in an inverter emit is dropped before encoding, so one failed register does not lose the emit.
    • Inverter(driver): the last known reading, for the driver detail view, which shows its age and stale.
    • LiveInverter(driver): only while the driver is live and its device reports no fault.
    • LiveBatteryInverter(driver): LiveInverter for a reading with the same poll number as the driver's latest battery reading. When one of the two reads fails, the other is left from an earlier poll however close in time, and the pair is refused. Readings from outside a poll never pair.
  • /api/status drivers map: inverter_w, inverter_available_import_w, inverter_available_export_w and inverter_updated_at_ms, through LiveInverter, so a stale or faulted driver's cached values never show as live. /api/drivers/{name}: an inverter object with the same values, the emit as sent, updated_at_ms and stale.
  • lua.go: the host API comment lists the stream.

The verdict uses the headroom. In explainBatteryShortfall, after the battery's own reported limit and before learned limits: a power_below_target battery (it gives part of its order, in the right direction) whose same-poll inverter reports available_import_W (charging) or available_export_W (discharging) at no more than 100 W (Core's smallest control tolerance) becomes limited / battery_limit / info, with limit_source: "device", limit_kind: "inverter_import" or "inverter_export", and limit_w = the headroom left.

  • no_power_response keeps its warning. A dead battery on a site that may not export also sees no export headroom. Only the battery's own report of 0 available (feat(control): judge a battery against what it can do now #2068's path) explains a zero response.
  • Only power_below_target is relabelled, so wrong direction, power above the order, power while idle, setpoint_changed, telemetry_stale, readings_lost and device_fault keep their own reasons.
  • The headroom must be in the order's direction: no export headroom says nothing about a charging shortfall.
  • device_standby and the battery's own battery_reported limit come first.

Words (web/control-feedback.js, next to #2068's): title "Limited by the inverter"; text "The inverter reports that it can take no more from the grid now. FTW asked for 5.0 kW charge." or "…send only 60 W more to the grid now…". The reason stays battery_limit, so setControlStatus, the journal and notices already treat it as limited.

Two fixes to #2068's words, found by the web app agent and fixed there in srcfl/ftw-webapp#144; the box now uses the same words:

  • a battery_limit row with no limit_w and no target read "below the the new target FTW asked for". It now reads "The battery reports a limit below what FTW asked for."
  • controlNumbers labelled a battery's limit_a (its learned current limit) "Charger lets the car take". For a battery row it now reads "Battery current limit"; chargers keep their labels.

These have their own patch changeset.

After review (third commit): pairing by poll number instead of a 2 s window; no_power_response no longer explained by headroom; /api/status gated on a live driver, with the reading's time; one bad field no longer fails the emit.

Tests and results

  • telemetry/inverter_test.go: parsing, with each bad field left out and the rest kept, and exact key names only; storing a 9 kW inverter reading leaves the live and history measurement, every per-type read, the site sum and the history samples unchanged; pairing at 1 s intervals refuses an inverter reading from the poll before and a battery reading from the poll before, pairs an every-other-poll driver on its inverter polls only, and never pairs readings from outside a poll; LiveInverter and LiveBatteryInverter refuse a faulted or offline driver; Remove clears it.
  • drivers/inverter_stream_test.go: a Lua driver's host.emit("inverter", …) returns no error and is stored; it creates no DER reading and no history sample; it is no sign of life; a failed held poll drops it and a good one pairs; a back-to-back every-other-poll Lua driver pairs only on its inverter polls; a NaN or infinite value is dropped and the rest kept.
  • control/inverter_stream_test.go: two identical sites, one with a −20 kW, zero-headroom inverter stream on both batteries, get identical dispatch targets over five ticks in self-consumption, charge, idle and peak-shaving, with fuse clamping in play.
  • api/api_control_inverter_test.go: a table of verdicts (no headroom explains a partial delivery both ways; a zero response stays no_power_response with no headroom either way, and reads battery_reported only when the battery reports 0 available; headroom above 100 W, the wrong direction's headroom, missing or out-of-range headroom, and no stream do not explain; standby comes first); a 1 Hz stream whose inverter read stops is not following from the very next poll; the never-explain table with zero headroom both ways (setpoint changed, above target, while idle, wrong direction, no response both ways, device fault, readings lost, driver says offline, driver offline); /api/status totals are unchanged, the new fields show with the reading's time, and vanish for an offline or faulted driver.
  • Mutation checks: relabelling no_power_response again fails four cases; going back to the 2 s window fails the 1 Hz API test, the telemetry pairing test and the Lua every-other-poll test; reading the ungated reading in /api/status fails the status test; turning off the verdict rule fails the "limited" cases.
  • web/control-feedback-battery-limits.test.mjs: the new words, the inverter title, no codes, undefined or doubled "the", a check that every inverter_* kind in api_control_capability.go has words, and two tests for the feat(control): judge a battery against what it can do now #2068 fixes that fail on the old code.
  • make verify (GOFLAGS=-p=4, bundled drivers synced with scripts/sync-bundled-drivers.sh): clean on 847b276. An earlier run, before the review fixes, failed once in go/cmd/ftw (TestChargeNowSurvivesOCPPSocketBlip: bind: address already in use, a port taken on the shared laptop); it passed 10 times alone.
  • npm test: 966 pass, 0 fail.
  • .github/scripts/check_telemetry_reads.py: 133 reads outside go/internal/telemetry, none added.

Not verified

  • Not run on hardware. No site in reach runs a driver that sends the stream; the Solis C&I drivers are not in the bundled set.
  • The owner must review the new words in a browser. I have not seen them rendered.
  • The apps copy web/control-feedback.js (its header says byte for byte). ftw-webapp and ftw-app owe the inverter words; ftw-webapp#144 already has the two fixes.
  • A driver that sends the stream only every Nth poll is explained only on those polls, so its verdict alternates. The Solis C&I and Konja drivers send it on each poll whose AC read answers.
  • Choice for the owner: the 100 W "no headroom" tolerance.

Changeset: minor, for the owner to approve.

Refs #2068

🤖 Generated with Claude Code

frahlg and others added 2 commits November 22, 2026 13:21
The driver contract defines an `inverter` emit stream: a battery or
hybrid driver's AC stage, with available_import_W / available_export_W,
how much more the inverter takes from or gives to the grid now. Core's
host passed the type to ParseDerType and refused it, so the Solis C&I
drivers lost it on every poll.

Keep the latest inverter reading per driver in its own map on the
telemetry store, apart from the DER readings, so no site sum, dispatch,
fuse guard, ledger or history reads it, and write no history samples
from it. The emit follows the poll rules of a DER emit but is no sign of
life. Show it in /api/status and /api/drivers/{name}.

LiveBatteryInverter returns the reading only while the driver is live
and unfaulted and the reading came within 2 s of its battery reading.
A battery shortfall in the right direction, or a zero response, while
that reading reports at most 100 W of headroom in the order's direction
reads limited / battery_limit with limit_kind inverter_import or
inverter_export, after the battery's own report and before learned
limits. The box page says "Limited by the inverter".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
A battery_limit row without limit_w or a target read "below the the
new target". It now reads "below what FTW asked for". The Numbers list
labelled a battery's learned current limit "Charger lets the car take";
a battery row now says "Battery current limit". Same words as
srcfl/ftw-webapp#144.

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 22, 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-22T12:24:02.678581Z 997a3e0 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: 997a3e01a6

ℹ️ 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/internal/telemetry/inverter.go Outdated
Comment on lines +123 to +125
if apart := r.UpdatedAt.Sub(bat.UpdatedAt); apart > InverterPollSlack || apart < -InverterPollSlack {
return InverterReading{}, false
}

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 Match inverter and battery readings by poll identity

For drivers polling every second—a supported interval also used by the new inverter-stream test—the two-second window accepts inverter data from previous polls. If a poll emits zero inverter headroom and the next poll updates the battery but omits the inverter after a failed read, LiveBatteryInverter still returns the previous headroom. explainBatteryShortfall then suppresses the non-following warning as an informational inverter limit despite lacking current inverter evidence. Track a shared poll identity or explicitly invalidate the decision-facing inverter reading when its poll does not emit one; timestamp proximity cannot establish the promised same-poll relationship. This also conflicts with the requirement to expose freshness and failures in the normal experience.

AGENTS.md reference: AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

Review of the inverter stream found four gaps.

The pairing was a 2 s window, not a poll. On a 1 Hz driver a failed
inverter read left a reading a second old that still paired with the
next battery reading, and the reverse. The host now numbers every driver
poll, process-wide, and stamps each reading of the poll with it, held
readings included. LiveBatteryInverter needs the same number on both.

Headroom explained a zero response. A dead battery ordered to discharge
on a site that may not export also sees no export headroom, and read
limited/info. The inverter now explains only power_below_target; a zero
response keeps its warning unless the battery itself reports 0
available.

/api/status showed a stale driver's cached inverter values as live. It
now reads them through LiveInverter, live and unfaulted only, and adds
inverter_updated_at_ms.

One bad field failed the whole emit. Each field is now read on its own
by Blixt's exact names; a non-number, null or out-of-range value is left
out and the rest kept, and Lua drops NaN and Inf before encoding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg merged commit 0bd640c into master Nov 22, 2026
21 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