From 04bd314ea2fb4a3695244a6799fd1e3932da841c Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Mon, 7 Jul 2025 11:20:26 +0200 Subject: [PATCH 1/5] move tasmota to devices; add inverter nd battery --- packages/modules/common/tasmota.py | 73 ------------------- .../modules/devices/tasmota/tasmota/bat.py | 70 ++++++++++++++++++ .../modules/devices/tasmota/tasmota/config.py | 28 +++++++ .../devices/tasmota/tasmota/counter.py | 46 ++++++++++-- .../modules/devices/tasmota/tasmota/device.py | 20 ++++- .../devices/tasmota/tasmota/inverter.py | 66 +++++++++++++++++ 6 files changed, 222 insertions(+), 81 deletions(-) delete mode 100644 packages/modules/common/tasmota.py create mode 100644 packages/modules/devices/tasmota/tasmota/bat.py create mode 100644 packages/modules/devices/tasmota/tasmota/inverter.py diff --git a/packages/modules/common/tasmota.py b/packages/modules/common/tasmota.py deleted file mode 100644 index cf150140a9..0000000000 --- a/packages/modules/common/tasmota.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python3 -import logging - -from modules.common.component_state import CounterState -from modules.common import req - -log = logging.getLogger(__name__) - - -class Tasmota: - def __init__(self, - device_id: int, - ip_address: str, - phase: int) -> None: - self.__device_id = device_id - self.__ip_address = ip_address - if phase: - self.__phase = phase - else: - self.__phase = 1 - - def get_CounterState(self) -> CounterState: - url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" - response = req.get_http_session().get(url, timeout=5).json() - - voltages = [0.0, 0.0, 0.0] - powers = [0.0, 0.0, 0.0] - currents = [0.0, 0.0, 0.0] - power_factors = [0.0, 0.0, 0.0] - - if 'ENERGY' in response['StatusSNS']: - voltages[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Voltage']) - powers[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Power']) - power = sum(powers) - currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']) - power_factors[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Factor']) - imported = float(response['StatusSNS']['ENERGY']['Total']*1000) - exported = 0.0 - - counter_state = CounterState( - imported=imported, - exported=exported, - power=power, - voltages=voltages, - currents=currents, - powers=powers, - power_factors=power_factors - ) - else: - power = float(response['StatusSNS']['Itron']['Power']) - imported = float(response['StatusSNS']['Itron']['E_in']) - exported = float(response['StatusSNS']['Itron']['E_out']) - - counter_state = CounterState( - imported=imported, - exported=exported, - power=power - ) - - log.debug("tasmota.get_CounterState:\nurl=" + url + - "\nresponse=" + str(response) + - "\nCounterState=" + str(counter_state)) - return counter_state - - def set_PowerOn(self) -> str: - url = "http://" + self.__ip_address + "/cm?cmnd=Power%20on" - response = req.get_http_session().get(url, timeout=3).json() - return response['POWER'] - - def setPowerOff(self) -> str: - url = "http://" + self.__ip_address + "/cm?cmnd=Power%20off" - response = req.get_http_session().get(url, timeout=3).json() - return response['POWER'] diff --git a/packages/modules/devices/tasmota/tasmota/bat.py b/packages/modules/devices/tasmota/tasmota/bat.py new file mode 100644 index 0000000000..a1be3cf51c --- /dev/null +++ b/packages/modules/devices/tasmota/tasmota/bat.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +from typing import Any, TypedDict +import logging + +from modules.devices.tasmota.tasmota.config import TasmotaBatSetup +from modules.common.abstract_device import AbstractBat +from modules.common.component_type import ComponentDescriptor +from modules.common.fault_state import ComponentInfo, FaultState +from modules.common.store import get_counter_value_store +from modules.common.simcount import SimCounter +from modules.common import req +from modules.common.component_state import BatState + +log = logging.getLogger(__name__) + + +class KwargsDict(TypedDict): + device_id: int + ip_address: str + phase: int + + +class TasmotaBat(AbstractBat): + def __init__(self, component_config: TasmotaBatSetup, **kwargs: Any) -> None: + self.component_config = component_config + self.kwargs: KwargsDict = kwargs + + def initialize(self) -> None: + self.__device_id: int = self.kwargs['device_id'] + self.__ip_address: str = self.kwargs['ip_address'] + self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") + self.store = get_counter_value_store(self.component_config.id) + self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) + + def update(self): + log.debug("Tasmota bat update: " + self.__ip_address) + + url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" + response = req.get_http_session().get(url, timeout=5).json() + + if 'ENERGY' in response['StatusSNS']: + power = float(response['StatusSNS']['ENERGY']['Power']) + powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] + imported = float(response['StatusSNS']['ENERGY']['Total']*1000) + _, exported = self.sim_counter.sim_count(power) + + bat_state = BatState( + power=power, + powers=powers, + imported=imported, + exported=exported + ) + else: + power = float(response['StatusSNS']['Itron']['Power']) + imported = float(response['StatusSNS']['Itron']['E_in']*1000) + exported = float(response['StatusSNS']['Itron']['E_out']*1000) + + bat_state = BatState( + power=power, + imported=imported, + exported=exported + ) + + log.debug("Tasmota BatState:\nurl=" + url + + "\nresponse=" + str(response) + + "\nBatState=" + str(bat_state)) + self.store.set(bat_state) + + +component_descriptor = ComponentDescriptor(configuration_factory=TasmotaBatSetup) diff --git a/packages/modules/devices/tasmota/tasmota/config.py b/packages/modules/devices/tasmota/tasmota/config.py index bd874e760d..8f6785b83c 100644 --- a/packages/modules/devices/tasmota/tasmota/config.py +++ b/packages/modules/devices/tasmota/tasmota/config.py @@ -35,3 +35,31 @@ def __init__(self, id: int = 0, configuration: TasmotaCounterConfiguration = None) -> None: super().__init__(name, type, id, configuration or TasmotaCounterConfiguration()) + + +class TasmotaInverterConfiguration: + def __init__(self): + pass + + +class TasmotaInverterSetup(ComponentSetup[TasmotaInverterConfiguration]): + def __init__(self, + name: str = "Tasmota Wechselrichterzähler", + type: str = "inverter", + id: int = 0, + configuration: TasmotaInverterConfiguration = None) -> None: + super().__init__(name, type, id, configuration or TasmotaInverterConfiguration()) + + +class TasmotaBatConfiguration: + def __init__(self): + pass + + +class TasmotaBatSetup(ComponentSetup[TasmotaBatConfiguration]): + def __init__(self, + name: str = "Tasmota Speicherzähler", + type: str = "bat", + id: int = 0, + configuration: TasmotaBatConfiguration = None) -> None: + super().__init__(name, type, id, configuration or TasmotaBatConfiguration()) diff --git a/packages/modules/devices/tasmota/tasmota/counter.py b/packages/modules/devices/tasmota/tasmota/counter.py index 01c35f0d90..344b63f0f4 100644 --- a/packages/modules/devices/tasmota/tasmota/counter.py +++ b/packages/modules/devices/tasmota/tasmota/counter.py @@ -4,10 +4,12 @@ from modules.devices.tasmota.tasmota.config import TasmotaCounterSetup from modules.common.abstract_device import AbstractCounter -from modules.common.tasmota import Tasmota from modules.common.component_type import ComponentDescriptor from modules.common.fault_state import ComponentInfo, FaultState from modules.common.store import get_counter_value_store +from modules.common.simcount import SimCounter +from modules.common import req +from modules.common.component_state import CounterState log = logging.getLogger(__name__) @@ -26,14 +28,48 @@ def __init__(self, component_config: TasmotaCounterSetup, **kwargs: Any) -> None def initialize(self) -> None: self.__device_id: int = self.kwargs['device_id'] self.__ip_address: str = self.kwargs['ip_address'] - self.__phase: int = self.kwargs['phase'] + self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug") self.store = get_counter_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) - self.__tasmota = Tasmota(self.__device_id, self.__ip_address, self.__phase) def update(self): - log.debug("tasmota.counter.update: " + self.__ip_address) - counter_state = self.__tasmota.get_CounterState() + log.debug("Tasmota counter update: " + self.__ip_address) + + url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" + response = req.get_http_session().get(url, timeout=5).json() + + if 'ENERGY' in response['StatusSNS']: + power = float(response['StatusSNS']['ENERGY']['Power']) + voltages = [float(response['StatusSNS']['ENERGY']['Voltage']), 0.0, 0.0] + powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] + currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] + power_factors = [float(response['StatusSNS']['ENERGY']['Factor']), 0.0, 0.0] + imported = float(response['StatusSNS']['ENERGY']['Total']*1000) + _, exported = self.sim_counter.sim_count(power) + + counter_state = CounterState( + power=power, + voltages=voltages, + currents=currents, + powers=powers, + power_factors=power_factors, + imported=imported, + exported=exported + ) + else: + power = float(response['StatusSNS']['Itron']['Power']) + imported = float(response['StatusSNS']['Itron']['E_in']*1000) + exported = float(response['StatusSNS']['Itron']['E_out']*1000) + + counter_state = CounterState( + power=power, + imported=imported, + exported=exported + ) + + log.debug("Tasmota CounterState:\nurl=" + url + + "\nresponse=" + str(response) + + "\nCounterState=" + str(counter_state)) self.store.set(counter_state) diff --git a/packages/modules/devices/tasmota/tasmota/device.py b/packages/modules/devices/tasmota/tasmota/device.py index 58d34f98de..8a5604e4f0 100644 --- a/packages/modules/devices/tasmota/tasmota/device.py +++ b/packages/modules/devices/tasmota/tasmota/device.py @@ -2,9 +2,11 @@ import logging from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, IndependentComponentUpdater -from modules.devices.tasmota.tasmota.config import Tasmota, TasmotaCounterSetup +from modules.devices.tasmota.tasmota.config import Tasmota, TasmotaCounterSetup, TasmotaInverterSetup, TasmotaBatSetup from modules.common.abstract_device import DeviceDescriptor from modules.devices.tasmota.tasmota.counter import TasmotaCounter +from modules.devices.tasmota.tasmota.inverter import TasmotaInverter +from modules.devices.tasmota.tasmota.bat import TasmotaBat log = logging.getLogger(__name__) @@ -13,13 +15,25 @@ def create_device(device_config: Tasmota): def create_counter_component(component_config: TasmotaCounterSetup): return TasmotaCounter(component_config, device_id=device_config.id, - ip_address=device_config.configuration.ip_address, - phase=int(device_config.configuration.phase)) + ip_address=device_config.configuration.ip_address) +# phase=int(device_config.configuration.phase) + + def create_inverter_component(component_config: TasmotaInverterSetup): + return TasmotaInverter(component_config, + device_id=device_config.id, + ip_address=device_config.configuration.ip_address) + + def create_bat_component(component_config: TasmotaBatSetup): + return TasmotaBat(component_config, + device_id=device_config.id, + ip_address=device_config.configuration.ip_address) return ConfigurableDevice( device_config=device_config, component_factory=ComponentFactoryByType( counter=create_counter_component, + inverter=create_inverter_component, + inverter=create_bat_component ), component_updater=IndependentComponentUpdater(lambda component: component.update()) ) diff --git a/packages/modules/devices/tasmota/tasmota/inverter.py b/packages/modules/devices/tasmota/tasmota/inverter.py new file mode 100644 index 0000000000..3acc3dec73 --- /dev/null +++ b/packages/modules/devices/tasmota/tasmota/inverter.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +from typing import Any, TypedDict +import logging + +from modules.devices.tasmota.tasmota.config import TasmotaInverterSetup +from modules.common.abstract_device import AbstractInverter +from modules.common.component_type import ComponentDescriptor +from modules.common.fault_state import ComponentInfo, FaultState +from modules.common.store import get_inverter_value_store +from modules.common.simcount import SimCounter +from modules.common import req +from modules.common.component_state import InverterState + +log = logging.getLogger(__name__) + + +class KwargsDict(TypedDict): + device_id: int + ip_address: str + phase: int + + +class TasmotaInverter(AbstractInverter): + def __init__(self, component_config: TasmotaInverterSetup, **kwargs: Any) -> None: + self.component_config = component_config + self.kwargs: KwargsDict = kwargs + + def initialize(self) -> None: + self.__device_id: int = self.kwargs['device_id'] + self.__ip_address: str = self.kwargs['ip_address'] + self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv") + self.store = get_inverter_value_store(self.component_config.id) + self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) + + def update(self): + log.debug("Tasmota inverter update: " + self.__ip_address) + + url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" + response = req.get_http_session().get(url, timeout=5).json() + + if 'ENERGY' in response['StatusSNS']: + power = float(response['StatusSNS']['ENERGY']['Power']) * -1 + powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] + _, exported = self.sim_counter.sim_count(power) + + inverter_state = InverterState( + power=power, + powers=powers, + exported=exported + ) + else: + power = float(response['StatusSNS']['Itron']['Power']) * -1 + exported = float(response['StatusSNS']['Itron']['E_out']*1000) + + inverter_state = InverterState( + power=power, + exported=exported + ) + + log.debug("Tasmota InverterState:\nurl=" + url + + "\nresponse=" + str(response) + + "\nInverterState=" + str(inverter_state)) + self.store.set(inverter_state) + + +component_descriptor = ComponentDescriptor(configuration_factory=TasmotaInverterSetup) From fb2a6dfa6112fc6f6c574338f100d57c2ee719e0 Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Mon, 7 Jul 2025 13:38:34 +0200 Subject: [PATCH 2/5] add component currents --- packages/modules/devices/tasmota/tasmota/bat.py | 8 ++++---- packages/modules/devices/tasmota/tasmota/device.py | 2 +- packages/modules/devices/tasmota/tasmota/inverter.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/modules/devices/tasmota/tasmota/bat.py b/packages/modules/devices/tasmota/tasmota/bat.py index a1be3cf51c..b254b4132b 100644 --- a/packages/modules/devices/tasmota/tasmota/bat.py +++ b/packages/modules/devices/tasmota/tasmota/bat.py @@ -6,7 +6,7 @@ from modules.common.abstract_device import AbstractBat from modules.common.component_type import ComponentDescriptor from modules.common.fault_state import ComponentInfo, FaultState -from modules.common.store import get_counter_value_store +from modules.common.store import get_bat_value_store from modules.common.simcount import SimCounter from modules.common import req from modules.common.component_state import BatState @@ -29,7 +29,7 @@ def initialize(self) -> None: self.__device_id: int = self.kwargs['device_id'] self.__ip_address: str = self.kwargs['ip_address'] self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") - self.store = get_counter_value_store(self.component_config.id) + self.store = get_bat_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): @@ -40,13 +40,13 @@ def update(self): if 'ENERGY' in response['StatusSNS']: power = float(response['StatusSNS']['ENERGY']['Power']) - powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] + currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] imported = float(response['StatusSNS']['ENERGY']['Total']*1000) _, exported = self.sim_counter.sim_count(power) bat_state = BatState( power=power, - powers=powers, + currents=currents, imported=imported, exported=exported ) diff --git a/packages/modules/devices/tasmota/tasmota/device.py b/packages/modules/devices/tasmota/tasmota/device.py index 8a5604e4f0..ddd0acd858 100644 --- a/packages/modules/devices/tasmota/tasmota/device.py +++ b/packages/modules/devices/tasmota/tasmota/device.py @@ -33,7 +33,7 @@ def create_bat_component(component_config: TasmotaBatSetup): component_factory=ComponentFactoryByType( counter=create_counter_component, inverter=create_inverter_component, - inverter=create_bat_component + bat=create_bat_component ), component_updater=IndependentComponentUpdater(lambda component: component.update()) ) diff --git a/packages/modules/devices/tasmota/tasmota/inverter.py b/packages/modules/devices/tasmota/tasmota/inverter.py index 3acc3dec73..0000f51fac 100644 --- a/packages/modules/devices/tasmota/tasmota/inverter.py +++ b/packages/modules/devices/tasmota/tasmota/inverter.py @@ -40,12 +40,12 @@ def update(self): if 'ENERGY' in response['StatusSNS']: power = float(response['StatusSNS']['ENERGY']['Power']) * -1 - powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] + currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] _, exported = self.sim_counter.sim_count(power) inverter_state = InverterState( power=power, - powers=powers, + currents=currents, exported=exported ) else: From 5459e5cabfcab7c994b2abb2f677ff9518c10ffd Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Mon, 7 Jul 2025 13:48:42 +0200 Subject: [PATCH 3/5] update config --- packages/helpermodules/update_config.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 72a92f9461..8c4ce5c542 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -56,7 +56,7 @@ class UpdateConfig: - DATASTORE_VERSION = 85 + DATASTORE_VERSION = 86 valid_topic = [ "^openWB/bat/config/configured$", @@ -2307,3 +2307,15 @@ def cp_upgrade(topic: str, payload) -> Optional[dict]: self._loop_all_received_topics(upgrade) self._loop_all_received_topics(cp_upgrade) self.__update_topic("openWB/system/datastore_version", 85) + + def upgrade_datastore_85(self) -> None: + def upgrade(topic: str, payload) -> None: + if re.search("openWB/system/device/[0-9]+", topic) is not None: + payload = decode_payload(payload) + # remove phase from device tasmota + # phase=int(device_config.configuration.phase) + if payload.get("type") == "tasmota" and "phase" in payload["configuration"]: + payload["configuration"].pop("phase") + Pub().pub(topic, payload) + self._loop_all_received_topics(upgrade) + self.__update_topic("openWB/system/datastore_version", 86) From 2a15de801ea71fad4aa2022086a404ee187bfaff Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Tue, 8 Jul 2025 08:38:21 +0200 Subject: [PATCH 4/5] add phase selection to all tasmota components --- packages/helpermodules/update_config.py | 14 +------------- packages/modules/devices/tasmota/tasmota/bat.py | 6 ++++-- .../modules/devices/tasmota/tasmota/counter.py | 15 ++++++++++----- .../modules/devices/tasmota/tasmota/device.py | 10 ++++++---- .../modules/devices/tasmota/tasmota/inverter.py | 6 ++++-- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 8c4ce5c542..72a92f9461 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -56,7 +56,7 @@ class UpdateConfig: - DATASTORE_VERSION = 86 + DATASTORE_VERSION = 85 valid_topic = [ "^openWB/bat/config/configured$", @@ -2307,15 +2307,3 @@ def cp_upgrade(topic: str, payload) -> Optional[dict]: self._loop_all_received_topics(upgrade) self._loop_all_received_topics(cp_upgrade) self.__update_topic("openWB/system/datastore_version", 85) - - def upgrade_datastore_85(self) -> None: - def upgrade(topic: str, payload) -> None: - if re.search("openWB/system/device/[0-9]+", topic) is not None: - payload = decode_payload(payload) - # remove phase from device tasmota - # phase=int(device_config.configuration.phase) - if payload.get("type") == "tasmota" and "phase" in payload["configuration"]: - payload["configuration"].pop("phase") - Pub().pub(topic, payload) - self._loop_all_received_topics(upgrade) - self.__update_topic("openWB/system/datastore_version", 86) diff --git a/packages/modules/devices/tasmota/tasmota/bat.py b/packages/modules/devices/tasmota/tasmota/bat.py index b254b4132b..948e188440 100644 --- a/packages/modules/devices/tasmota/tasmota/bat.py +++ b/packages/modules/devices/tasmota/tasmota/bat.py @@ -29,18 +29,20 @@ def initialize(self) -> None: self.__device_id: int = self.kwargs['device_id'] self.__ip_address: str = self.kwargs['ip_address'] self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") + self.__phase: int = self.kwargs['phase'] self.store = get_bat_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): log.debug("Tasmota bat update: " + self.__ip_address) - url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() if 'ENERGY' in response['StatusSNS']: + currents = [0.0, 0.0, 0.0] + power = float(response['StatusSNS']['ENERGY']['Power']) - currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] + currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 imported = float(response['StatusSNS']['ENERGY']['Total']*1000) _, exported = self.sim_counter.sim_count(power) diff --git a/packages/modules/devices/tasmota/tasmota/counter.py b/packages/modules/devices/tasmota/tasmota/counter.py index 344b63f0f4..116af5b7c2 100644 --- a/packages/modules/devices/tasmota/tasmota/counter.py +++ b/packages/modules/devices/tasmota/tasmota/counter.py @@ -29,21 +29,26 @@ def initialize(self) -> None: self.__device_id: int = self.kwargs['device_id'] self.__ip_address: str = self.kwargs['ip_address'] self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug") + self.__phase: int = self.kwargs['phase'] self.store = get_counter_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): log.debug("Tasmota counter update: " + self.__ip_address) - url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() if 'ENERGY' in response['StatusSNS']: + voltages = [0.0, 0.0, 0.0] + powers = [0.0, 0.0, 0.0] + currents = [0.0, 0.0, 0.0] + power_factors = [0.0, 0.0, 0.0] + power = float(response['StatusSNS']['ENERGY']['Power']) - voltages = [float(response['StatusSNS']['ENERGY']['Voltage']), 0.0, 0.0] - powers = [float(response['StatusSNS']['ENERGY']['Power']), 0.0, 0.0] - currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] - power_factors = [float(response['StatusSNS']['ENERGY']['Factor']), 0.0, 0.0] + voltages[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Voltage']) + powers[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Power']) + currents[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Current']) + power_factors[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Factor']) imported = float(response['StatusSNS']['ENERGY']['Total']*1000) _, exported = self.sim_counter.sim_count(power) diff --git a/packages/modules/devices/tasmota/tasmota/device.py b/packages/modules/devices/tasmota/tasmota/device.py index ddd0acd858..2a187ab957 100644 --- a/packages/modules/devices/tasmota/tasmota/device.py +++ b/packages/modules/devices/tasmota/tasmota/device.py @@ -15,18 +15,20 @@ def create_device(device_config: Tasmota): def create_counter_component(component_config: TasmotaCounterSetup): return TasmotaCounter(component_config, device_id=device_config.id, - ip_address=device_config.configuration.ip_address) -# phase=int(device_config.configuration.phase) + ip_address=device_config.configuration.ip_address, + phase=int(device_config.configuration.phase)) def create_inverter_component(component_config: TasmotaInverterSetup): return TasmotaInverter(component_config, device_id=device_config.id, - ip_address=device_config.configuration.ip_address) + ip_address=device_config.configuration.ip_address, + phase=int(device_config.configuration.phase)) def create_bat_component(component_config: TasmotaBatSetup): return TasmotaBat(component_config, device_id=device_config.id, - ip_address=device_config.configuration.ip_address) + ip_address=device_config.configuration.ip_address, + phase=int(device_config.configuration.phase)) return ConfigurableDevice( device_config=device_config, diff --git a/packages/modules/devices/tasmota/tasmota/inverter.py b/packages/modules/devices/tasmota/tasmota/inverter.py index 0000f51fac..a5e6c0cf2f 100644 --- a/packages/modules/devices/tasmota/tasmota/inverter.py +++ b/packages/modules/devices/tasmota/tasmota/inverter.py @@ -29,18 +29,20 @@ def initialize(self) -> None: self.__device_id: int = self.kwargs['device_id'] self.__ip_address: str = self.kwargs['ip_address'] self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv") + self.__phase: int = self.kwargs['phase'] self.store = get_inverter_value_store(self.component_config.id) self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): log.debug("Tasmota inverter update: " + self.__ip_address) - url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() if 'ENERGY' in response['StatusSNS']: + currents = [0.0, 0.0, 0.0] + power = float(response['StatusSNS']['ENERGY']['Power']) * -1 - currents = [float(response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0] + currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 _, exported = self.sim_counter.sim_count(power) inverter_state = InverterState( From bb38c9d42af11fdf0e6435dfca1be34e7098adcf Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Wed, 9 Jul 2025 09:25:41 +0200 Subject: [PATCH 5/5] remove unnecessary log messages --- packages/modules/devices/tasmota/tasmota/bat.py | 4 ---- packages/modules/devices/tasmota/tasmota/counter.py | 4 ---- packages/modules/devices/tasmota/tasmota/inverter.py | 4 ---- 3 files changed, 12 deletions(-) diff --git a/packages/modules/devices/tasmota/tasmota/bat.py b/packages/modules/devices/tasmota/tasmota/bat.py index 948e188440..d38f1a4090 100644 --- a/packages/modules/devices/tasmota/tasmota/bat.py +++ b/packages/modules/devices/tasmota/tasmota/bat.py @@ -34,7 +34,6 @@ def initialize(self) -> None: self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): - log.debug("Tasmota bat update: " + self.__ip_address) url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() @@ -63,9 +62,6 @@ def update(self): exported=exported ) - log.debug("Tasmota BatState:\nurl=" + url + - "\nresponse=" + str(response) + - "\nBatState=" + str(bat_state)) self.store.set(bat_state) diff --git a/packages/modules/devices/tasmota/tasmota/counter.py b/packages/modules/devices/tasmota/tasmota/counter.py index 116af5b7c2..b0330725ba 100644 --- a/packages/modules/devices/tasmota/tasmota/counter.py +++ b/packages/modules/devices/tasmota/tasmota/counter.py @@ -34,7 +34,6 @@ def initialize(self) -> None: self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): - log.debug("Tasmota counter update: " + self.__ip_address) url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() @@ -72,9 +71,6 @@ def update(self): exported=exported ) - log.debug("Tasmota CounterState:\nurl=" + url + - "\nresponse=" + str(response) + - "\nCounterState=" + str(counter_state)) self.store.set(counter_state) diff --git a/packages/modules/devices/tasmota/tasmota/inverter.py b/packages/modules/devices/tasmota/tasmota/inverter.py index a5e6c0cf2f..c610831c28 100644 --- a/packages/modules/devices/tasmota/tasmota/inverter.py +++ b/packages/modules/devices/tasmota/tasmota/inverter.py @@ -34,7 +34,6 @@ def initialize(self) -> None: self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) def update(self): - log.debug("Tasmota inverter update: " + self.__ip_address) url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" response = req.get_http_session().get(url, timeout=5).json() @@ -59,9 +58,6 @@ def update(self): exported=exported ) - log.debug("Tasmota InverterState:\nurl=" + url + - "\nresponse=" + str(response) + - "\nInverterState=" + str(inverter_state)) self.store.set(inverter_state)