From 9f7e1d0cac0699c8913b86e0d0f4eae2071f0fe0 Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Tue, 10 Jun 2025 13:12:56 +0200 Subject: [PATCH 1/3] add different tasmota API --- packages/modules/common/tasmota.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/modules/common/tasmota.py b/packages/modules/common/tasmota.py index 42c99f1bbd..96ec398426 100644 --- a/packages/modules/common/tasmota.py +++ b/packages/modules/common/tasmota.py @@ -28,13 +28,18 @@ def get_CounterState(self) -> CounterState: currents = [0.0, 0.0, 0.0] power_factors = [0.0, 0.0, 0.0] - 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 + 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 + 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, From e8c0c7668cb33c27bf07a8bb3acaabc34d502dfa Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Tue, 10 Jun 2025 15:41:50 +0200 Subject: [PATCH 2/3] add Counterstate --- packages/modules/common/tasmota.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/modules/common/tasmota.py b/packages/modules/common/tasmota.py index 96ec398426..98e3fb3a0b 100644 --- a/packages/modules/common/tasmota.py +++ b/packages/modules/common/tasmota.py @@ -36,20 +36,27 @@ def get_CounterState(self) -> CounterState: 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, - voltages=voltages, - currents=currents, - powers=powers, - power_factors=power_factors - ) + counter_state = CounterState( + imported=imported, + exported=exported, + power=power + ) + log.debug("tasmota.get_CounterState:\nurl=" + url + "\nresponse=" + str(response) + "\nCounterState=" + str(counter_state)) From cfe0f9825937cacd67ab81675f74deb3974af0eb Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Tue, 17 Jun 2025 08:07:00 +0200 Subject: [PATCH 3/3] fix --- packages/modules/common/tasmota.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/common/tasmota.py b/packages/modules/common/tasmota.py index 98e3fb3a0b..2eb6eb78b1 100644 --- a/packages/modules/common/tasmota.py +++ b/packages/modules/common/tasmota.py @@ -28,7 +28,7 @@ def get_CounterState(self) -> CounterState: currents = [0.0, 0.0, 0.0] power_factors = [0.0, 0.0, 0.0] - if ['ENERGY'] in response['StatusSNS']: + if ['ENERGY'] in tuple(response['StatusSNS']): voltages[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Voltage']) powers[self.__phase-1] = float(response['StatusSNS']['ENERGY']['Power']) power = sum(powers)