Repository navigation
Fix: Solakon One: power values - #4316
Open
seaspotter wants to merge 4 commits into
Open
seaspotter wants to merge 4 commits into
seaspotter wants to merge 4 commits into
Conversation
Linked issuesChecked at commit fe7d80f #3852 [BUG] Solakon ONE: statt Netz- nun Batterieleistung ausgewertet / Werte verfälscht · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/devices/solakon/solakon_one/bat.py" line_range="36" />
<code_context>
- # Reg 39237 Battery Combined Power
- power = self.client.read_holding_registers(39237, ModbusDataType.INT_32, unit=unit)
+ # Reg 39230 Battery Power, laut Hersteller-Doku positiv beim Laden, negativ beim Entladen
+ power = self.client.read_holding_registers(39230, ModbusDataType.INT_32, unit=unit)
# SoC Ladezustand der Batterie in %
soc = self.client.read_holding_registers(39424, ModbusDataType.INT_16, unit=unit)
</code_context>
<issue_to_address>
**Still reads battery power**
The issue asks for power at the grid connection, as before, because battery-power readings distort the values. This change reads register 39230 for battery power instead.
</issue_to_address>
Collaborator
Author
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/devices/solakon/solakon_one/counter.py" line_range="35" />
<code_context>
+
+ # Reg 39134 AC Leistung am Stecker (Grid Information laut Hersteller-Doku), Bezug hat positive Werte,
+ # Einspeisung hat negative Werte
+ power = self.client.read_holding_registers(39134, ModbusDataType.INT_32, unit=unit) * -1
+
+ # Gesamte Netzeinspeisung/-bezug in Wh
</code_context>
<issue_to_address>
**Grid power direction is reversed**
When the grid register reports its documented positive-import or negative-export value, `power` negates register 39134 before storing it in `CounterState`, so imports are reported as exports and exports as imports; `CounterAll` then uses the reversed power for consumption calculations, and callers see incorrect grid direction and consumption.
Store register 39134 without reversing its documented sign.
</issue_to_address>
### Comment 2
<location path="packages/modules/devices/solakon/solakon_one/inverter.py" line_range="41" />
<code_context>
+ power = self.client.read_holding_registers(39118, ModbusDataType.INT_32, unit=unit) * -1
+ # Gesamte DC PV Produktion in Wh
+ exported = self.client.read_holding_registers(39601, ModbusDataType.UINT_32, unit=unit) * 10
+ imported, _ = self.sim_counter.sim_count(power)
imported, exported = self.peak_filter.check_values(power, imported, exported)
</code_context>
<issue_to_address>
**AC imports are not accumulated**
When the inverter consumes or charges from AC while PV output is absent or generating, `power` comes from the DC PV register and is negated before `sim_counter.sim_count()`, which counts generation as export; assigning only its imported result leaves `InverterState.imported` unchanged, so AC consumption is not reported.
Derive simulated imported energy from an AC-import measurement rather than the DC PV power register.
Also at `packages/modules/devices/solakon/solakon_one/inverter.py:42`.
</issue_to_address>
### Comment 3
<location path="packages/modules/devices/solakon/solakon_one/inverter.py" line_range="38" />
<code_context>
- exported = self.client.read_holding_registers(39621, ModbusDataType.UINT_32, unit=unit) * 10
- imported = self.client.read_holding_registers(39625, ModbusDataType.UINT_32, unit=unit) * 10
+ # Gesamte DC PV Leistung aller vier MPPT in W
+ power = self.client.read_holding_registers(39118, ModbusDataType.INT_32, unit=unit) * -1
+ # Gesamte DC PV Produktion in Wh
+ exported = self.client.read_holding_registers(39601, ModbusDataType.UINT_32, unit=unit) * 10
</code_context>
<issue_to_address>
**Valid PV readings are rejected**
When DC PV power exceeds twice the configured AC output maximum, `PeakFilter.check_values()` compares the DC PV reading with the AC output maximum and rejects the update, so valid inverter data is omitted and the inverter state is not refreshed.
Validate the DC PV reading against an appropriate DC limit instead of the configured AC output maximum.
Also at `packages/modules/devices/solakon/solakon_one/inverter.py:39`.
</issue_to_address>
### Comment 4
<location path="packages/modules/devices/solakon/solakon_one/inverter.py" line_range="41" />
<code_context>
+ power = self.client.read_holding_registers(39118, ModbusDataType.INT_32, unit=unit) * -1
+ # Gesamte DC PV Produktion in Wh
+ exported = self.client.read_holding_registers(39601, ModbusDataType.UINT_32, unit=unit) * 10
+ imported, _ = self.sim_counter.sim_count(power)
imported, exported = self.peak_filter.check_values(power, imported, exported)
</code_context>
<issue_to_address>
**Rejected samples still change energy**
When a power reading exceeds twice the configured inverter maximum, `sim_counter.sim_count()` persists the sample and accumulated energy before `peak_filter.check_values()` rejects it, so the failed update still advances the simulated total and callers see incorrect inverter energy.
Reject the sample before updating the simulated counter state.
</issue_to_address>
### Comment 5
<location path="packages/modules/devices/solakon/solakon_one/inverter.py" line_range="41" />
<code_context>
+ power = self.client.read_holding_registers(39118, ModbusDataType.INT_32, unit=unit) * -1
+ # Gesamte DC PV Produktion in Wh
+ exported = self.client.read_holding_registers(39601, ModbusDataType.UINT_32, unit=unit) * 10
+ imported, _ = self.sim_counter.sim_count(power)
imported, exported = self.peak_filter.check_values(power, imported, exported)
</code_context>
<issue_to_address>
**Simulated import resets on restart**
When the service restarts after the inverter has accumulated simulated import energy, `sim_counter.sim_count(power)` restores the inverter’s simulated state through `SimCounterStoreBroker.initialize`, which explicitly initializes inverter `imported` energy to 0 instead of restoring its last value. After a service restart, the inverter’s accumulated simulated import therefore starts over and callers see the energy total drop.
Restore the inverter’s last imported total during SimCounter initialization now that inverter imports are simulated.
</issue_to_address>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UI: openWB/openwb-ui-settings#1170
Fixes #3852: seit #3497 liest bat.py Register 39237 ("Battery Combined Power") für die Batterieleistung. Dieses Register existiert laut der offiziellen Solakon-Dokumentation (https://github.com/solakon-de/solakon-one-homeassistant/blob/main/custom_components/solakon_one/const.py) überhaupt nicht - das echte, dort dokumentierte Batterieleistungsregister ist 39230 ("battery_power").
Zusätzlich: neuer counter-Baustein (Reg 39134, "Grid Information") für Nutzer ohne separaten Zähler, inverter.py zurück auf reine PV-Register (39118/39601).
Summary by Sourcery
Correct Solakon One power measurements and add integrated grid-meter support for installations without a separate counter.
New Features:
Bug Fixes:
Enhancements: