mirror of https://github.com/arendst/Tasmota.git
[Energy] Fix hardware sensor and restore (#22528)
- Fix handling, when using hardware sensor for EnergytTotal (SO72) - Fix restore values, when device is off over midnight and power supply is unstable while powering on at the next day
This commit is contained in:
parent
bf872defab
commit
16b6d353f4
|
@ -368,8 +368,8 @@ 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];
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -624,8 +624,8 @@ 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];
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue