From 37c2239d619bec47e4cc2cdaab3749a63a2b7a8a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 20 Oct 2019 15:48:14 +0200 Subject: [PATCH] (Try to) fix EnergyReset (again) (Try to) fix EnergyReset (again) (#6561) --- sonoff/xnrg_03_pzem004t.ino | 8 ++++++-- sonoff/xnrg_05_pzem_ac.ino | 9 ++++++--- sonoff/xnrg_06_pzem_dc.ino | 9 ++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sonoff/xnrg_03_pzem004t.ino b/sonoff/xnrg_03_pzem004t.ino index 39b690bceff9..1a541b8f8021 100644 --- a/sonoff/xnrg_03_pzem004t.ino +++ b/sonoff/xnrg_03_pzem004t.ino @@ -30,6 +30,8 @@ #define XNRG_03 3 +const uint32_t PZEM_STABILIZE = 30; // Number of seconds to stabilize configuration + #include TasmotaSerial *PzemSerial = nullptr; @@ -192,7 +194,9 @@ void PzemEvery250ms(void) Pzem.energy += value; if (Pzem.phase == Energy.phase_count -1) { if (Pzem.energy > Pzem.last_energy) { // Handle missed phase - EnergyUpdateTotal(Pzem.energy, false); + if (uptime > PZEM_STABILIZE) { + EnergyUpdateTotal(Pzem.energy, false); + } Pzem.last_energy = Pzem.energy; } Pzem.energy = 0; @@ -228,7 +232,7 @@ void PzemEvery250ms(void) } else { Pzem.send_retry--; - if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (uptime < 30)) { + if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (uptime < PZEM_STABILIZE)) { Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart } } diff --git a/sonoff/xnrg_05_pzem_ac.ino b/sonoff/xnrg_05_pzem_ac.ino index af36d7466755..b438138bd315 100644 --- a/sonoff/xnrg_05_pzem_ac.ino +++ b/sonoff/xnrg_05_pzem_ac.ino @@ -31,7 +31,8 @@ #define XNRG_05 5 -#define PZEM_AC_DEVICE_ADDRESS 0x01 // PZEM default address +const uint8_t PZEM_AC_DEVICE_ADDRESS = 0x01; // PZEM default address +const uint32_t PZEM_AC_STABILIZE = 30; // Number of seconds to stabilize configuration #include TasmotaModbus *PzemAcModbus; @@ -79,7 +80,9 @@ void PzemAcEverySecond(void) PzemAc.energy += (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh if (PzemAc.phase == Energy.phase_count -1) { if (PzemAc.energy > PzemAc.last_energy) { // Handle missed phase - EnergyUpdateTotal(PzemAc.energy, false); + if (uptime > PZEM_AC_STABILIZE) { + EnergyUpdateTotal(PzemAc.energy, false); + } PzemAc.last_energy = PzemAc.energy; } PzemAc.energy = 0; @@ -105,7 +108,7 @@ void PzemAcEverySecond(void) } else { PzemAc.send_retry--; - if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (uptime < 30)) { + if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (uptime < PZEM_AC_STABILIZE)) { Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart } } diff --git a/sonoff/xnrg_06_pzem_dc.ino b/sonoff/xnrg_06_pzem_dc.ino index 5aaf3f29e776..29687967a5ae 100644 --- a/sonoff/xnrg_06_pzem_dc.ino +++ b/sonoff/xnrg_06_pzem_dc.ino @@ -31,7 +31,8 @@ #define XNRG_06 6 -#define PZEM_DC_DEVICE_ADDRESS 0x01 // PZEM default address +const uint8_t PZEM_DC_DEVICE_ADDRESS = 0x01; // PZEM default address +const uint32_t PZEM_DC_STABILIZE = 30; // Number of seconds to stabilize configuration #include TasmotaModbus *PzemDcModbus; @@ -77,7 +78,9 @@ void PzemDcEverySecond(void) PzemDc.energy += (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh if (PzemDc.channel == Energy.phase_count -1) { if (PzemDc.energy > PzemDc.last_energy) { // Handle missed channel - EnergyUpdateTotal(PzemDc.energy, false); + if (uptime > PZEM_DC_STABILIZE) { + EnergyUpdateTotal(PzemDc.energy, false); + } PzemDc.last_energy = PzemDc.energy; } PzemDc.energy = 0; @@ -102,7 +105,7 @@ void PzemDcEverySecond(void) } else { PzemDc.send_retry--; - if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (uptime < 30)) { + if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (uptime < PZEM_DC_STABILIZE)) { Energy.phase_count--; // Decrement channels if no response after retry within 30 seconds after restart } }