Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/modules/devices/sma/sma_sunny_boy/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


class SunnyBoyBat(AbstractBat):
SMA_UINT_64_NAN = 0xFFFFFFFFFFFFFFFF # SMA uses this value to represent NaN

def __init__(self,
device_id: int,
component_config: Union[Dict, SmaSunnyBoyBatSetup],
Expand All @@ -35,6 +37,11 @@ def read(self) -> BatState:
exported = self.__tcp_client.read_holding_registers(31401, ModbusDataType.UINT_64, unit=unit)
imported = self.__tcp_client.read_holding_registers(31397, ModbusDataType.UINT_64, unit=unit)

if exported == self.SMA_UINT_64_NAN or imported == self.SMA_UINT_64_NAN:
raise ValueError(f'Batterie lieferte nicht plausible Werte. Export: {exported}, Import: {imported}. ',
'Sobald die Batterie geladen/entladen wird sollte sich dieser Wert ändern, ',
'andernfalls kann ein Defekt vorliegen.')

return BatState(
power=power,
soc=soc,
Expand Down
10 changes: 8 additions & 2 deletions packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


class SunnyBoySmartEnergyBat(AbstractBat):
SMA_INT32_NAN = 0xFFFFFFFF # SMA uses this value to represent NaN
SMA_UINT32_NAN = 0xFFFFFFFF # SMA uses this value to represent NaN
SMA_UINT_64_NAN = 0xFFFFFFFFFFFFFFFF # SMA uses this value to represent NaN

def __init__(self,
device_id: int,
Expand All @@ -36,7 +37,7 @@ def read(self) -> BatState:
current = self.__tcp_client.read_holding_registers(30843, ModbusDataType.INT_32, unit=unit)/-1000
voltage = self.__tcp_client.read_holding_registers(30851, ModbusDataType.INT_32, unit=unit)/100

if soc == self.SMA_INT32_NAN:
if soc == self.SMA_UINT32_NAN:
# If the storage is empty and nothing is produced on the DC side, the inverter does not supply any values.
soc = 0
power = 0
Expand All @@ -45,6 +46,11 @@ def read(self) -> BatState:
exported = self.__tcp_client.read_holding_registers(31401, ModbusDataType.UINT_64, unit=3)
imported = self.__tcp_client.read_holding_registers(31397, ModbusDataType.UINT_64, unit=3)

if exported == self.SMA_UINT_64_NAN or imported == self.SMA_UINT_64_NAN:
raise ValueError(f'Batterie lieferte nicht plausible Werte. Export: {exported}, Import: {imported}. ',
'Sobald die Batterie geladen/entladen wird sollte sich dieser Wert ändern, ',
'andernfalls kann ein Defekt vorliegen.')

return BatState(
power=power,
soc=soc,
Expand Down
8 changes: 8 additions & 0 deletions packages/modules/devices/sma/sma_sunny_boy/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class SmaSunnyBoyInverter(AbstractInverter):

SMA_INT32_NAN = -0x80000000 # SMA uses this value to represent NaN
SMA_UINT32_NAN = 0xFFFFFFFF # SMA uses this value to represent NaN
SMA_NAN = -0xC000

def __init__(self,
Expand Down Expand Up @@ -68,6 +69,13 @@ def read(self) -> InverterState:
if power_total == self.SMA_INT32_NAN or power_total == self.SMA_NAN:
power_total = 0

if energy == self.SMA_UINT32_NAN:
raise ValueError(
f'Wechselrichter lieferte nicht plausiblen Zählerstand: {energy}. '
'Sobald PV Ertrag vorhanden ist sollte sich dieser Wert ändern, '
'andernfalls kann ein Defekt vorliegen.'
)

inverter_state = InverterState(
power=power_total * -1,
dc_power=dc_power * -1,
Expand Down