Skip to content

fix(alphaess, kstar): read the vendor's own register maps (1.3.0) - #269

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

frahlg merged 2 commits into
mainfrom
map-257

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What this does

alphaess and kstar read register addresses that no source supports (#257). Their PV, battery and meter values were therefore probably wrong on real hardware. This PR moves both drivers to the register maps in their vendors' own Modbus documents, with site signs, and sends each stream only when its read answered.

Both drivers are read_only. No write, mode or control path changes.

Gates, in both drivers

  • No battery. Battery voltage and SoC both 0 means no pack is connected, so the battery stream and battery metrics are left out rather than sent as an empty pack (docs/WRITING-A-DRIVER.md, "A hybrid inverter may have no battery"). A pack with a voltage and 0 % SoC is still sent.
  • No meter: not gated. Neither vendor map has a flag that says a grid meter or CT is fitted. AlphaESS's 0x0000 "Grid Meter CT Enable" read 0 on a working system in Alpha2MQTT's register dump, and 0x0806 "Meter CT Select" only says CT or meter. KSTAR's 3264 "CT Or Meter" only says which, and its alarm table has no meter fault. So on a site with no meter, both drivers send whatever the meter registers hold, and 0 W there cannot be told from a balanced site. Both vendors sell these as systems with a CT in the box, but nothing on the wire proves one is fitted.

alphaess 1.3.0

Source: AlphaESS Modbus_RTU/TCP Protocol and its Parameter address table (version history to V1.39, 2024-11-29), and the Household Register Map table, all as copies in ramonvanraaij/ha-alphaess-modbus docs/. AlphaESS publishes no download URL I could find. Cross-checked for addresses, types and signs with evcc alpha-ess-smile.yaml, dxoverdy/Alpha2MQTT and senalse/ha-alphaess-modbus. No code copied.

Field Before Now Source Confidence
meter.W 0x0028, I16 (reactive power, phase C) 0x0021, S32, 1 W, import positive vendor address; sign from Alpha2MQTT ("Minus = feeding, Positive = drawing"), evcc, senalse high for address, medium-high for sign (the vendor gives none)
meter.L1_A 0x0027 0x0017, S16 x 0.1 A vendor, evcc high
meter.Hz 0x0022 (low word of grid power) 0x001A, U16 x 0.01 Hz vendor, Alpha2MQTT high
meter.L1_V 0x0026 left out vendor says 1 V/bit; Alpha2MQTT's author read 2421 for 242.1 V sources disagree
battery.W 0x0020 (grid power C, high word) -(0x0126), S16, 1 W vendor: "-: Charge, +: Discharge"; evcc and Alpha2MQTT agree high
battery.V 0x0021 0x0100, U16 x 0.1 V vendor high
battery.SoC_nom_fract 0x0024 / 100 0x0102, U16 x 0.1 % vendor, evcc high
pv.W -(0x0012) (grid import energy) -(sum of PV1-PV6 power, U32 at 0x041F-0x0433) vendor, evcc high
pv.mppt1_v / mppt1_a 0x0010 / 0x0011 (export energy) 0x041D / 0x041E, x 0.1 vendor high

The cell temperature metrics (0x010D, 0x0110) are unchanged; they now come from the same battery block read (0x0100-0x0126).

Left alone, and why

  • 0x0111 / 0x0112 (battery max charge / discharge current, x 0.1 A) are still not used as live limits. The vendor's table names them without saying they move with the BMS. Alpha2MQTT's code notes the charge value is "always zero for me" and the discharge value 1000 (100 A) on a 50 A pack. senalse calls 0x0111 the BMS's present limit, which contradicts that. A 0 would tell Core the battery may not charge.
  • senalse disagrees on battery sign. It describes 0x0126 as positive when charging. The vendor's table, evcc and Alpha2MQTT all say positive is discharging, so the driver follows them.
  • Older firmware: gated on presence, not on the version number. AlphaESS's own V1.17 protocol (2020) put the grid meter at 0x0000-0x0019 (total power at 0x0006) and the inverter temperature at 0x0429, where the current map has PV4. The meter table changed in V1.19 (2020-10-20), and V1.20 (2020-10-25) added the System info block, 0x0740-0x074E, which the vendor's model table lists for every model. The driver reads 0x074E (Protocol Version) once. If it answers, it uses the current meter and PV strings 1 to 6. If it fails three times, it sends no meter and reads only PV strings 1 to 3, which sit in the same place in V1.17. The battery block is the same in both maps.
    • What could not be gated: the value of 0x074E. It read 0 on a real system in Alpha2MQTT's dump, so the driver cannot tell V1.20 or V1.21 firmware from later. V1.22 (2020-10-30) changed the inverter block again, and I have no copy of the V1.20/V1.21 layout. Firmware from those ten days, if any shipped, would get strings 4 to 6 read from the current layout.
  • PV meter (0x00A1, an AC-coupled inverter) is not added to PV: that inverter may have its own driver.
  • "G2 Series" (G2-H30, G2-H50) in the manifest appears in no AlphaESS source. The driver has no model detection, so it reads the same map for every model, as before. The vendor's model table lists SMILE-SP, SMILE-G3 (S3.6 to S8, T4 to T20), SMILE-S6-HV, SMILE-T10-HV and B3/B3PLUS.

kstar 1.3.0

Source: KSTAR Hybrid Inverter MODBUS RS485 Communication Protocol V2.9.1 (2024-07-21, document SFT-KSE-001), which KSTAR support gave to a ha-solarman user (PDF). Its model table (3.1.5) covers the KSE single-phase models, the BluE-S 3680D/5000D/6000D (and M1) and the E8KT/E10KT/E12KT three-phase models, so both families in the manifest use this map. Cross-checked with davidrapan/ha-solarman and StephanJoubert/home_assistant_solarman kstar_hybrid.yaml. No code copied.

All reads are input registers (function 04H). Before, the driver read holding registers 10-54, which no source has.

Field Now Source Confidence
pv.W -(3024 + 3025), S16, 1 W vendor, both ha-solarman forks high
pv.mppt1_v / mppt1_a 3000 x 0.1 V / 3012 S16 x 0.01 A vendor high (the old read used 0.1 A)
battery.W -(3065), S16, 1 W vendor address; sign from ha-solarman, whose "Power losses" sensor is PV + battery - inverter output, so positive is discharging high for address, medium for sign
battery.V (new) 3063 x 0.01 V vendor high
battery.SoC_nom_fract 3066 x 0.1 % vendor high
meter.W -(3100), plus 3104 and 3108 on three-phase models vendor address; sign from ha-solarman, which negates it "to match standard behavior of the other inverters", and an owner there who saw the raw value negative while importing high for address, medium for sign
meter.L1_V, meter.Hz, meter.L1_A 3097 x 0.1 V, 3098 x 0.01 Hz, 3099 S16 x 0.001 A vendor high (current sent as read; its sign is not documented)

The battery and inverter temperatures (3067, 3055) are unchanged; voltage, power and SoC now come from the same read (3055-3067).

Model detection. KSTAR marks the S and T phase meter registers "only for three phase model". The driver reads the model at 3045 once and uses only the codes KSTAR's table 3.1.5 names (ha-solarman's lookup has the same list): 0-9, 11, 12, 14, 15, 17 and 18 (KSE and BluE-S, single phase) read the R phase; 32-34 (E10KT, E8KT, E12KT) sum R, S and T. The codes the table marks "reserve" (10, 13, 16, 19-31, 35-47) and anything else send no meter, and the driver logs why.

Left alone, and why

  • 3070 / 3071 (BAT_CHG_LIMIT_CURR / BAT_DISCHG_LIMIT_CURR, 1 A) are read-only, but the map does not say they come from the BMS or move with it, so no available_* field is sent.
  • Battery absence uses the voltage-and-SoC rule above. KSTAR's alarm word (3049-3050) has a "Bat Loss" bit (W05) that could also say it; it is not read, to keep to one rule in both drivers.

Also in this PR

  • Both drivers leave invented-number-baseline.json (alphaess 10 → 0, kstar 9 → 0).
  • probe_read in both now treats a short reply as a failed read, so a decode never does arithmetic on nil.
  • lua_harness/test_all_drivers.lua sets the KSTAR model register and moves the two SoC fixtures to the new addresses.
  • Manifests: minor bumps with make bump-driver, vendor documents added to upstream_docs (all answered 200), and a one-line changelog.

Tests

  • New: drivers/tests/test_alphaess_map.py (16 cases) and drivers/tests/test_kstar_map.py (30 cases). They cover each field's address, scale and sign; streams absent on a failed or short read; no battery (voltage and SoC 0) against an empty pack with a voltage; the AlphaESS map gate (0x074E read once; when it never answers, no meter, three PV strings, and only three tries); every listed and reserved KSTAR model code; a failed model read; and that the old addresses are no longer read.
  • The first 25 cases fail against the main drivers. The 21 added in review failed against the first version of this PR before the fix.
  • Updated: the two *_battery_now.py tests now fail the block's first register, since the block is one read.
  • make absent-register-report for both: every address settles, 0x074E included.
  • make test-driver ID=alphaess: 67 passed. make test-driver ID=kstar: 81 passed.
  • make check on head 5f6b587 (rebased onto main after fix(growatt): leave a failed read out instead of sending 0 (2.2.2) #273): 5317 passed, 928 skipped.

Not verified on hardware. All values in the tests are synthetic. The signs that rest on integrations rather than the vendor (AlphaESS grid, KSTAR grid and battery) are the most likely to be wrong. A field report from an AlphaESS or KSTAR owner would settle it: grid power while importing, battery power while charging, and PV power at midday, compared with the vendor app.

Refs #257

🤖 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:24:49.754180Z cf93527 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 map-257 branch 4 times, most recently from c62b52b to 5f6b587 Compare November 22, 2026 12:59
frahlg and others added 2 commits November 22, 2026 14:08
Both drivers read addresses that no source supports, so their PV,
battery and meter values were probably wrong on real hardware.

alphaess follows AlphaESS's parameter address table: grid meter power
at 0x0021 (S32, import positive), phase A current at 0x0017, frequency
at 0x001A; battery power at 0x0126 (AlphaESS: discharge positive, so
negated), voltage at 0x0100, SoC at 0x0102 (0.1 %); PV as the sum of
the six string powers at 0x041F-0x0433. The grid phase voltage is no
longer sent: the sources disagree on its scale.

kstar reads KSTAR's input registers from 3000 (Hybrid Inverter Modbus
V2.9.1): PV at 3000-3025, battery voltage, power and SoC at
3063-3066, and the grid meter at 3097-3108. KSTAR gives no signs;
following ha-solarman, meter power (export positive) and battery
power (discharge positive) are negated. The model at 3045 says whether
the S and T phases exist.

Each stream goes out only when its read answered, never as zeros, so
both drivers leave the invented-number baseline. Not verified on
hardware.

Refs #257

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Review fixes for the 1.3.0 map change.

- Both: battery voltage and SoC both 0 means no pack is connected, so
  the battery stream and battery metrics are left out instead of an
  empty pack (docs/WRITING-A-DRIVER.md, "A hybrid inverter may have no
  battery"). KSTAR's inverter temperature still goes out.
- alphaess: the current meter map and PV strings 4 to 6 are used only
  once 0x074E (Protocol Version, in the System info block that V1.20
  added) answers. Its value is not used; it read 0 on a real system.
  Firmware where it never answers gets PV strings 1 to 3 and no meter.
- kstar: only the model codes KSTAR's table 3.1.5 names (0-9, 11, 12,
  14, 15, 17, 18 single phase; 32-34 three phase) get a meter; reserved
  codes get none.
- Neither map has a flag that says a grid meter is fitted, so the
  meter is still sent without one; the code and CHANGELOG say 0 W is
  then ambiguous.

Not verified on hardware.

Refs #257

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