From f7cbab50400c3cd37b0dba6563f60f57f543d6fe Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Fri, 24 Apr 2026 20:09:31 +0200 Subject: [PATCH 1/3] Add bat control for Sunny Island --- .../devices/sma/sma_sunny_island/bat.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/modules/devices/sma/sma_sunny_island/bat.py b/packages/modules/devices/sma/sma_sunny_island/bat.py index 7d866b303d..72b74b26e5 100644 --- a/packages/modules/devices/sma/sma_sunny_island/bat.py +++ b/packages/modules/devices/sma/sma_sunny_island/bat.py @@ -28,7 +28,7 @@ def initialize(self) -> None: self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) self.peak_filter = PeakFilter(ComponentType.BAT, self.component_config.id, self.fault_state) - def read(self) -> BatState: + def update(self) -> None: unit = self.component_config.configuration.modbus_id with self.__tcp_client: @@ -44,9 +44,28 @@ def read(self) -> BatState: imported=imported, exported=exported ) + self.store.set(bat_state) - def update(self) -> None: - self.store.set(self.read()) + def set_power_limit(self, power_limit: Optional[int]) -> None: + unit = self.component_config.configuration.modbus_id + + if power_limit is None: + if self.last_mode is not None: + # Kein Powerlimit gefordert, externe Steuerung war aktiv, externe Steuerung deaktivieren + self.__tcp_client.write_register(40151, 803, data_type=ModbusDataType.UINT_32, unit=unit) + self.__tcp_client.write_register(40149, 0, data_type=ModbusDataType.INT_32, unit=unit) + log.debug("Keine Batteriesteuerung gefordert, deaktiviere externe Steuerung.") + self.last_mode = None + else: + # Powerlimit gefordert, externe Steuerung aktivieren, Limit setzen + self.__tcp_client.write_register(40151, 802, data_type=ModbusDataType.UINT_32, unit=unit) + power_value = int(power_limit) * -1 + self.__tcp_client.write_register(40149, power_value, data_type=ModbusDataType.INT_32, unit=unit) + log.debug("Aktive Batteriesteuerung vorhanden. Setze externe Steuerung. Angeforderte Leistung: {power_value}") + self.last_mode = 'limited' + + def power_limit_controllable(self) -> bool: + return True component_descriptor = ComponentDescriptor(configuration_factory=SmaSunnyIslandBatSetup) From 962f3af146763f15316c5b73f3f91983808487b1 Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Fri, 24 Apr 2026 20:15:42 +0200 Subject: [PATCH 2/3] Update bat.py --- packages/modules/devices/sma/sma_sunny_island/bat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/modules/devices/sma/sma_sunny_island/bat.py b/packages/modules/devices/sma/sma_sunny_island/bat.py index 72b74b26e5..445f9b29da 100644 --- a/packages/modules/devices/sma/sma_sunny_island/bat.py +++ b/packages/modules/devices/sma/sma_sunny_island/bat.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -from typing import TypedDict, Any +from typing import TypedDict, Any, Optional +import logging from modules.common import modbus from modules.common.abstract_device import AbstractBat @@ -12,6 +13,8 @@ from modules.common.utils.peak_filter import PeakFilter from modules.common.component_type import ComponentType +log = logging.getLogger(__name__) + class KwargsDict(TypedDict): client: modbus.ModbusTcpClient_ @@ -27,6 +30,7 @@ def initialize(self) -> None: self.store = get_bat_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) self.peak_filter = PeakFilter(ComponentType.BAT, self.component_config.id, self.fault_state) + self.last_mode = 'Undefined' def update(self) -> None: unit = self.component_config.configuration.modbus_id From f3843eb82e0fe5b664a2f8017f08f4fd9e30db7a Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Fri, 24 Apr 2026 20:19:22 +0200 Subject: [PATCH 3/3] Update bat.py --- packages/modules/devices/sma/sma_sunny_island/bat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/modules/devices/sma/sma_sunny_island/bat.py b/packages/modules/devices/sma/sma_sunny_island/bat.py index 445f9b29da..0514c915dd 100644 --- a/packages/modules/devices/sma/sma_sunny_island/bat.py +++ b/packages/modules/devices/sma/sma_sunny_island/bat.py @@ -42,7 +42,7 @@ def update(self) -> None: imported, exported = self.__tcp_client.read_holding_registers(30595, [ModbusDataType.INT_32]*2, unit=unit) imported, exported = self.peak_filter.check_values(power, imported, exported) - return BatState( + bat_state = BatState( power=power, soc=soc, imported=imported, @@ -65,7 +65,7 @@ def set_power_limit(self, power_limit: Optional[int]) -> None: self.__tcp_client.write_register(40151, 802, data_type=ModbusDataType.UINT_32, unit=unit) power_value = int(power_limit) * -1 self.__tcp_client.write_register(40149, power_value, data_type=ModbusDataType.INT_32, unit=unit) - log.debug("Aktive Batteriesteuerung vorhanden. Setze externe Steuerung. Angeforderte Leistung: {power_value}") + log.debug("Aktive Batteriesteuerung vorhanden. Setze externe Steuerung. Leistung: {power_value}") self.last_mode = 'limited' def power_limit_controllable(self) -> bool: