Skip to content

fix(sungrow): stop polling SH hybrid registers on SG string inverters - #17

Merged
frahlg merged 2 commits into
mainfrom
17-sungrow-sg-string-skips-hybrid-registers
Jul 25, 2026
Merged

frahlg merged 2 commits into
mainfrom
17-sungrow-sg-string-skips-hybrid-registers

Conversation

@frahlg

@frahlg frahlg commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

SG string inverters answer the 5xxx PV registers but none of the SH hybrid
block. The driver read 13019 and its neighbours on every model. Since the
host started counting a poll as failed when any single read fails, an SG12RT
failed 12 of its 19 Modbus reads and the whole device went offline instead of
reporting the PV it does have.

The catalog already said what the driver ignored: SG-RT is "PV + meter only
(no battery)".

Each model-specific register is now read through optional_read, which probes
an address once and then stops reading it. The battery and meter streams are
emitted only when the registers behind them responded, so a string inverter no
longer reports a battery DER it does not have. Battery commands are refused
once a poll has proved the model has no battery block, so we never write EMS
registers an SG does not implement.

Same pattern as the Pixii fix in #16.

The probe is lazy rather than in driver_init, unlike Pixii. This driver
notes that Modbus is connected only by the first poll, so probing in init
would risk marking registers absent for the whole session because of a startup
gap. The cost is one failed poll after a restart on an affected model.

Reported in Discord by an SG12RT owner: driver_poll: 12 of 19 modbus reads failed on bundled sungrow-shx 1.1.0.

Driver evidence

  • Driver id: sungrow
  • Device make/model: Sungrow SG12RT (SG-RT three-phase string), against SH-RT hybrids for the unchanged path
  • Firmware tested: not recorded by the reporter
  • Protocol/register source: Sungrow SH/SG Modbus map, same addresses the driver already used
  • Hardware test performed: none. Reproduced in the Lua harness by failing the hybrid addresses an SG-RT does not answer
  • Known limits: the reporter runs the bundled sungrow-shx 1.1.0, so this fix reaches that site only after it moves to the managed driver

Safety

  • The driver starts read-only, or this is a separately reviewed control change.
  • Vendor signs are converted at the driver boundary.
  • Cached telemetry becomes stale instead of being re-emitted as fresh.
  • No credentials, serial numbers, private addresses or site data are included.

The control change only narrows what the driver will write: a battery command
is refused on a model with no battery block. No new write path is added.

Package or promotion evidence

  • Public source SHA: filled in on merge
  • Package ID and new version: com.sourceful.driver.sungrow unchanged at 1.3.2; the shipped observe-only target is byte-locked to the FTW baseline and is not touched here
  • Target matrix: ftw-core. The staged v2 control adapter moves 1.3.1 to 1.3.3 and stays disabled
  • Material and candidate artifact SHA-256: make package-driver ID=sungrow TARGET=ftw-core builds the unchanged 1.3.2 observe candidate
  • HIL evidence or required: required
  • Control enabled: false
  • Control changes include default-mode, lease-expiry and HIL evidence.

Checks

  • Commits include Signed-off-by.
  • make test-driver ID=sungrow
  • make package-driver ID=sungrow TARGET=ftw-core
  • make check — 2606 passed, 0 failed

New harness tests: sungrow-sg-string and sungrow-ftw-v2-sg-string. Both
poll three times with the hybrid block failing, and assert PV and meter keep
flowing, no battery stream is emitted, and no absent register is read twice.

The pre-existing goodwe harness failure on main is unrelated and unchanged.

🤖 Generated with Claude Code

SG string inverters answer the 5xxx PV registers but none of the SH
hybrid block. The driver read 13019 and its neighbours on every model,
so on an SG12RT 12 of 19 Modbus reads failed. Since the host started
counting a poll as failed when any single read fails, the whole device
went offline instead of reporting the PV it does have.

Probe each model-specific register once, then skip the addresses this
inverter does not answer, and emit the battery and meter streams only
when the registers behind them responded. Battery commands are refused
once a poll has proved the model has no battery block.

Same pattern as the Pixii fix in #16.

Signed-off-by: Fredrik Ahlgren <[email protected]>

@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: d6c5faafaf

ℹ️ 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 drivers/lua/sungrow.lua Outdated
if ok and registers ~= nil and registers[1] ~= nil then
return registers
end
absent_registers[address] = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retry transient failures before declaring registers absent

When a supported register has a one-off Modbus timeout, this unconditional cache marks it unsupported for the lifetime of the VM. A transient failure at 13000 therefore makes all subsequent battery discharge samples use status = 0 and report discharge as positive, while a transient failure at 13019 or the 56xx registers permanently removes battery or meter telemetry and rejects battery commands until restart; only definitive unsupported-address responses should be cached, while communication failures must remain retryable. The mirrored FTW target has the same logic.

AGENTS.md reference: AGENTS.md:L22-L24

Useful? React with 👍 / 👎.

…ilures

The first version of this fix learned the register map by failing reads.
That had two faults. It still spent one failed poll per absent register
before settling, and any single timeout wrote a register off for the rest
of the session, so a glitching bus could silence the battery on a healthy
SH hybrid.

Read the device type code at 4999 instead. 0x0D and 0x0E are the SH hybrid
families; any other clean code is a string inverter, and the hybrid block
is then never read at all. The same register already backs
driver_fingerprint in the FTW baseline, so this is the identity the fleet
already trusts.

Probing remains only as a fallback for an unreadable type code, and now
takes three consecutive failures before it writes a register off.

Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg merged commit b1d5575 into main Jul 25, 2026
5 checks passed
@frahlg
frahlg deleted the 17-sungrow-sg-string-skips-hybrid-registers branch July 25, 2026 07:10
frahlg added a commit that referenced this pull request Jul 25, 2026
#17 changed drivers/lua/sungrow.lua, so the manifest hash this branch
wrote no longer described the file. This is the guard working: make check
caught it rather than letting main carry a manifest that lied.

Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Jul 25, 2026
…hes (#18)

* feat: make the repository state the truth about the drivers it publishes

Manifest sha256 and size_bytes were maintained by hand and had drifted:
60 of 62 manifests described bytes their driver no longer had, and 22
claimed nothing at all. validate_manifest.py only checked that the size
was a non-negative number, so nothing caught it. index.yaml was the only
file telling the truth, because it derives both from the source.

Derive them everywhere instead. tools/sync_manifests.py rewrites both
fields from the Lua file, make check runs it and fails on any diff.

Two gaps followed from the same place. There was no quick way to raise a
version without forgetting one of the two files that state it, and no way
to recover an older driver: index.yaml names only the current version,
while spec/driver-package-v1.md already promises rollback to a previously
verified package.

- make bump-driver ID=<id> LEVEL=patch moves the manifest and the DRIVER
  table together, then refreshes the generated catalog.
- driver-history.json records every published version with its source
  hash, size, first commit and date. The record is append-only: a
  published version describes bytes already running on hardware, so
  make check fails if an entry is rewritten or dropped.

Signed-off-by: Fredrik Ahlgren <[email protected]>

* chore: record sungrow 1.2.1 and resync its manifest after #17

#17 changed drivers/lua/sungrow.lua, so the manifest hash this branch
wrote no longer described the file. This is the guard working: make check
caught it rather than letting main carry a manifest that lied.

Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
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