From 5677a9c85438e35bd4957cba5f1efb7e2cc7eb09 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Fri, 16 Mar 2018 16:46:58 +0100 Subject: [PATCH] v5.12.0e - Fix S31 power on wrong power report Fix S31 power on wrong power report --- sonoff/xdrv_03_energy.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index eb9249d2b..74a52460f 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -265,6 +265,7 @@ void HlwInit() #define CSE_UREF 100 uint8_t cse_receive_flag = 0; +uint8_t cse_power_valid = 0; long voltage_cycle = 0; long current_cycle = 0; @@ -330,9 +331,15 @@ void CseReceived() if ((header & 0xF2) == 0xF2) { // Power cycle exceeds range energy_power = 0; } else { - energy_power = (float)(Settings.energy_power_calibration * CSE_PREF) / (float)power_cycle; + if (cse_power_valid < 16) { // Skip first incomplete power_cycle + cse_power_valid++; + energy_power = 0; + } else { + energy_power = (float)(Settings.energy_power_calibration * CSE_PREF) / (float)power_cycle; + } } } else { + cse_power_valid = 0; energy_power = 0; // Powered on but no load } if (adjustement & 0x20) { // Current valid