From 5cdd9791f4300607ae9a39d6f0e62a07b3ac77d6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 28 Feb 2023 10:17:30 +0100 Subject: [PATCH] Fix invalid apparent and reactive power --- tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino | 6 ++++++ tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino index 408451297..5de2c90af 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino @@ -1189,6 +1189,9 @@ void EnergyShow(bool json) { if (isnan(apparent_power[i])) { apparent_power[i] = Energy->voltage[i] * Energy->current[i]; } + else if (0 == Energy->current[i]) { + apparent_power[i] = 0; + } if (apparent_power[i] < Energy->active_power[i]) { // Should be impossible Energy->active_power[i] = apparent_power[i]; } @@ -1216,6 +1219,9 @@ void EnergyShow(bool json) { reactive_power[i] = (float)(SqrtInt((uint32_t)(power_diff))); } } + else if (0 == Energy->current[i]) { + reactive_power[i] = 0; + } } } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino index ddc7bb3ec..b64571ef5 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino @@ -1419,6 +1419,9 @@ void EnergyShow(bool json) { if (isnan(apparent_power[i])) { apparent_power[i] = Energy->voltage[i] * Energy->current[i]; } + else if (0 == Energy->current[i]) { + apparent_power[i] = 0; + } if (apparent_power[i] < Energy->active_power[i]) { // Should be impossible Energy->active_power[i] = apparent_power[i]; } @@ -1446,6 +1449,9 @@ void EnergyShow(bool json) { reactive_power[i] = (float)(SqrtInt((uint32_t)(power_diff))); } } + else if (0 == Energy->current[i]) { + reactive_power[i] = 0; + } } }