diff --git a/sonoff/xnrg_03_pzem004t.ino b/sonoff/xnrg_03_pzem004t.ino index d30b769c2..850131762 100644 --- a/sonoff/xnrg_03_pzem004t.ino +++ b/sonoff/xnrg_03_pzem004t.ino @@ -181,8 +181,10 @@ void PzemEvery200ms(void) break; case 4: // Total energy as 99999Wh if (!energy_start || (value < energy_start)) energy_start = value; // Init after restart and hanlde roll-over if any - energy_kWhtoday += (value - energy_start) * 100; - energy_start = value; + if (value != energy_start) { + energy_kWhtoday += (unsigned long)((value - energy_start) * 100); + energy_start = value; + } EnergyUpdateToday(); break; } diff --git a/sonoff/xnrg_05_pzem_ac.ino b/sonoff/xnrg_05_pzem_ac.ino index 6bbabdaa9..7c145384a 100644 --- a/sonoff/xnrg_05_pzem_ac.ino +++ b/sonoff/xnrg_05_pzem_ac.ino @@ -62,9 +62,11 @@ void PzemAcEverySecond(void) energy_power_factor = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00 float energy = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh - if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and hanlde roll-over if any - energy_kWhtoday += (energy - energy_start) * 100; - energy_start = energy; + if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and handle roll-over if any + if (energy != energy_start) { + energy_kWhtoday += (unsigned long)((energy - energy_start) * 100); + energy_start = energy; + } EnergyUpdateToday(); } } diff --git a/sonoff/xnrg_06_pzem_dc.ino b/sonoff/xnrg_06_pzem_dc.ino index 3dcaf8332..c12f401d4 100644 --- a/sonoff/xnrg_06_pzem_dc.ino +++ b/sonoff/xnrg_06_pzem_dc.ino @@ -60,9 +60,11 @@ void PzemDcEverySecond(void) energy_active_power = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0; // 429496729.0 W float energy = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh - if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and hanlde roll-over if any - energy_kWhtoday += (energy - energy_start) * 100; - energy_start = energy; + if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and handle roll-over if any + if (energy != energy_start) { + energy_kWhtoday += (unsigned long)((energy - energy_start) * 100); + energy_start = energy; + } EnergyUpdateToday(); } }