Skip to content

feat(foxess_h3_smart, konja-261-svk): report grid state on the inverter stream - #285

Merged
frahlg merged 1 commit into
mainfrom
feat/inverter-grid-state
Nov 29, 2026
Merged

frahlg merged 1 commit into
mainfrom
feat/inverter-grid-state

Conversation

@frahlg

@frahlg frahlg commented Nov 29, 2026

Copy link
Copy Markdown
Member

Step (5) of off-grid support, srcfl/ftw#2125. FoxESS and Konja now report whether the inverter is on grid or islanded. This is observe-only: no register read, write or control path changes, and FTW Core does not act on the field yet. The point is to get readings from a real grid cut on a 1K5 before any off-grid behaviour is built on them.

The field

grid_state on host.emit("inverter", …), with the value "on_grid" or "off_grid":

  • It is reported only from a vendor status register read in the same poll. A failed read or a state that says nothing about the grid leaves the field out, and a cached value is never sent.
  • It is never derived from grid V, Hz or power. An inverter in backup mode forms its own grid with normal V/Hz.
  • Debounce and every off-grid behaviour belong to Core.
  • It goes on the inverter stream because that stream is the inverter's AC stage, which is what islands. Like device_state, it is FTW's own key. It is documented in docs/WRITING-A-DRIVER.md under "Grid state".

foxess_h3_smart 0.11.0

  • Decode: bit 0 of Status 3, with 1 meaning off-grid. FoxESS Modbus definition V1.05.04.00 places Status 3 at 39065, but it is a 32-bit field with the high word first, so its bit 0 is in 39066 bit 0. This is how the foxess_modbus maintainer reads the definition in fix: read the off-grid status bit from 39066 on H3 Smart nathanmarlor/foxess_modbus#1314.

  • Evidence: #1314 measured this on a P3-5.0-SH, which is in the same register family:

    Register Islanded On grid
    39066 0x0001 0x0000
    39065 0x0000 0x0000
    39063 0x0004 0x0004

    These held over two real outages (93 s and 20.7 min, where grid V and Hz read 0) and 27 short relay trips of 9–20 s (where V and Hz stayed normal). #1314 applies the read to the H3-Smart family and to the 1K5 profile.

  • No extra Modbus traffic: the status block (39063, count 79) is already read every poll.

  • First inverter stream: the driver emits an inverter stream for the first time, carrying only this field. Grid V and Hz stay on the meter emit.

  • Not yet verified on a 1K5-HI. Both words therefore also go to history as foxess_status3_hi (39065) and foxess_status3_lo (39066). The metrics are split because one 32-bit value would not fit Blixt's 32-bit Lua integers. verification_notes says grid state is unverified.

  • Worth knowing for Core: in the same measurement, 39067 read 0x0980 while islanded. This driver's fault latch reads 39067..39069 as fault codes, so on that evidence an outage today raises a device fault (codes 2432/0/0). This PR does not change that. It is recorded here for the off-grid behaviour step.

konja-261-svk 0.5.0

  • PCS 8063 (protocol V1.16) maps as follows: 4, grid-connected operation, is on_grid, and 3 is off_grid.
  • Shutdown, power-on, standby, fault and debug leave the field out.
  • The driver already read 8063 and only logged it.

What to record in the grid cut on the 1K5

Please record:

  • inverter model and firmware;
  • foxess_status3_hi, foxess_status3_lo, foxess_inverter_state, and the device-fault message (fault codes), before, during and after the cut;
  • grid V and Hz from the meter emit;
  • the time from the cut until 39066 changes, and from the grid returning until it clears;
  • any single-poll flicker.

Tests

  • drivers/tests/test_foxess_h3_smart.py covers three cases:
    • on grid, with both words 0;
    • off-grid from 39066 bit 0, while the high word and other bits carry no grid state;
    • a failed status read, which gives no inverter emit and no metrics.
  • drivers/tests/lua_harness/test_grid_state_konja.lua, run by drivers/tests/test_grid_state.py, covers 4 → on_grid, 3 → off_grid, other states leaving the field out, and no replay after a failed PCS read. It fails against the driver on main.
  • make check passes: 5569 passed, 927 skipped.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 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-29T11:20:55.154581Z c842e04 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.

…er stream

A hybrid inverter with a backup switch keeps the house on its battery when
the grid goes, and FTW had no way to know (srcfl/ftw#2125). Both drivers
now report grid_state, "on_grid" or "off_grid", on the inverter stream,
only from a vendor status read in the same poll. Observe-only: no read,
write or control path changes, and FTW Core does not act on it yet.

foxess_h3_smart 0.11.0 decodes bit 0 of Status 3, a 32-bit field at
39065..39066 with the high word first, so the bit is in 39066. That is
what nathanmarlor/foxess_modbus#1314 measured through two real outages
and 27 relay trips. It is not yet confirmed on 1K5 hardware, so both words
also go to history.

konja-261-svk 0.5.0 maps PCS 8063: 4 is on_grid, 3 is off_grid, any other
state leaves the field out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the feat/inverter-grid-state branch from c842e04 to f1c2b24 Compare November 29, 2026 16:45
@frahlg
frahlg merged commit eeee2c4 into main Nov 29, 2026
5 checks passed
@frahlg
frahlg deleted the feat/inverter-grid-state branch November 29, 2026 16:47
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