diff --git a/packages/helpermodules/setdata.py b/packages/helpermodules/setdata.py index c66aefdc71..adaaa6062b 100644 --- a/packages/helpermodules/setdata.py +++ b/packages/helpermodules/setdata.py @@ -693,8 +693,7 @@ def process_pv_topic(self, msg: mqtt.MQTTMessage): elif "/get/power" in msg.topic: self._validate_value(msg, float) elif "/get/currents" in msg.topic: - self._validate_value( - msg, float, collection=list) + self._validate_value(msg, float, collection=list) else: self.__unknown_topic(msg) else: @@ -743,6 +742,8 @@ def process_bat_topic(self, msg: mqtt.MQTTMessage): "/get/daily_exported" in msg.topic or "/get/daily_imported" in msg.topic): self._validate_value(msg, float, [(0, float("inf"))]) + elif "/get/currents" in msg.topic: + self._validate_value(msg, float, collection=list) elif "/get/soc" in msg.topic: self._validate_value(msg, float, [(0, 100)]) elif "/get/fault_state" in msg.topic: diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index 97dc9f9cf9..437c02a68a 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -56,6 +56,7 @@ def __init__( exported: float = 0, power: float = 0, soc: float = 0, + currents: Optional[List[float]] = None, ): """Args: imported: total imported energy in Wh @@ -67,6 +68,12 @@ def __init__( self.exported = exported self.power = power self.soc = soc + if _check_none(currents): + currents = [0.0]*3 + else: + if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)): + log.debug("currents sign wrong "+str(currents)) + self.currents = currents @auto_str diff --git a/packages/modules/common/store/_battery.py b/packages/modules/common/store/_battery.py index efb4c59ab3..7ca0e9d1a9 100644 --- a/packages/modules/common/store/_battery.py +++ b/packages/modules/common/store/_battery.py @@ -30,6 +30,7 @@ def set(self, bat_state: BatState): def update(self): try: + pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/currents", self.state.currents, 2) pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/power", self.state.power, 2) pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/soc", self.state.soc, 0) pub_to_broker("openWB/set/bat/"+str(self.num)+"/get/imported", self.state.imported, 2) diff --git a/packages/modules/devices/generic/http/bat.py b/packages/modules/devices/generic/http/bat.py index 7835bc1f94..d42c8060cf 100644 --- a/packages/modules/devices/generic/http/bat.py +++ b/packages/modules/devices/generic/http/bat.py @@ -9,7 +9,7 @@ from modules.common.fault_state import ComponentInfo, FaultState from modules.common.simcount import SimCounter from modules.common.store import get_bat_value_store -from modules.devices.generic.http.api import create_request_function +from modules.devices.generic.http.api import create_request_function, create_request_function_array from modules.devices.generic.http.config import HttpBatSetup @@ -29,6 +29,11 @@ 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.__get_currents = create_request_function_array(self.kwargs['url'], [ + self.component_config.configuration.current_l1_path, + self.component_config.configuration.current_l2_path, + self.component_config.configuration.current_l3_path, + ]) self.__get_power = create_request_function(self.kwargs['url'], self.component_config.configuration.power_path) self.__get_imported = create_request_function( self.kwargs['url'], self.component_config.configuration.imported_path) @@ -44,6 +49,7 @@ def update(self, session: Session) -> None: imported, exported = self.sim_counter.sim_count(power) bat_state = BatState( + currents=self.__get_currents(session), power=power, exported=exported, imported=imported, diff --git a/packages/modules/devices/generic/http/config.py b/packages/modules/devices/generic/http/config.py index f2d6bcfa7d..f40fcee1e9 100644 --- a/packages/modules/devices/generic/http/config.py +++ b/packages/modules/devices/generic/http/config.py @@ -25,9 +25,18 @@ def __init__(self, @auto_str class HttpBatConfiguration: - def __init__(self, power_path=None, soc_path=None, imported_path=None, exported_path=None): + def __init__(self, power_path=None, + soc_path=None, + current_l1_path=None, + current_l2_path=None, + current_l3_path=None, + imported_path=None, + exported_path=None): self.power_path = power_path self.soc_path = soc_path + self.current_l1_path = current_l1_path + self.current_l2_path = current_l2_path + self.current_l3_path = current_l3_path self.imported_path = imported_path self.exported_path = exported_path diff --git a/packages/modules/devices/generic/json/bat.py b/packages/modules/devices/generic/json/bat.py index 191cddc157..4b2cef9477 100644 --- a/packages/modules/devices/generic/json/bat.py +++ b/packages/modules/devices/generic/json/bat.py @@ -29,6 +29,11 @@ def initialize(self) -> None: def update(self, response) -> None: config = self.component_config.configuration + currents = [0] * 3 + for i, c in enumerate(config.jq_currents): + if c is not None: + currents[i] = float(jq.compile(c).input(response).first()) + power = float(jq.compile(config.jq_power).input(response).first()) if config.jq_soc != "": soc = float(jq.compile(config.jq_soc).input(response).first()) @@ -42,6 +47,7 @@ def update(self, response) -> None: imported, exported = self.sim_counter.sim_count(power) bat_state = BatState( + currents=currents, power=power, soc=soc, imported=imported, diff --git a/packages/modules/devices/generic/json/config.py b/packages/modules/devices/generic/json/config.py index fc714bbc84..430dc0ded8 100644 --- a/packages/modules/devices/generic/json/config.py +++ b/packages/modules/devices/generic/json/config.py @@ -24,10 +24,14 @@ def __init__(self, class JsonBatConfiguration: def __init__(self, + jq_current_l1: Optional[str] = None, + jq_current_l2: Optional[str] = None, + jq_current_l3: Optional[str] = None, jq_imported: Optional[str] = None, jq_exported: Optional[str] = None, jq_soc: str = "", jq_power: str = ""): + self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3) self.jq_imported = jq_imported self.jq_exported = jq_exported self.jq_soc = jq_soc diff --git a/packages/modules/devices/generic/mqtt/bat.py b/packages/modules/devices/generic/mqtt/bat.py index f1d83110e5..45e08a83fd 100644 --- a/packages/modules/devices/generic/mqtt/bat.py +++ b/packages/modules/devices/generic/mqtt/bat.py @@ -26,6 +26,7 @@ def initialize(self) -> None: self.store = get_bat_value_store(self.component_config.id) def update(self, received_topics: Dict) -> None: + currents = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/currents") power = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/power") soc = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/soc") if (received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/imported") and @@ -36,6 +37,7 @@ def update(self, received_topics: Dict) -> None: imported, exported = self.sim_counter.sim_count(power) bat_state = BatState( + currents=currents, power=power, soc=soc, imported=imported, diff --git a/packages/modules/devices/openwb/openwb_flex/bat.py b/packages/modules/devices/openwb/openwb_flex/bat.py index 78d7dc220b..494af8bf12 100644 --- a/packages/modules/devices/openwb/openwb_flex/bat.py +++ b/packages/modules/devices/openwb/openwb_flex/bat.py @@ -7,6 +7,7 @@ from modules.common.component_type import ComponentDescriptor from modules.common.fault_state import ComponentInfo, FaultState from modules.common.lovato import Lovato +from modules.common.mpm3pm import Mpm3pm from modules.common.sdm import Sdm120 from modules.common.sdm import Sdm630_72 from modules.common.simcount import SimCounter @@ -49,7 +50,16 @@ def update(self): imported = self.__client.get_imported() exported = self.__client.get_exported() + voltages = self.__client.get_voltages() + powers, power = self.__client.get_power() + + if isinstance(self.__client, Mpm3pm): + currents = [powers[i] / voltages[i] for i in range(3)] + else: + currents = self.__client.get_currents() + bat_state = BatState( + currents=currents, imported=imported, exported=exported, power=power