From 7377eb45441aa005ac383263cdc2a836e1412d1d Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Mon, 3 Feb 2025 22:31:36 +0100 Subject: [PATCH 1/5] hybird inverters: add support for discrete energy counters while power is combined (i.e. SMA) --- packages/modules/common/component_state.py | 5 ++++- packages/modules/common/store/_inverter.py | 5 ++++- packages/modules/devices/sma/sma_sunny_boy/inverter.py | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index b2b27c970d..798de2ae2b 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -109,7 +109,9 @@ def __init__( exported: float, power: float, currents: Optional[List[Optional[float]]] = None, - dc_power: Optional[float] = None + dc_power: Optional[float] = None, + is_discrete_energy_and_combined_power: bool = False # energy counters pv/bat are discrete, power is combined + ): """Args: exported: total energy in Wh @@ -126,6 +128,7 @@ def __init__( self.power = power self.exported = exported self.dc_power = dc_power + self.is_discrete_energy_and_combined_power = is_discrete_energy_and_combined_power @auto_str diff --git a/packages/modules/common/store/_inverter.py b/packages/modules/common/store/_inverter.py index abbae2dfda..75a1dbc664 100644 --- a/packages/modules/common/store/_inverter.py +++ b/packages/modules/common/store/_inverter.py @@ -70,7 +70,10 @@ def fix_hybrid_values(self, state: InverterState) -> InverterState: for bat in hybrid: bat_get = data.data.bat_data[bat].data.get power -= bat_get.power - exported += bat_get.imported - bat_get.exported + + if not state.is_discrete_energy_and_combined_power: + exported += bat_get.imported - bat_get.exported + if state.dc_power is not None: # Manche Systeme werden auch aus dem Netz geladen, um einen Mindest-SoC zu halten. if state.dc_power == 0: diff --git a/packages/modules/devices/sma/sma_sunny_boy/inverter.py b/packages/modules/devices/sma/sma_sunny_boy/inverter.py index 8685fd7410..a8dc0dcc4a 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/inverter.py +++ b/packages/modules/devices/sma/sma_sunny_boy/inverter.py @@ -79,7 +79,8 @@ def read(self) -> InverterState: inverter_state = InverterState( power=power_total * -1, dc_power=dc_power * -1, - exported=energy + exported=energy, + is_discrete_energy_and_combined_power=True ) log.debug("WR {}: {}".format(self.tcp_client.address, inverter_state)) return inverter_state From bac75d10f66cad50bbad5abaa99c4dc3bac5d545 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Thu, 6 Feb 2025 08:18:51 +0100 Subject: [PATCH 2/5] add import to InverterState for hybrid bat AC charging scenarios --- packages/modules/common/component_state.py | 3 +++ packages/modules/common/store/_inverter.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index 798de2ae2b..a7c69fce17 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -108,6 +108,7 @@ def __init__( self, exported: float, power: float, + imported: float = 0, # simulated import counter to properly calculate PV energy when bat is charged from AC currents: Optional[List[Optional[float]]] = None, dc_power: Optional[float] = None, is_discrete_energy_and_combined_power: bool = False # energy counters pv/bat are discrete, power is combined @@ -115,6 +116,7 @@ def __init__( ): """Args: exported: total energy in Wh + imported: total energy in Wh power: actual power in W currents: actual currents for 3 phases in A dc_power: dc power in W @@ -127,6 +129,7 @@ def __init__( self.currents = currents self.power = power self.exported = exported + self.imported = imported self.dc_power = dc_power self.is_discrete_energy_and_combined_power = is_discrete_energy_and_combined_power diff --git a/packages/modules/common/store/_inverter.py b/packages/modules/common/store/_inverter.py index 75a1dbc664..9c47bf5275 100644 --- a/packages/modules/common/store/_inverter.py +++ b/packages/modules/common/store/_inverter.py @@ -60,6 +60,7 @@ def fix_hybrid_values(self, state: InverterState) -> InverterState: children = data.data.counter_all_data.get_entry_of_element(self.delegate.delegate.num)["children"] power = state.power exported = state.exported + imported = state.imported if len(children): hybrid = [] for c in children: @@ -70,9 +71,8 @@ def fix_hybrid_values(self, state: InverterState) -> InverterState: for bat in hybrid: bat_get = data.data.bat_data[bat].data.get power -= bat_get.power - - if not state.is_discrete_energy_and_combined_power: - exported += bat_get.imported - bat_get.exported + + exported += bat_get.imported - bat_get.exported - imported if state.dc_power is not None: # Manche Systeme werden auch aus dem Netz geladen, um einen Mindest-SoC zu halten. From 9e03d1da5a713ac931b68d78494b883f6e24ae51 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Thu, 6 Feb 2025 08:19:28 +0100 Subject: [PATCH 3/5] SMA: add import simcount for hybrid --- packages/modules/devices/sma/sma_sunny_boy/inverter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/modules/devices/sma/sma_sunny_boy/inverter.py b/packages/modules/devices/sma/sma_sunny_boy/inverter.py index a8dc0dcc4a..a9ecb246f9 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/inverter.py +++ b/packages/modules/devices/sma/sma_sunny_boy/inverter.py @@ -12,6 +12,7 @@ from modules.common.store import get_inverter_value_store from modules.devices.sma.sma_sunny_boy.config import SmaSunnyBoyInverterSetup from modules.devices.sma.sma_sunny_boy.inv_version import SmaInverterVersion +from modules.common.simcount import SimCounter log = logging.getLogger(__name__) @@ -30,6 +31,7 @@ def __init__(self, self.tcp_client = tcp_client self.store = get_inverter_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) + self.sim_counter = SimCounter(device_id, self.component_config.id, prefix="Wechselrichter") def update(self) -> None: self.store.set(self.read()) @@ -76,11 +78,13 @@ def read(self) -> InverterState: 'andernfalls kann ein Defekt vorliegen.' ) + imported, not_needed_exported = self.sim_counter.sim_count(power_total * -1) + inverter_state = InverterState( power=power_total * -1, dc_power=dc_power * -1, exported=energy, - is_discrete_energy_and_combined_power=True + imported=imported ) log.debug("WR {}: {}".format(self.tcp_client.address, inverter_state)) return inverter_state From 042859352c8e25bbb08a13b1593ebb0c2f148b82 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Fri, 7 Feb 2025 17:58:35 +0100 Subject: [PATCH 4/5] Revert "hybird inverters: add support for discrete energy counters while power is combined (i.e. SMA)" This reverts commit 7377eb45441aa005ac383263cdc2a836e1412d1d. --- packages/modules/common/component_state.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index a7c69fce17..fbd8e6abd6 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -110,9 +110,7 @@ def __init__( power: float, imported: float = 0, # simulated import counter to properly calculate PV energy when bat is charged from AC currents: Optional[List[Optional[float]]] = None, - dc_power: Optional[float] = None, - is_discrete_energy_and_combined_power: bool = False # energy counters pv/bat are discrete, power is combined - + dc_power: Optional[float] = None ): """Args: exported: total energy in Wh @@ -131,7 +129,6 @@ def __init__( self.exported = exported self.imported = imported self.dc_power = dc_power - self.is_discrete_energy_and_combined_power = is_discrete_energy_and_combined_power @auto_str From 5c202450bcce0804d12e688c09af8984128bb346 Mon Sep 17 00:00:00 2001 From: MartinRinas Date: Fri, 7 Feb 2025 18:07:46 +0100 Subject: [PATCH 5/5] remove unused variable --- packages/modules/devices/sma/sma_sunny_boy/inverter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/sma/sma_sunny_boy/inverter.py b/packages/modules/devices/sma/sma_sunny_boy/inverter.py index a9ecb246f9..7e6596b4c8 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/inverter.py +++ b/packages/modules/devices/sma/sma_sunny_boy/inverter.py @@ -78,7 +78,7 @@ def read(self) -> InverterState: 'andernfalls kann ein Defekt vorliegen.' ) - imported, not_needed_exported = self.sim_counter.sim_count(power_total * -1) + imported, _ = self.sim_counter.sim_count(power_total * -1) inverter_state = InverterState( power=power_total * -1,