Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Energy] Fix hardware sensor and restore #22528

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ void EnergyUpdateTotal(void) {
}
}

if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
if (Settings->flag3.hardware_energy_total && // SetOption72 - Enable hardware energy total counter as reference (#6561)
fabs(Energy->total[i] - Energy->import_active[i]) > 0.01f) { // to avoid continuous updates, check for difference of min 10Wh
// The following calculation allows total usage (Energy->import_active[i]) up to +/-2147483.647 kWh
RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy->import_active[i] * 1000) - ((Energy->kWhtoday_offset[i] + Energy->kWhtoday[i]) / 100));
Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i];
Energy->total[i] = Energy->import_active[i];
Settings->energy_kWhtotal_time = (!Energy->kWhtoday_offset[i]) ? LocalTime() : Midnight();
// AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total updated with hardware value"));
// AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: EnergyTotal updated with hardware value"));
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ void Energy200ms(void) {
}

bool midnight = (LocalTime() == Midnight());
if (midnight || (RtcTime.day_of_year > Settings->energy_kWhdoy)) {
if ((midnight || RtcTime.day_of_year > Settings->energy_kWhdoy) && TasmotaGlobal.uptime > 10) {
Energy->kWhtoday_offset_init = true;
Settings->energy_kWhdoy = RtcTime.day_of_year;

Expand Down
8 changes: 4 additions & 4 deletions tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,14 @@ void EnergyUpdateTotal(void) {
}
}

if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
if (Settings->flag3.hardware_energy_total && // SetOption72 - Enable hardware energy total counter as reference (#6561)
fabs(Energy->total[i] - Energy->import_active[i]) > 0.01f) { // to avoid continuous updates, check for difference of min 10Wh
// The following calculation allows total usage (Energy->import_active[i]) up to +/-2147483.647 kWh
RtcEnergySettings.energy_total_kWh[i] = Energy->import_active[i] - (Energy->energy_today_offset_kWh[i] + ((float)Energy->kWhtoday[i] / 100000));
Energy->Settings.energy_total_kWh[i] = RtcEnergySettings.energy_total_kWh[i];
Energy->total[i] = Energy->import_active[i];
Energy->Settings.energy_kWhtotal_time = (!Energy->energy_today_offset_kWh[i]) ? LocalTime() : Midnight();
// AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total updated with hardware value"));
// AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: EnergyTotal updated with hardware value"));
}
}

Expand Down Expand Up @@ -663,7 +663,7 @@ void Energy200ms(void) {
}

bool midnight = (LocalTime() == Midnight());
if (midnight || (RtcTime.day_of_year > Energy->Settings.energy_kWhdoy)) {
if ((midnight || RtcTime.day_of_year > Energy->Settings.energy_kWhdoy) && TasmotaGlobal.uptime > 10) {
Energy->kWhtoday_offset_init = true;
Energy->Settings.energy_kWhdoy = RtcTime.day_of_year;

Expand Down