Skip to content

fix(goodwe): read PV, battery and meter from GoodWe's map (2.3.0) - #267

Merged
frahlg merged 2 commits into
mainfrom
map-264
Nov 22, 2026
Merged

frahlg merged 2 commits into
mainfrom
map-264

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What this does

goodwe read most of its PV, battery and meter values from the wrong registers (#264). This PR moves every one of those reads to the address, type and scale in GoodWe's own map. The driver stays read-only; no write or control path changes.

Not verified on hardware. All test values are synthetic. A field report from a GoodWe ET or EH site would settle it: raw words for 35019 (ARM firmware version), 35103-35123, 35180-35184, 36004-36026, 36052-36057 and 37000-37023, and what SEMS or the display shows at the same moment. Please post one on #264 if you have a GoodWe.

Sources

  1. GoodWe, Modbus Protocol Hybrid for Energy Storage Inverters, 2 February 2024 (PDF, already in upstream_docs). Used for addresses, types and scales.
  2. evcc's goodwe-hybrid template (ET/EH/BH/BT/ESA), added to upstream_docs.
  3. The goodwe library, et.py (ET/EH/BT/BH).

GoodWe's table states no signs in words. Both integrations treat battery discharge and meter export as positive: evcc scales meter power by -1 and passes battery power through as "positive = discharging", and the library's house consumption adds battery power and subtracts meter power. The driver turns both round, as our convention needs. Addresses, types and scales only were taken from the integrations; no code was copied.

Reads changed

Value Was Now Confidence
PV power 35105 U32 × 0.1 (PV1 alone) sum of 35105, 35109, 35113, 35117, U32 W; an MPPT reading 0xFFFFFFFF adds nothing high (all three agree)
PV2 V / A 35109 / 35110 (PV2 power) 35107 / 35108 high
Grid frequency (grid_hz) 35113 (PV3 power, high word) 35123, U16 × 0.01 Hz high
Battery power 35180 I16 (the battery voltage) 35182-35183 S32, negated high for address and type; sign from evcc and the library
Battery voltage 35178 (BUS voltage) 35180 U16 × 0.1 V high
Battery current 35179 (NBUS voltage) 35181 S16 × 0.1 A, negated high for address; the sign follows power, since the voltage is never negative
Battery SoC 35182 (power, high word) 37007 %, only while 37011 says a BMS talks; above 100 (0xFFFF) left out high for address (all three)
Meter power 35140-35141 I32 (two halves of different values) 36025-36026 S32, negated, above ARM firmware 9 only high (vendor and evcc)
Meter power per phase 35132-35137 (inverter T phase current, frequency, power, grid mode) 36019 / 36021 / 36023 S32, negated, above ARM firmware 9 only high (vendor and evcc)
Meter frequency 35113 36014, U16 × 0.01 Hz high
Meter V / A per phase 35121-35126 (inverter phase values, mixed with frequency and power) 36052-36057, U16 × 0.1 medium: vendor and evcc list them; the library reads them only on newer units
Meter energy bought / sold 35195 / 35199-35200 (an inverter export total and a daily value) 36017 / 36015, float32 Wh medium: vendor gives address and type, "read from meter"; the unit (Wh) comes from evcc and the library

Kept as they were, because they already match all three sources: PV1 V/A (35103/35104), PV lifetime energy (35191, × 0.1 kWh), heat sink temperature (35176) and #262's BMS block (37000-37023).

New rules

  • No battery when there is none. 35184 = 0 means "No battery, or battery disconnected" (Table 8-9). No battery stream goes out then, as the goodwe library also treats mode 0 (docs/WRITING-A-DRIVER.md, "A hybrid inverter may have no battery"). test_goodwe_battery_now.py changed for this one case.
  • No meter when the inverter does not hear one. The meter goes out only while 36004 ("Meter Communication Status") is 1. Before, a site without a meter got the inverter's own power reported as the grid.
  • No meter on old firmware. GoodWe's table puts meter power at 36019-36041 only when the ARM firmware version is above 9, and at 36005-36008 (S16) before that. On older firmware 36019 and up would read 0, and with 36004 = 1 that is a confident 0 W site meter. The driver reads the ARM version (35019, U16, the register the goodwe library reads as arm_version) once. On ARM 9 or older, or while 35019 has not answered, it sends no meter. No source gives the sign of 36005-36008, so the driver does not read them; a field report from an old unit could change that. 35019 is given up after three failed tries, like every other register.
  • No-value sentinels. A PV power or PV lifetime energy of 0xFFFFFFFF is left out (evcc reads these as uint32 with that sentinel), so an unused PV3/PV4 cannot add 4.3 GW. With no MPPT power at all, no PV stream goes out. A SoC above 100 % (0xFFFF) is left out.
  • Never fabricate. Each stream goes out only when its defining read answered, and each field only from a register that answered. The driver was 23 fields in invented-number-baseline.json and is now clean, so it is removed from that file.
  • 32-bit values are joined on their 16-bit halves (docs/WRITING-A-DRIVER.md, "Numbers"), and float32 NaN or infinity gives no value.

Left alone, and why

  • Model families. The driver covers GoodWe's ET platform (ET-Plus, EH; evcc and the library put BH and BT on the same map). ES, EM and BP speak another protocol; the driver does not claim them, and nothing moved them onto this map. The driver has no model detection, and this map does not need one to tell those families apart.
  • Meter power on ARM firmware 9 and older (36005-36008): not read, since no source gives their sign. Those units get no meter (see above).
  • 36017 on newer models. evcc notes that 36017 reads 0 on some newer models (ETA-G20) and offers 36120/36104 instead. Those are not in GoodWe's February 2024 table, so they are not used.
  • Second battery (35262 and 39000): not read, as before.

Tests

  • New drivers/tests/test_goodwe_map.py (33 cases): PV sum over four MPPTs and both words, PV2 address, PV energy, frequency at 35123, 0xFFFFFFFF left out of the PV sum and the energy, no PV when no MPPT has a value; battery sign while discharging and charging, both words, SoC from 37007, SoC 0xFFFF and 101 left out, no battery on mode 0, nothing on a failed read, no SoC without a talking BMS; meter sign for export and import, per-phase power, frequency, float energy, per-phase V/A, no meter on 36004 = 0 or a failed read, NaN energy left out; no meter on ARM 9 or when 35019 fails, a meter on ARM 10, 35019 read once and given up after three tries; and that none of the old wrong registers is read. The first 23 were written before the map change and 22 of them fail on main (the one that passes covers PV lifetime energy, whose read did not change); the firmware and sentinel cases were written before their fix and failed on the first version of this branch.
  • Removed: goodwe_fixtures.lua, test_goodwe_failures.lua, test_goodwe_ftw_contract.lua and test_goodwe_profiles.lua under drivers/tests/lua_harness/. No test ran them. They tested the community-v1 and gw8kn-et-hk3000 profiles, which the driver lost in feat: FTW's field-proven drivers become the source #27, and community-v1 encoded the wrong map. The THIRD_PARTY_NOTICES.md entry for the gw8kn-et-hk3000 profile goes too, since no file derives from it any more.
  • test_all_drivers.lua (not run by CI) now sets 36004 and 37011 for GoodWe and puts its SoC at 37007; goodwe passes there.
  • make test-driver ID=goodwe: 95 passed, 6 skipped.
  • make check: 5304 passed, 928 skipped, on head 1a49f2c (rebased onto main after fix(growatt): leave a failed read out instead of sending 0 (2.2.2) #273).
  • make absent-register-report ID=goodwe: every register settles to 0 failed reads after three tries.

Version 2.3.0 via make bump-driver; CHANGELOG, manifest and generated files updated.

Refs #264

🤖 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-22T12:23:10.563593Z f9932d5 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: f9932d5d14

ℹ️ 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/goodwe.lua Outdated
Comment on lines +250 to +251

local pv_w = u32(regs[3], regs[4]) + u32(regs[7], regs[8])

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 Filter unavailable MPPT power before summing

When an MPPT reports the 0xFFFFFFFF unavailable sentinel, this sum includes it as power. On the repository's 32-bit Lua build, each such input becomes -1 W: synthetic PV1/PV2 readings of 2800/2300 W with unavailable PV3/PV4 produce -5098 W instead of -5100 W, and zero production becomes positive consumption. With 64-bit Lua integers, the same sentinel becomes billions of watts. The referenced GoodWe library explicitly recognizes this sentinel and excludes it from its PV total. Check the word pair before adding each MPPT.

Useful? React with 👍 / 👎.

Comment thread drivers/lua/goodwe.lua

local lifetime_wh = nil
local energy = probe_read(35191, 2, "holding")
if energy and energy[2] ~= nil then

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 Scale lifetime energy using floating-point arithmetic

On the repository's LUA_32BITS build, both u32() and the literal 100 are integers, so this multiplication wraps once lifetime generation reaches 2,147,483.7 kWh. A synthetic register count of 21,474,837 reproduces lifetime_wh = -2147483596 instead of approximately 2,147,483,700 Wh. The previous calculation promoted to floating point through * 0.1; retain floating-point scaling here so a valid cumulative counter cannot become negative.

Useful? React with 👍 / 👎.

@frahlg
frahlg force-pushed the map-264 branch 3 times, most recently from 87c6d9f to 1a49f2c Compare November 22, 2026 12:59
frahlg and others added 2 commits November 22, 2026 14:00
The driver read most values from the wrong registers: battery power from
35180 (the battery voltage), battery V and A from 35178/35179 (BUS and
NBUS voltages), SoC from 35182, total PV from PV1 alone scaled by 0.1,
grid frequency from 35113 (PV3 power) and the meter from the inverter's
own phase registers.

Addresses, types and scales now follow GoodWe's "Modbus Protocol Hybrid
for Energy Storage Inverters" (2 February 2024); signs follow evcc's
goodwe-hybrid template and the goodwe library. No battery stream when
35184 says none, no meter when 36004 says the inverter does not hear one,
and no field from a read that failed. The orphaned community-v1 and
gw8kn-et-hk3000 Lua fixtures, which no test ran, are removed.

Refs #264

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
GoodWe's map puts meter power at 36019-36041 only above ARM firmware
version 9 (35019). On older firmware those registers would read 0 and the
driver would send a confident 0 W site meter. No source gives the sign
of the older 36005-36008, so the driver now reads 35019 once and sends no
meter on ARM 9 or older, or while the version is unknown.

PV power and energy of 0xFFFFFFFF (evcc's uint32 "no value") are left
out, and an MPPT without a value adds nothing to PV power. SoC above
100 % (0xFFFF) is left out. The THIRD_PARTY_NOTICES entry for the
removed gw8kn-et-hk3000 profile is dropped, since no file derives from
it any more.

Refs #264

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg merged commit cb7cdf3 into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the map-264 branch November 22, 2026 13:04
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