Skip to content

feat(huawei, sma, fronius, kostal, sigenergy): report what the battery can do now - #259

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

frahlg merged 2 commits into
mainfrom
battery-limits-g1

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Core will judge a battery against what the device says it can do now (docs/WRITING-A-DRIVER.md, "What a battery can do now", #250). This PR fills that in for five drivers: huawei, sma, fronius, kostal and sigenergy. Each reports only what its vendor documents, and leaves out a value whose read failed, which is NaN, or which falls outside -40 to 100 °C or 0 to 100 kW. The same values go to history (battery_temp_c, battery_available_charge_w, battery_available_discharge_w, inverter_temp_c). No control path, write or command changed.

Per driver

huawei 2.2.0

Field Register Source Confidence
available_charge_W 37046-37047, U32, W, RO, "[Energy storage] Maximum charge power" Huawei "Solar Inverter Modbus Interface Definitions", issue 02 (2021-08-12) and issue 05 (2023-02-16), table 3-2, row 16 Medium
available_discharge_W 37048-37049, U32, W, RO, "Maximum discharge power" same, row 17 Medium
temp_c (kept) 37022, I16, 0.1 °C, "[Energy storage unit 1] battery temperature" same, row 12 High
inverter_temp_c (fixed) 32087, I16, 0.1 °C, "Internal temperature" same, inverter table High
battery fitted (gate) 37007-37010, U32, W, RO, "[Energy storage unit 1] Rated charge/discharge power" same, rows 6-7 High
  • Not shown to be live on hardware: Huawei defines 37046/37048 as "the smaller value of" the inverter's and the connected ESU's charge/discharge capability. It lists the rated charge/discharge power apart, at 37007/37009. It does not say whether the value follows the BMS as the pack warms, cools or fills, and no one has seen it move. The CHANGELOG, manifest notes and code comment say so.
  • Gate:
    • A SUN2000 with no LUNA2000 may still answer 37001/37004 with 0, so an answer alone proves nothing.
    • Temperature and limits are read only once ESU1 reports a rated charge or discharge power above 0 (37007/37009). Otherwise 0 W would read as "may not charge now", and 0 °C as a cold battery.
    • The finding is kept for the run; until then the rating is read each poll the battery answers.
  • Only ESU1 is read, as for power and SoC. A second unit (37700-37755) is not.
  • Not read: the per-pack max/min temperatures (38452-38463) are documented. Huawei does not say what an empty pack slot answers, and a 0 there would pass for a cell reading.
  • Huawei publishes this document at no public URL of its own; the copies are forum uploads. The driver comment names it instead of upstream_docs.

kostal 2.2.0

Field Register Source Confidence
temperature_C 0xD6 (214), Float, °C, RO, "Battery temperature" KOSTAL "PIKO IQ/PLENTICORE Interface description MODBUS (TCP) & SunSpec with control information", rev 2.10 (12.11.2026), section 3.2 High
available_charge_W 0x434 (1076), Float, W, RO, "Maximum charge power limit (read-out from battery)" same, section 3.4 Medium-high
available_discharge_W 0x436 (1078), Float, W, RO, "Maximum discharge power limit (read-out from battery)" same, section 3.4 Medium-high
inverter_temp_c (fixed) SunSpec 40103 with SF 40106, as before unchanged address Unchanged
  • Floats follow the "MODBUS Byte Order" register 0x05 (0 = CDAB, the default; 1 = ABCD), read once per run.
  • Unverified on hardware: that register 5 gives the word order of every Float here. A wrong order would give plausible but wrong numbers, not an error: 21.5 °C read with swapped words decodes near 0 °C and passes the range check.
  • The learned word order and battery type hold for the run. Changing either on the inverter needs a driver restart.
  • Battery values are read only when the battery type at 0x24C (588) is not 0, "No battery (PV-Functionality)".
  • On firmware 3.07.03 and later, 0x24C is a U32. With the ABCD order its first word is 0, so the battery reads as absent and the fields stay out. That fails safe; the code comment says so.
  • Unconfirmed: KOSTAL does not say how often 0x434/0x436 refresh or what sign they carry. A negative value is dropped.
  • Not used: 0x40E/0x410 and 0x500/0x502 are limits an external EMS writes.
  • Not documented: cell temperatures and grid headroom.

sigenergy 1.2.0

Field Register (plant, slave 247, FC04) Source Confidence
available_charge_W 30047-30048, U32, gain 1000 on kW (raw = W), "[ESS]Available max charging power" Sigenergy Modbus Protocol V2.9 (2026-05-13), table 5-1, row 29 Medium-high
available_discharge_W 30049-30050, same, "[ESS]Available max discharging power" same, row 30 Medium-high
temperature_C 30286, S16, gain 10, °C, "[ESS]Average cell temperature" same, row 128 (new in V2.9) High
  • Both power registers say "Count only the running inverters". The rated values sit apart at 30068/30070, so these follow plant state.
  • Unconfirmed: the document does not say how the power registers follow the BMS (charge level, temperature).
  • All three are read only when the ESS answered, so a PV-only plant is not asked.
  • Older firmware without 30286 is left alone after three misses.
  • Not read:
    • Cluster max/min temperature (30620/30621) and PCS temperature (31003) exist only at an inverter's own slave address. This plant-address driver does not read those.
    • 30039/30041 are the AC range the running inverters can feed or absorb, not headroom against the grid. They are not sent as available_import_W/available_export_W.
  • upstream_docs points at the vendor PDF in TypQxQ/Sigenergy-Local-Modbus (marked volatile), because Sigenergy's download page refuses direct fetches.

sma 2.2.0: fabricated-zero fix only

  • temp_c from 30849 "Battery temperature" and inverter_temp_c from 30953 "Internal temperature" (S32, TEMP format) are now left out when the read fails or answers NaN. They used to be sent as 0 °C. Source: SMA Modbus TI for Sunny Boy / Sunny Tripower, version 1.4.
  • No live limit documented:
    • 40189/40191 "Maximum charge/discharge power of the battery" are read-only. They sit in the device-parameter block beside the nominal capacity and the maximum apparent power, so they read as ratings.
    • 40081/40083 and 40793-40799 are settings.
    • 30997/30999 are battery statistics, not live cell temperatures.
  • Caveat: SMA's TEMP format follows the device's unit setting (°C, °F or K). The driver assumes °C. K is dropped by the range check; °F is not.
  • I could not get SMA's per-device Modbus HTML lists for SBS, STP X or SI. The register rows come from the generic SMA_Modbus-TI-en-14, which is not on files.sma.de. upstream_docs names SMA-Modbus-TI-en-10, which is hosted there.

fronius 2.2.0: fabricated-zero fix only

  • The inverter temperature now comes from TmpCab, "Cabinet Temperature", float32 at register 40110 in Fronius's 1-based numbering, which is address 40109 on the wire.
  • The driver used to read 40111, which is TmpSnk. Fronius's GEN24, Tauro and Verto maps mark TmpSnk "not supported", so it answered NaN and the driver sent 0 °C.
  • Source: Fronius GEN24 Modbus TCP & RTU manual 42,0410,2649 (034-28092026), and the register map bundle 1.2.7-2 behind fronius.com/QR-link/0024.
  • Nothing documented over Modbus:
    • No battery temperature: model 124 has none, and the model 160 module Tmp is "not supported".
    • No live limit: the manual defines WChaMax as max(MaxChaRte, MaxDisChaRte), the nameplate rates.
    • No grid headroom: model 122 WAval is "not supported".

Found while reading, not changed here

  • Fronius battery addresses look wrong.
    • The driver reads model 124 at fixed addresses (40315 onward) that assume a two-module model 160.
    • Fronius's own storage maps add two storage modules to model 160. They put WChaMax at register 40356 (float) or 40346 (int+SF), and say to find each model by walking the chain.
    • InBatV is "not supported", and OutWRte/InWRte are setpoints, not measured rates.
    • So the Fronius battery w, v and soc are likely wrong on a GEN24 with storage. This needs its own fix; there is a NOTE in the driver.
  • Fronius floats on 32-bit Lua. Fronius's decode_f32_be joins both words into one 32-bit number. That flips the sign on a Lua build with 32-bit integers, which the test interpreter is ("Numbers" in WRITING-A-DRIVER.md). The new temperature decoder works on the 16-bit halves; the old one is unchanged.
  • Fabricated zeros remain. These drivers still send 0 for other fields whose read failed (W, V, SoC, meter values). The invented-number baseline drops by 1 to 2 per driver here, and the rest is unchanged.
  • device_state not added. Huawei (37000 running status) and Sigenergy (30051 plant running state) could report it later. It was outside this task.

Tests

  • New Lua harness tests, one file per driver: drivers/tests/test_{huawei,sma,fronius,kostal,sigenergy}_battery_now.py. Each covers:
    • fields and metrics present, with scale and sign (negative temperatures included)
    • a 0 W limit kept as a reading
    • fields absent when the read fails
    • NaN and out-of-range values dropped, with both temperature edges kept
    • no limit read when no battery answers
  • Huawei is also tested with a unit that answers 0, a rating that does not answer, and one rating above 0.
  • Kostal is also tested in both word orders, and with the word order unknown.
  • make test-driver ID=<id> passed for all five.
  • make absent-register-report settles for every new register.
  • make check: 5101 passed, 929 skipped.
  • drivers/tests/invented-number-baseline.json shrinks: fronius 11 to 10, kostal 22 to 21, sma 28 to 26.

Not verified on hardware. FTW's bundled copies of huawei, sma, fronius and kostal do 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:31:09.841006Z f0ca186 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 added a commit that referenced this pull request Nov 22, 2026
…e the caveats

Review of #259.

- huawei: a SUN2000 with no LUNA2000 may answer 37001/37004 with 0, so
  that answer does not prove a battery. The temperature (37022) and the
  limits (37046/37048) are now read only once energy storage unit 1
  reports a rated charge or discharge power above 0 (37007/37009, U32 W).
  Otherwise 0 W would read as "may not charge now". The finding is kept
  for the run; until then it is read on each poll the battery answers.
  Tests cover a unit that answers 0, a rating that does not answer, and
  one rating above 0.
- huawei: CHANGELOG, manifest and code say plainly that 37046/37048 are
  not shown to be live on hardware, and that only unit 1 is read.
- kostal: the code comment says that taking register 5 as the word order
  of every Float is unverified on hardware, that a wrong order gives
  plausible but wrong values, and that the learned order and battery type
  hold until a driver restart.

Refs #250

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg and others added 2 commits November 22, 2026 10:48
…y can do now

Core will judge a battery against what the device says it can do now
(docs/WRITING-A-DRIVER.md, "What a battery can do now"). Each driver now
reports what its vendor documents, and leaves out what did not answer.

- huawei 2.2.0: available_charge_W/available_discharge_W from 37046/37048
  ("[Energy storage] Maximum charge/discharge power", U32 W). Huawei does
  not say how fast they follow the BMS.
- kostal 2.2.0: temperature_C from 0xD6 and available_* from 0x434/0x436,
  "Maximum charge/discharge power limit (read-out from battery)", Floats
  in the word order register 0x05 reports, read only when 0x24C shows a
  battery.
- sigenergy 1.2.0: available_* from plant 30047/30049 ("[ESS] Available
  max charging/discharging power") and temperature_C from 30286 (average
  cell temperature), read only when the ESS answered.
- sma 2.2.0, huawei, kostal: battery and inverter temperatures are left
  out when the read fails, is NaN or is outside -40..100 C, instead of 0.
- fronius 2.2.0: the inverter temperature comes from TmpCab (40109).
  40111 is TmpSnk, which Fronius marks not supported, so it sent 0 C.

SMA and Fronius document no live charge or discharge limit, so they send
none. No driver documents grid import/export headroom. Metrics follow the
same rules. 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]>
…e the caveats

Review of #259.

- huawei: a SUN2000 with no LUNA2000 may answer 37001/37004 with 0, so
  that answer does not prove a battery. The temperature (37022) and the
  limits (37046/37048) are now read only once energy storage unit 1
  reports a rated charge or discharge power above 0 (37007/37009, U32 W).
  Otherwise 0 W would read as "may not charge now". The finding is kept
  for the run; until then it is read on each poll the battery answers.
  Tests cover a unit that answers 0, a rating that does not answer, and
  one rating above 0.
- huawei: CHANGELOG, manifest and code say plainly that 37046/37048 are
  not shown to be live on hardware, and that only unit 1 is read.
- kostal: the code comment says that taking register 5 as the word order
  of every Float is unverified on hardware, that a wrong order gives
  plausible but wrong values, and that the learned order and battery type
  hold until a driver restart.

Refs #250

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg merged commit 203abe7 into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the battery-limits-g1 branch November 22, 2026 09:52
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