Fixed tariff peaks on wrong date and time (#1159)

* Trying to fix tariff on wrong date. Also some code cleanup

* Fix issue for ex DLMS where accumulated is always included

* Stricter time restrictions when updating history

* Adjustments after testing
This commit is contained in:
Gunnar Skjold
2026-04-09 11:41:58 +02:00
committed by GitHub
parent 6011d3169e
commit 2c96b4d94f
14 changed files with 152 additions and 133 deletions

View File

@@ -1593,6 +1593,7 @@ void handleDataSuccess(AmsData* data) {
time_t dataUpdateTime = now;
if(abs(now - meterTime) < 300) {
// If the meter timestamp is close to our internal clock, use meter timestamp, because that is best for data tracking
dataUpdateTime = meterTime;
}
@@ -1605,14 +1606,14 @@ void handleDataSuccess(AmsData* data) {
debugD_P(PSTR("READY to update (internal clock %02d:%02d:%02d UTC, meter clock: %02d:%02d:%02d, list type %d, est: %d, using clock: %d)"), tm.Hour, tm.Minute, tm.Second, mtm.Hour, mtm.Minute, mtm.Second, data->getListType(), wasCounterEstimated, dataUpdateTime == now);
tmElements_t dtm;
breakTime(dataUpdateTime, dtm);
if(dtm.Minute < 2 && data->getListType() >= 3) {
if(dtm.Minute < 1 && data->getListType() >= 3) {
debugD_P(PSTR("Updating data storage using actual data"));
saveData = ds.update(data, dataUpdateTime);
#if defined(_CLOUDCONNECTOR_H)
if(saveData && cloud != NULL) cloud->forceUpdate();
#endif
} else if(dtm.Minute == 2) {
} else if(dtm.Minute == 1) {
debugW_P(PSTR("Did not receive necessary data for previous hour, clearing"));
AmsData nullData;
saveData = ds.update(&nullData, dataUpdateTime);
@@ -1627,7 +1628,7 @@ void handleDataSuccess(AmsData* data) {
debugD_P(PSTR("NOT Ready to update (internal clock %02d:%02d:%02d UTC, meter clock: %02d:%02d:%02d, list type %d, est: %d)"), tm.Hour, tm.Minute, tm.Second, mtm.Hour, mtm.Minute, mtm.Second, data->getListType(), wasCounterEstimated);
}
if(ea.update(data)) {
if(ea.update(dataUpdateTime, data->getLastUpdateMillis(), data->getListType(), data->getActiveImportPower(), data->getActiveExportPower())) {
debugI_P(PSTR("Saving energy accounting"));
if(!ea.save()) {
debugW_P(PSTR("Unable to save energy accounting"));