Skip to content

feat(sungrow): report what the battery can do now (1.7.0) - #251

Merged
frahlg merged 2 commits into
mainfrom
sungrow-battery-limits
Nov 22, 2026
Merged

frahlg merged 2 commits into
mainfrom
sungrow-battery-limits

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

FTW Core marks a battery "not following" when it gives less than ordered. On the owner's SH-RT with an SBR096 pack, 30 days show device limits, not lost control:

  • Forced discharge of 4.5 kW or more gave 4,049-4,383 W at a flat 21.6-23.1 A DC; forced charge of 4.5 kW or more met the order 10 % of minutes while total grid import sat flat near 4,316 W.
  • 14 times the running state went to 8 (standby), then 32 (startup), for 2-9 minutes while a forced order stood, and the battery gave 0 W.

Core will learn these limits. First the driver reports what the device says, using the contract in #250 (docs/WRITING-A-DRIVER.md, "What a battery can do now").

What changes

On the battery blob:

Field From Notes
temperature_C documented 13025, host 13024, input S16 × 0.1 °C pack temperature from the BMS, not the heatsink
available_charge_W documented 5635, host 5634, input U16, 1 A times the battery voltage read in the same poll
available_discharge_W documented 5636, host 5635, input U16, 1 A same
device_state documented 13000, host 12999 (already read) "standby" for 0x0008, 0x1400, 0x0010, 0x1200; "starting" for 0x0020, 0x1600; left out otherwise

Metrics on full polls, each only when its value is present: battery_temp_c, battery_charge_limit_a, battery_discharge_limit_a, battery_available_charge_w, battery_available_discharge_w.

  • One read for 13024 and one for 5634-5635, both on the full poll every five seconds and only after the battery read answers. Both go through optional_read, so a model that refuses them stops being asked after three refusals. An SG string inverter never asks.
  • Fast polls carry the last values only while that poll's battery read succeeds, as the energy counters do. A failed read on a full poll clears its value until the next full poll reads it.
  • Watts are computed every poll from the carried amps and that poll's voltage. 0 A gives 0 W, which means the BMS allows nothing now.
  • Dropped: a temperature outside -40 to 100 °C (compared in the register's tenths, so both edges stay in), a current above 1000 A, a voltage of 0 or above 1000 V, a power above 100 kW. Sungrow answers 0x7FFF (signed) and 0xFFFF (unsigned) for a register it does not have; those land outside the same bounds.
  • No control path, EMS write or command changed.

Sources and confidence

Sources: Sungrow's "Communication Protocol of Residential Hybrid Inverter" V1.1.9 (2025-06-20), read from a third-party copy; mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant modbus_sungrow.yaml; bohdan-s/SunGather registers-sungrow.yaml. Read for addresses only; no code copied.

  • 13025 battery temperature: high. All three agree on address, S16 and 0.1 °C.
  • 5635 / 5636 BMS max charge / discharge current: address high, meaning unconfirmed. All three agree on address, U16 and 1 A, and name them "(BMS)". None says whether they move with temperature or charge level. mkaiser polls them every 600 s. This PR treats them as the BMS's limit now and says so in the driver comment. If a site shows them flat while the battery is held back, they are a rating and should leave available_*. The CHANGELOG and the SH-RT, SH-RS and SH-T notes in the manifest say this is unconfirmed on hardware.
  • 13000 running state: high, with one correction to the brief. Appendix 2 of V1.1.9 lists whole values, some with an older and a newer code (Standby 0x1400/0x0008, Initial standby 0x1200/0x0010, Starting 0x1600/0x0020, Running 0x0000/0x0040, compulsory mode 0x0800, external EMS 0x4000). It is not a bitfield: 0x0014 is microgrid operation and 0x2501 is restarting. SunGather and mkaiser also match whole values. The driver matches whole values. The owner's box confirms the low codes: in all 14 standby episodes the state went 0x0800 (forced mode) -> 0x0008 -> 0x0020 -> 0x0800, and 0x0010 showed in 3 of them. 0x1200, 0x1400 and 0x1600 rest on the appendix alone.
  • Not mapped, for Core to decide: Restarting 0x2501, Stop 0x8000/0x0001, Key stop 0x1300/0x0002. Faults keep their existing set_device_fault path.

The protocol PDF asks not to be put on public sites, and Sungrow does not host it at a URL the watcher can fetch, so upstream_docs is unchanged. The driver comment names the document and version.

Grid import limit: not found

No available_import_W. Neither V1.1.9 nor mkaiser nor SunGather has a register for import headroom, a purchase limit or a grid charge limit. What I found:

  • V1.1.9 section 3.2.2, note 2: battery power is limited by BDC rated power (5628), Max. Charging/Discharging Power (33047/33048), SoC and ambient temperature; discharge also by the feed-in limit (13074 / 31222). Nothing on import.
  • Sungrow's SH5.0-10RT datasheet: SH8.0RT max AC input from grid 18,600 W, max battery charge/discharge 30 A and 10,600 W. Neither explains 4.3 kW.
  • Import held flat on total meter power (stdev 41 W) while each phase moved, so whatever holds it reads the site meter. A Sungrow help page for an unnamed ESS has an "Energy purchase control method" with "Purchase energy with limited power", set from the breaker size. It fits the shape, but it has no Modbus register and I could not tie it to SH-RT. Worth checking in iSolarCloud with an installer account. This PR writes no setting.

What to check on hardware

Not verified on hardware. On the owner's box, during a short forced discharge: if battery_discharge_limit_a reads about 22 A, 5636 is a live BMS limit. If it stays at a rating (for example 30 A), it is not, and available_* should come out. Also check that device_state reads standby then starting in the next standby event.

Tests

  • New drivers/tests/test_sungrow_battery_limits.py, 39 cases: scale and sign (25.3 °C, -5.0 °C, 24 A × 208 V = 4992 W, 22 A = 4576 W, positive while discharging); 0 A gives 0 W; each field and metric absent when its read fails, for a refusal and a timeout; temperature edges (-40.0 and 100.0 kept, -40.1 and 100.1 dropped), out-of-range temperature, 0xFFFF amps, over 100 kW and 0 V or 0xFFFF V dropped; device_state for each standby and starting code, absent for running, forced, external EMS, 0x0014 and 0x0041, and when the running state fails; the field's full episode (0x0800, 0x0008, 0x0020, then 0x0800 or 0x0040 on successive full polls) with device_state leaving on the poll that reads running; carried on fast polls; watts follow the fresh voltage; a failed full read or failed battery read clears the carried values; a refused register is given up after three full polls; an SG string inverter never asks. 20 of them fail against 1.6.1.
  • test_sungrow_poll_cadence.py: the full poll now also reads 13024 and 5634; fast polls are unchanged.
  • make test-driver ID=sungrow: 153 passed, 4 skipped.
  • make check: 5052 passed, 929 skipped.
  • Invented-number probe: no new field; the 20 old ones are unchanged.

Stacked on #250

device_state is not an allowed battery field on main until #250 merges, so this branch sits on battery-limits-contract (6e4f526) and shows #250's two commits. I will rebase onto main once #250 merges.

FTW's bundled copy does not move with this PR. Bump the pin and run scripts/sync-bundled-drivers.sh.

Refs #250

🤖 Generated with Claude Code

@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-22T09:12:07.404196Z edf3710 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.

@frahlg
frahlg force-pushed the sungrow-battery-limits branch from edf3710 to f551a36 Compare November 22, 2026 09:16
frahlg and others added 2 commits November 22, 2026 10:17
Read the pack temperature (documented 13025), the BMS's max charge and
discharge current (5635/5636) and map the running state the driver
already reads (13000) to device_state. Emit temperature_C,
available_charge_W, available_discharge_W (amps times this poll's
battery voltage) and device_state on the battery blob, plus the
battery_* metrics from docs/WRITING-A-DRIVER.md.

The two new reads run on the full poll only. Fast polls carry the
last values only while the battery read succeeds; a failed read leaves
its field out. Out-of-range values and Sungrow's "not available"
values are dropped. Running-state values are matched whole, as
Appendix 2 of Sungrow's protocol V1.1.9 lists them.

No available_import_W: the protocol has no register for it. No control
path, write or command changed. Not checked on hardware.

Refs #250

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
…edges

Cite the owner's box beside NOT_RUNNING and in the test header: in all
14 standby episodes the state went 0x0800 -> 0x0008 -> 0x0020 -> 0x0800,
with 0x0010 in 3 of them. Test that device_state leaves when a later
full poll reads 0x0800 or 0x0040. Compare the battery temperature in
the register's tenths, so -40.0 and 100.0 stay in on any float width,
and test both edges. Say in the CHANGELOG and the manifest notes that
whether 5635/5636 follow the BMS live is unconfirmed on hardware.

Refs #250

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the sungrow-battery-limits branch from f551a36 to 4f7951f Compare November 22, 2026 09:18
@frahlg
frahlg merged commit c95f607 into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the sungrow-battery-limits branch November 22, 2026 09:22
frahlg added a commit that referenced this pull request Nov 22, 2026
Keep both CHANGELOG entries (this group and sungrow 1.7.0 from #251) and
regenerate index.yaml, devices.yaml and the support status.

Co-Authored-By: Claude Opus 5.5 <[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