Skip to content

Commit

Permalink
Fix Solis (openWB#1990)
Browse files Browse the repository at this point in the history
* Solis: fix modbus address for SOC

The Solis support was created based on Fox ESS. It looks like the
creator missed to adjust the modbus address for SOC, it's 33139 based
on a register map I got from solis support.

Total discharge energy is also in kWh, not 1/10kWh units.

* Solis: read all registers as input registers

Every modbus query fails, as all registers need to be read as input
registers (code 0x04), instead of holding register.

* Solis: Fix for unreachable local variables

right now I get the following error:
UnboundLocalError: local variable 'power' referenced before assignment

Fix it by moving some code around.

* Review

---------

Co-authored-by: LKuemmel <[email protected]>
  • Loading branch information
the2masters and LKuemmel authored Nov 7, 2024
1 parent 6751a09 commit ec23648
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
10 changes: 5 additions & 5 deletions packages/modules/devices/solis/solis/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def __init__(self, component_config: SolisBatSetup) -> None:
def update(self, client: ModbusTcpClient_) -> None:
unit = self.component_config.configuration.modbus_id

power = client.read_holding_registers(33149, ModbusDataType.INT_32, unit=unit) * -1
soc = client.read_holding_registers(31038, ModbusDataType.UINT_16, unit=unit)
power = client.read_input_registers(33149, ModbusDataType.INT_32, unit=unit) * -1
soc = client.read_input_registers(33139, ModbusDataType.UINT_16, unit=unit)
# Geladen in kWh
imported = client.read_holding_registers(33161, ModbusDataType.UINT_32, unit=unit) * 1000
# Entladen in kWh * 0,1
exported = client.read_holding_registers(33165, ModbusDataType.UINT_32, unit=unit) * 100
imported = client.read_input_registers(33161, ModbusDataType.UINT_32, unit=unit) * 1000
# Entladen in kWh
exported = client.read_input_registers(33165, ModbusDataType.UINT_32, unit=unit) * 1000

bat_state = BatState(
power=power,
Expand Down
15 changes: 8 additions & 7 deletions packages/modules/devices/solis/solis/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ def __init__(self, component_config: SolisCounterSetup,

def update(self, client: ModbusTcpClient_):
unit = self.component_config.configuration.modbus_id

register_offset = 30000
if self.version == SolisVersion.inverter:
register_offset = -1
elif self.version == SolisVersion.hybrid:
register_offset = 30000
power = client.read_holding_registers(3263 + register_offset, ModbusDataType.INT_32, unit=unit)
powers = client.read_holding_registers(3257 + register_offset, [ModbusDataType.INT_32]*3, unit=unit)
frequency = client.read_holding_registers(3282 + register_offset, ModbusDataType.UINT_16, unit=unit) / 100
imported = client.read_holding_registers(3283 + register_offset, ModbusDataType.UINT_32, unit=unit) * 10
exported = client.read_holding_registers(3285 + register_offset, ModbusDataType.UINT_32, unit=unit) * 10

power = client.read_input_registers(3263 + register_offset, ModbusDataType.INT_32, unit=unit)
powers = client.read_input_registers(3257 + register_offset, [ModbusDataType.INT_32]*3, unit=unit)
frequency = client.read_input_registers(3282 + register_offset, ModbusDataType.UINT_16, unit=unit) / 100
imported = client.read_input_registers(3283 + register_offset, ModbusDataType.UINT_32, unit=unit) * 10
exported = client.read_input_registers(3285 + register_offset, ModbusDataType.UINT_32, unit=unit) * 10

counter_state = CounterState(
imported=imported,
Expand Down
10 changes: 4 additions & 6 deletions packages/modules/devices/solis/solis/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ def update(self, client: ModbusTcpClient_) -> None:
unit = self.component_config.configuration.modbus_id

if self.version == SolisVersion.inverter:
power = client.read_holding_registers(3004, ModbusDataType.UINT_32, unit=unit) * -1
# Unit 1kWh
exported = client.read_holding_registers(3008, ModbusDataType.UINT_32, unit=unit) * 1000
power = client.read_input_registers(3004, ModbusDataType.UINT_32, unit=unit) * -1
exported = client.read_input_registers(3008, ModbusDataType.UINT_32, unit=unit) * 1000
elif self.version == SolisVersion.hybrid:
power = client.read_holding_registers(33057, ModbusDataType.UINT_32, unit=unit) * -1
# Unit 1kWh
exported = client.read_holding_registers(33029, ModbusDataType.UINT_32, unit=unit) * 1000
power = client.read_input_registers(33057, ModbusDataType.UINT_32, unit=unit) * -1
exported = client.read_input_registers(33029, ModbusDataType.UINT_32, unit=unit) * 1000

inverter_state = InverterState(
power=power,
Expand Down

0 comments on commit ec23648

Please sign in to comment.