From 08d82d4d3794720e057a18de7f03fb0978265138 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Thu, 19 Dec 2024 18:16:55 +0100 Subject: [PATCH 1/2] set discharge limit on hybrid bat --- .../sma/sma_sunny_boy/bat_smart_energy.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py b/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py index b80e0864d7..57505e992c 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py +++ b/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 from typing import Dict, Union +import logging from dataclass_utils import dataclass_from_dict from modules.common.abstract_device import AbstractBat @@ -10,6 +11,9 @@ from modules.common.simcount import SimCounter from modules.common.store import get_bat_value_store from modules.devices.sma.sma_sunny_boy.config import SmaSunnyBoySmartEnergyBatSetup +from typing import Optional + +log = logging.getLogger(__name__) class SunnyBoySmartEnergyBat(AbstractBat): @@ -52,5 +56,22 @@ def read(self) -> BatState: exported=exported ) + def set_power_limit(self, power_limit: Optional[int]) -> None: + POWER_LIMIT_REGISTER = 40799 + unit = self.component_config.configuration.modbus_id + + if power_limit is None: + power_limit = -1 + log.debug("Kein Entladelimit für den Speicher vorgegeben, Entladung wird durch den Speicher geregelt.") + else: + log.debug(f'Entladelimit {power_limit} W vorgegeben.') + + current_limit = self.__tcp_client.read_holding_registers(POWER_LIMIT_REGISTER, ModbusDataType.INT_32, unit=unit) + + if current_limit == power_limit: + log.debug(f'Aktives Entladelimit {current_limit} W weicht vom Sollwert {power_limit} W ab.') + log.debug(f'Setze neuen Wert {power_limit} in Register {POWER_LIMIT_REGISTER}.') + self.__tcp_client.write_registers(POWER_LIMIT_REGISTER, power_limit, unit=unit) + component_descriptor = ComponentDescriptor(configuration_factory=SmaSunnyBoySmartEnergyBatSetup) From bb52ca5af89c4557c3c2acf4d4126c9e05342da4 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Thu, 19 Dec 2024 18:32:12 +0100 Subject: [PATCH 2/2] typo --- packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py b/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py index 57505e992c..13c7a05029 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py +++ b/packages/modules/devices/sma/sma_sunny_boy/bat_smart_energy.py @@ -68,7 +68,7 @@ def set_power_limit(self, power_limit: Optional[int]) -> None: current_limit = self.__tcp_client.read_holding_registers(POWER_LIMIT_REGISTER, ModbusDataType.INT_32, unit=unit) - if current_limit == power_limit: + if current_limit != power_limit: log.debug(f'Aktives Entladelimit {current_limit} W weicht vom Sollwert {power_limit} W ab.') log.debug(f'Setze neuen Wert {power_limit} in Register {POWER_LIMIT_REGISTER}.') self.__tcp_client.write_registers(POWER_LIMIT_REGISTER, power_limit, unit=unit)