Autoupdate Energy.total with the value reported by hardware (sdm120, etc)

This commit is contained in:
pablozg 2019-09-18 11:42:28 +02:00
parent f8ea106e5d
commit 40657bd256
1 changed files with 7 additions and 0 deletions

View File

@ -190,6 +190,13 @@ void EnergyUpdateTotal(float value, bool kwh)
else if (value != Energy.start_energy) {
Energy.kWhtoday = (unsigned long)((value - Energy.start_energy) * multiplier);
}
if (Energy.total < value){
RtcSettings.energy_kWhtotal = (unsigned long)((value * multiplier) - Energy.kWhtoday_offset - Energy.kWhtoday);
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight();
}
EnergyUpdateToday();
}