From 95ad400af98a09d01c84be56ebaaf72fa3a9821e Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Thu, 6 Aug 2026 09:13:22 +0200 Subject: [PATCH 1/2] add Mode Optimization --- packages/modules/devices/sonnen/sonnenbatterie/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index 5689b6289f..d50672b2e0 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -136,6 +136,7 @@ class OperatingMode(Enum): MANUAL = "1" SELF_CONSUMPTION = "2" TIME_OF_USE = "10" + OPTIMIZATION = "11" class PowerMeterDirection(Enum): PRODUCTION = "production" From 5aed0a3e016f745ba04b6dd1b0552420756bc03c Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Thu, 10 Sep 2026 15:05:20 +0200 Subject: [PATCH 2/2] check for valid OperatingMode --- .../modules/devices/sonnen/sonnenbatterie/api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index d50672b2e0..d908d6f0f8 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -133,10 +133,12 @@ class JsonApiVersion(Enum): class JsonApi(): class OperatingMode(Enum): + # only define modes we can override savely MANUAL = "1" SELF_CONSUMPTION = "2" + # MODULE_EXTENSION = "6" TIME_OF_USE = "10" - OPTIMIZATION = "11" + # OPTIMIZATION = "11" class PowerMeterDirection(Enum): PRODUCTION = "production" @@ -448,12 +450,18 @@ def set_power_limit(self, power_limit: Optional[int]) -> None: configurations = self.__get_configurations() if "EM_OperatingMode" not in configurations: raise KeyError("The key 'EM_OperatingMode' is missing in the API response.") + try: + self.OperatingMode(configurations["EM_OperatingMode"]) + except ValueError: + raise ValueError("Aktive Speichersteuerung wird in " + f"Betriebsmodus {configurations['EM_OperatingMode']} " + "nicht unterstützt.") if self.default_operating_mode is None: # Store the default operating mode for later restoration self.default_operating_mode = self.OperatingMode(configurations["EM_OperatingMode"]) log.debug(f"default_operating_mode set to: {self.default_operating_mode}") - operating_mode = self.OperatingMode(configurations["EM_OperatingMode"]) + if power_limit is None: # No specific power limit is set, activating default mode to allow the system to optimize energy usage by it # self.