From 3d2c9945a86992a500d265f35f04b5b9bb07b083 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 12 Feb 2022 16:37:48 +0100 Subject: [PATCH] Fix SSPM energy yesterday when zero --- CHANGELOG.md | 1 + tasmota/xdrv_86_esp32_sonoff_spm.ino | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c4aa9e9..8fc7960e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Changed ### Fixed +- SSPM energy yesterday when zero ## [Released] diff --git a/tasmota/xdrv_86_esp32_sonoff_spm.ino b/tasmota/xdrv_86_esp32_sonoff_spm.ino index 6a5d2d086..27773eed1 100644 --- a/tasmota/xdrv_86_esp32_sonoff_spm.ino +++ b/tasmota/xdrv_86_esp32_sonoff_spm.ino @@ -252,6 +252,7 @@ typedef struct { uint16_t expected_bytes; uint8_t module[SSPM_MAX_MODULES][SSPM_MODULE_NAME_SIZE]; + uint8_t history_day[SSPM_MAX_MODULES][4]; uint8_t allow_updates; uint8_t get_energy_relay; uint8_t get_totals; @@ -1136,16 +1137,22 @@ void SSPMHandleReceivedData(void) { energy_total += energy; } } + + uint8_t history_day = SspmBuffer[36]; // Date of last entry + if (0 == Sspm->history_day[module][channel]) { // Initial setting + Sspm->history_day[module][channel] = history_day; + } if ((0 == Sspm->Settings.energy_total[module][channel]) && energy_total) { - Sspm->Settings.energy_yesterday[module][channel] = energy_yesterday; // Inital setting + Sspm->Settings.energy_yesterday[module][channel] = energy_yesterday; // Initial setting Sspm->Settings.energy_total[module][channel] = energy_total; // Initial setting if (Settings->save_data) { TasmotaGlobal.save_data_counter = Settings->save_data +2; // Postpone flash write until all relays are updated } } - // If received daily energy is below last daily energy then update total energy + // If received daily energy date is changed then update total energy // This happens around midnight in normal situations - else if (Sspm->energy_today[module][channel] < last_energy_today) { + else if (Sspm->history_day[module][channel] != history_day) { + Sspm->history_day[module][channel] = history_day; Sspm->Settings.energy_yesterday[module][channel] = last_energy_today; // Daily save Sspm->Settings.energy_total[module][channel] += last_energy_today; // Daily incremental save if (Settings->save_data) {