Skip to content

Commit

Permalink
Fix initial ESP32 Energy kWh total time
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed May 29, 2023
1 parent bf29828 commit 07b7a7e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions tasmota/tasmota_support/support_rtc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 07b7a7e

Please sign in to comment.