From 07b7a7ee9a5b1e7d5ffbb676502431293c69b6f3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 29 May 2023 16:19:55 +0200 Subject: [PATCH] Fix initial ESP32 Energy kWh total time --- RELEASENOTES.md | 1 + tasmota/tasmota_support/support_rtc.ino | 10 ++++------ tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino | 3 +++ tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 12a7eb682..309e280cf 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -131,6 +131,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ### Breaking Changed - Change command ``FileUpload`` index binary data detection from >199 to >299 +- Matter relay number starts at 1 instead of 0 to match Tasmota numbering ### Changed - AdafruitFingerprint library from v2.0.4 to v2.1.0 diff --git a/tasmota/tasmota_support/support_rtc.ino b/tasmota/tasmota_support/support_rtc.ino index 84f775a98..ff93c14d6 100644 --- a/tasmota/tasmota_support/support_rtc.ino +++ b/tasmota/tasmota_support/support_rtc.ino @@ -442,17 +442,15 @@ void RtcSecond(void) { last_sync = Rtc.utc_time; } - Rtc.local_time = Rtc.utc_time; - if (Rtc.local_time > START_VALID_TIME) { // 2016-01-01 + if (Rtc.utc_time > START_VALID_TIME) { // 2016-01-01 Rtc.time_timezone = RtcTimeZoneOffset(Rtc.utc_time); - Rtc.local_time += Rtc.time_timezone; + Rtc.local_time = Rtc.utc_time + Rtc.time_timezone; Rtc.time_timezone /= 60; - if (!Settings->energy_kWhtotal_time) { - Settings->energy_kWhtotal_time = Rtc.local_time; - } if (Settings->bootcount_reset_time < START_VALID_TIME) { Settings->bootcount_reset_time = Rtc.local_time; } + } else { + Rtc.local_time = Rtc.utc_time; } BreakNanoTime(Rtc.local_time, Rtc.nanos, RtcTime); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino index 1ef4fbdd4..ffe80ba22 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino @@ -389,6 +389,9 @@ void Energy200ms(void) { XnrgCall(FUNC_ENERGY_EVERY_SECOND); if (RtcTime.valid) { + if (!Settings->energy_kWhtotal_time) { + Settings->energy_kWhtotal_time = LocalTime(); + } if (!Energy->kWhtoday_offset_init && (RtcTime.day_of_year == Settings->energy_kWhdoy)) { Energy->kWhtoday_offset_init = true; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino index c7d8be494..71a19d25e 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino @@ -309,6 +309,7 @@ void EnergySettingsLoad(bool erase) { // Settings->energy_kWhtoday_ph[i], &Energy->Settings.energy_today_kWh[i], // Settings->energy_kWhyesterday_ph[i], &Energy->Settings.energy_yesterday_kWh[i]); } + Energy->Settings.energy_kWhtotal_time = Settings->energy_kWhtotal_time; // v0102 additions Energy->Settings.gui_display = ENERGY_GUI_DISPLAY_MODE; @@ -609,6 +610,9 @@ void Energy200ms(void) { XnrgCall(FUNC_ENERGY_EVERY_SECOND); if (RtcTime.valid) { + if (!Energy->Settings.energy_kWhtotal_time) { + Energy->Settings.energy_kWhtotal_time = LocalTime(); + } if (!Energy->kWhtoday_offset_init && (RtcTime.day_of_year == Energy->Settings.energy_kWhdoy)) { Energy->kWhtoday_offset_init = true;