Skip to content

fix(fronius): read the battery where the GEN24 storage maps put it (2.3.0) - #272

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

frahlg merged 2 commits into
mainfrom
map-260

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What this does

fronius read battery power, voltage and SoC from addresses that do not match Fronius's GEN24 storage maps, and its float decoder flipped the sign of every float on 32-bit Lua. This PR reads the battery where Fronius's maps put it, fixes the decoder, and leaves out what did not answer. The driver is read_only; no command path changes.

Source

Fronius register map bundle 1.2.7-2 (www.fronius.com/QR-link/0024, already in upstream_docs): the GEN24 Primo/Symo and Verto float maps, with and without storage. Fronius GEN24 Modbus manual 42,0410,2649 (also in upstream_docs). evcc's fronius-gen24 template reads the battery the same way (checked for addresses and signs only; no code copied). Fronius numbers registers from 1; the wire address is one lower.

Reads changed

What Before (wire) Now Confidence
Model 160 (MPPT) SFs at 40265, 40266; MPPT 1/2 at 40282, 40302 one read of the whole model from 40263, length from its header, so the auto-scaled factors come with their values high
Model 124 (storage) fixed at 40313 onward, which assumes a two-input model 160 found right after model 160 (40353 on a GEN24 with storage, 40373 on a Verto with three trackers); ID must be 124, length 24 high
Battery W OutWRte / InWRte (40325 / 40326) times WChaMax (40315): rate setpoints and a rating charge input DCW minus discharge input DCW, the last two blocks of model 160 ("StCha", "StDisCha"), times DCW_SF; positive charging high
Battery V 40323, InBatV in the driver's assumed layout; Fronius marks InBatV "not supported" larger of the two inputs' DCV times DCV_SF (before firmware 1.31 only the active input carries it); left out when both are 0 high
SoC 40321 ChaState (model 124, offset 8) times ChaState_SF (offset 22) high
PV W with storage model 113 DCW (40107), which may include the battery input sum of the MPPT blocks before the battery blocks, times DCW_SF, as evcc reads it high for the registers; see below
PV W without storage model 113 DCW unchanged high
Rated W WRtg and WRtg_SF in two reads one read of 40134-40135, same registers high

On a GEN24 with storage the old battery reads landed inside model 160's battery blocks (40315 is the StCha name string, for example).

  • No storage, no battery. Model 124 exists only with storage. Without it Fronius puts the end block (0xFFFF) right after model 160. That answers, so the driver learns there is no battery without a failed read. Earlier releases sent 0 W, 0 V and 0 % there.
  • Names are checked. Battery power and voltage are read only when the last two blocks are named StCha and StDisCha, as both maps name them. On any other layout the driver sends no battery power.
  • Float decoder. It now works on the 16-bit halves (docs/WRITING-A-DRIVER.md, "Numbers"), as ferroamp_modbus was fixed in feat(victron_mqtt, victron, ferroamp_modbus, zap): what the battery can do now #254. The old one compared the joined word with 0x80000000, which is negative on 32-bit Lua, so every float came out negative there. FTW and Blixt L1 use 64-bit integers and were not affected. NaN and infinity now give nil instead of 0.
  • PV with storage. Fronius's map does not say whether model 113's DC power includes the battery input. If it does, a 3 kW discharge would show as 3 kW more sun. With battery blocks present, PV is therefore the sum of the MPPT blocks. Model 113's DC power is used only where there is no battery input. When the storage model is known but the battery blocks cannot be read that poll, PV is left out for that poll.
  • A battery fitted later. While no storage model is known, the driver reads the chain again every five minutes (two short reads), and at once when model 160's length changes. A battery fitted after start is found without a restart.
  • Failed reads. PV is sent only when DC power answered. Every other PV field and metric is sent only when its own read answered. SunSpec's "not implemented" values (0xFFFF, scale factor 0x8000) are left out. fronius leaves invented-number-baseline.json (10 to 0).

Left alone

  • int+SF setting. There, model 160 starts at 40254 and the inverter model differs. The driver reads only the float maps, as before. It now sends no DC input or battery values there, rather than wrong ones, and logs why.
  • No battery temperature or live limit. None is documented: model 124 has no temperature point, the battery blocks' Tmp is "not supported", and WChaMax is a rating (as feat(huawei, sma, fronius, kostal, sigenergy): report what the battery can do now #259 found).
  • Tauro and Symo/Primo classic have no storage maps, so they send no battery. Their MPPT reads are unchanged.
  • Unused reads. The AC power and per-phase reads that the driver reads but does not send are unchanged.

Tests

drivers/tests/test_fronius_storage_map.py, 28 cases, built from the float storage maps:

  • charging, discharging, old firmware voltage, idle;
  • a Verto with three trackers;
  • MPPT scaling;
  • no storage: no battery, and no read past the end block;
  • model 124 or model 160 not answering;
  • SoC not implemented or out of range;
  • storage blocks not named as documented;
  • model 160 not at 40264;
  • the old addresses failing;
  • float sign, NaN and failed PV reads;
  • PV with storage as the MPPT sum, including a Verto, scale factors and a tracker that is not implemented; PV without storage from model 113; no PV when the battery blocks are unreadable;
  • a battery fitted later: found when model 160 grows, found after five minutes when only model 124 appears, and not looked for on every poll.

26 of the 28 fail against main. The two that pass, MPPT values and rated power, cover reads whose registers did not change.

Not verified on hardware. All values in the tests are synthetic. A field report from a GEN24 or Verto with a battery would confirm it: battery W, V and SoC next to Solar.web. The same report would show whether model 113's DC power includes the battery, which decides nothing now but would tell us if the MPPT sum is needed.

Refs #260

🤖 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:34:08.615890Z d52b4e4 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
…y again

Review of #272:

- With storage, PV power is now the sum of the MPPT blocks before the
  battery blocks, as evcc's fronius-gen24 template reads it. Fronius's map
  does not say whether model 113's DC power includes the battery input, so
  a 3 kW discharge could have shown as 3 kW of sun. Model 113's DC power is
  used only where there is no battery input, and PV is left out for a poll
  where the storage model is known but the battery blocks are not readable.
- The storage check is no longer sticky. While no storage model is known
  the driver reads the chain again every five minutes, and at once when
  model 160's length changes, so a battery fitted after start is found.

Refs #260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
frahlg added a commit that referenced this pull request Nov 22, 2026
…y again

Review of #272:

- With storage, PV power is now the sum of the MPPT blocks before the
  battery blocks, as evcc's fronius-gen24 template reads it. Fronius's map
  does not say whether model 113's DC power includes the battery input, so
  a 3 kW discharge could have shown as 3 kW of sun. Model 113's DC power is
  used only where there is no battery input, and PV is left out for a poll
  where the storage model is known but the battery blocks are not readable.
- The storage check is no longer sticky. While no storage model is known
  the driver reads the chain again every five minutes, and at once when
  model 160's length changes, so a battery fitted after start is found.

Refs #260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
frahlg added a commit that referenced this pull request Nov 22, 2026
…y again

Review of #272:

- With storage, PV power is now the sum of the MPPT blocks before the
  battery blocks, as evcc's fronius-gen24 template reads it. Fronius's map
  does not say whether model 113's DC power includes the battery input, so
  a 3 kW discharge could have shown as 3 kW of sun. Model 113's DC power is
  used only where there is no battery input, and PV is left out for a poll
  where the storage model is known but the battery blocks are not readable.
- The storage check is no longer sticky. While no storage model is known
  the driver reads the chain again every five minutes, and at once when
  model 160's length changes, so a battery fitted after start is found.

Refs #260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
frahlg added a commit that referenced this pull request Nov 22, 2026
…y again

Review of #272:

- With storage, PV power is now the sum of the MPPT blocks before the
  battery blocks, as evcc's fronius-gen24 template reads it. Fronius's map
  does not say whether model 113's DC power includes the battery input, so
  a 3 kW discharge could have shown as 3 kW of sun. Model 113's DC power is
  used only where there is no battery input, and PV is left out for a poll
  where the storage model is known but the battery blocks are not readable.
- The storage check is no longer sticky. While no storage model is known
  the driver reads the chain again every five minutes, and at once when
  model 160's length changes, so a battery fitted after start is found.

Refs #260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
frahlg and others added 2 commits November 22, 2026 14:04
….3.0)

Earlier releases read model 124 at fixed addresses that assume a model 160
with two inputs. With storage, Fronius's model 160 has two more blocks for
the battery, so those reads landed inside them. Battery power also came
from the OutWRte / InWRte setpoints times WChaMax, not a measurement.

The driver now reads model 160's header, finds model 124 right after it,
and takes battery power from the StCha / StDisCha blocks (charge minus
discharge, positive charging), voltage from the same blocks, and SoC from
ChaState with its scale factor. Without model 124 it sends no battery.

The float decoder works on the 16-bit halves, so floats keep their sign on
32-bit Lua, and NaN is left out instead of sent as 0. Failed PV reads are
left out too; fronius leaves the invented-number baseline.

Source: Fronius register map bundle 1.2.7-2 (GEN24 and Verto float maps
with storage) and the GEN24 Modbus manual 42,0410,2649; evcc's
fronius-gen24 template agrees. Not verified on hardware.

Refs #260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
…y again

Review of #272:

- With storage, PV power is now the sum of the MPPT blocks before the
  battery blocks, as evcc's fronius-gen24 template reads it. Fronius's map
  does not say whether model 113's DC power includes the battery input, so
  a 3 kW discharge could have shown as 3 kW of sun. Model 113's DC power is
  used only where there is no battery input, and PV is left out for a poll
  where the storage model is known but the battery blocks are not readable.
- The storage check is no longer sticky. While no storage model is known
  the driver reads the chain again every five minutes, and at once when
  model 160's length changes, so a battery fitted after start is found.

Refs #260

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