Skip to content

Solax: add Gen5 support - #4315

Merged
LKuemmel merged 3 commits into
openWB:masterfrom
seaspotter:solax-gen5-support
Nov 16, 2026
Merged

LKuemmel merged 3 commits into
openWB:masterfrom
seaspotter:solax-gen5-support

Conversation

@seaspotter

@seaspotter seaspotter commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

UI: openWB/openwb-ui-settings#1169

Ersetzt den eigenständigen Modulentwurf aus #1972 durch eine Integration in das bestehende solax-Modul, wie dort
vorgeschlagen - die meisten Register sind mit Gen3 identisch, nur PV3 (Register 292), 2. Batterie (297/302) und die zusätzlichen Zähler-Register (Spannung/Strom/cos φ) sind neu.

Registerwerte stammen aus #1972s Diff, inkl. der dortigen Klärung, dass Register 82 den Gesamt- nicht den Tagesertrag liefert. Die Stromkodierung (65535 - Wert) für negative Werte ist aus #1972 übernommen.

Battery-Index folgt genau dem bereits bestehenden Muster bei GoodWe (battery_index in config + Auswahlfeld in der UI).

Fixes #1919 (Ursprungsproblem)

Können geschlossen werden:

Summary by Sourcery

Integrate Solax Gen5 support into the existing Solax module.

New Features:

  • Add Solax Gen5 inverter, battery, and meter support, including PV3, dual-battery selection, and electrical measurements.

Bug Fixes:

  • Preserve existing Solax battery behavior while enabling Gen5-specific register handling.

Enhancements:

  • Extend Solax configuration with a selectable battery index and migrate existing Solax battery configurations to the default first battery.

Tests:

  • Add coverage for Gen5 battery selection and fallback behavior on older Solax generations.

@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit fdaef6f

#1919 Integration with Solax no Bat2 and no PV3 · 2 of 2 met

# Requirement Status Notes
1 Display data from both installed batteries. ✅ Met Battery components can select battery 1 or 2; Gen5 battery 2 reads registers 297 and 302.
2 Include PV3 in displayed PV production. ✅ Met The Gen5 inverter power calculation adds PV3 register 292 to the PV1 and PV2 readings.

@sourcery-ai sourcery-ai 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.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/modules/devices/solax/solax/counter.py" line_range="76" />
<code_context>
+            voltages = [value / 10 for value in self.__tcp_client.read_input_registers(
+                202, [ModbusDataType.UINT_16] * 3, unit=unit)]
+            # von Solax beobachtete Kodierung negativer Ströme als Offset von 65535
+            currents = [(65535 - value) / 10 for value in self.__tcp_client.read_input_registers(
+                206, [ModbusDataType.UINT_16] * 3, unit=unit)]
+            power_factors = [value / 100 for value in self.__tcp_client.read_input_registers(
</code_context>
<issue_to_address>
**Positive phase currents become enormous**

When a Gen5 current register contains an ordinary non-negative reading, `SolaxCounter.update` applies `(65535 - value) / 10` to every raw current, so ordinary readings become values near 6,553 A; `CounterState` only adjusts signs and publishes the excessive magnitudes as phase currents.

Apply the offset conversion only to negatively encoded current values.

Also at `packages/modules/devices/solax/solax/counter.py:77`.
</issue_to_address>

### Comment 2
<location path="packages/modules/devices/solax/solax/bat.py" line_range="55" />
<code_context>
-        # Basiswerte aus dem Batterie-Registersatz lesen
-        power = self.__tcp_client.read_input_registers(0x0016, ModbusDataType.INT_16, unit=unit)
-        soc = self.__tcp_client.read_input_registers(0x001C, ModbusDataType.UINT_16, unit=unit)
+        if self.component_config.configuration.battery_index == 2:
+            power = self.__tcp_client.read_input_registers(297, ModbusDataType.INT_16, unit=unit)
+            soc = self.__tcp_client.read_input_registers(302, ModbusDataType.UINT_16, unit=unit)
</code_context>
<issue_to_address>
**Non-G5 batteries read Gen5 registers**

When a non-G5 inverter is configured with battery index 2, `SolaxBat.update` selects registers 297 and 302 solely from `battery_index`, so it reads unrelated or unsupported registers and reports invalid battery values or fails the update.

Use the second-battery registers only when the inverter is Gen5.
</issue_to_address>

### Comment 3
<location path="packages/modules/devices/solax/solax/counter.py" line_range="69-70" />
<code_context>
+            power = self.__tcp_client.read_input_registers(
+                0x0046, ModbusDataType.INT_32, wordorder=Endian.Little, unit=unit) * -1
+            frequency = self.__tcp_client.read_input_registers(0x0007, ModbusDataType.UINT_16, unit=unit) / 100
+            powers = [-value for value in self.__tcp_client.read_input_registers(
+                130, [ModbusDataType.INT_32] * 3, wordorder=Endian.Little, unit=unit)]
+            exported, imported = [value * 10 for value in self.__tcp_client.read_input_registers(
+                0x0048, [ModbusDataType.UINT_32] * 2, wordorder=Endian.Little, unit=unit)]
</code_context>
<issue_to_address>
**Optional meter reads block counter updates**

When a Gen5 phase-measurement register read fails while the core power and energy registers remain readable, `SolaxCounter.update` lets errors reading phase powers, voltages, currents, or power factors escape before it creates and stores `CounterState`, so usable total power and energy readings are lost for that update and the last counter state remains stale.

Treat the added phase measurements as optional: catch their read failures and store the available core counter values with missing phase fields set to `None`.

Also at `packages/modules/devices/solax/solax/counter.py:73-79`.
</issue_to_address>

### Comment 4
<location path="packages/modules/devices/solax/solax/bat_test.py" line_range="54-55" />
<code_context>
+
+    solax_bat.update()
+
+    client.read_input_registers.assert_any_call(0x0016, bat.ModbusDataType.INT_16, unit=1)
+    client.read_input_registers.assert_any_call(0x001C, bat.ModbusDataType.UINT_16, unit=1)
+
+
</code_context>
<issue_to_address>
**Wrong battery still passes**

When `update()` reads the expected registers but uses another battery's values, `test_update_reads_first_battery_registers_by_default` and `test_update_reads_second_battery_registers_when_configured` pass even if `update()` stores values from the wrong battery, because these assertions only require the expected reads to occur; they do not verify that those reads supply the stored state.

Assert the exact read calls and verify the resulting battery state uses the selected battery's values.

Also at `packages/modules/devices/solax/solax/bat_test.py:66-67`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@LKuemmel
LKuemmel merged commit 2c8c59d into openWB:master Nov 16, 2026
2 checks passed
@seaspotter
seaspotter deleted the solax-gen5-support branch November 16, 2026 14: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.

Integration with Solax no Bat2 and no PV3

2 participants