From 3d128f5e20bf444048e0bee53305e5a395b53c4b Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sun, 15 Mar 2026 09:29:40 +0100 Subject: [PATCH] Fix issue for ex DLMS where accumulated is always included --- lib/AmsDataStorage/src/AmsDataStorage.cpp | 17 +++++++---------- src/AmsToMqttBridge.cpp | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/AmsDataStorage/src/AmsDataStorage.cpp b/lib/AmsDataStorage/src/AmsDataStorage.cpp index 9a703d3d..4f922e1e 100644 --- a/lib/AmsDataStorage/src/AmsDataStorage.cpp +++ b/lib/AmsDataStorage/src/AmsDataStorage.cpp @@ -639,25 +639,22 @@ bool AmsDataStorage::isDayHappy(time_t now) { return false; } - if(now < FirmwareVersion::BuildEpoch) return false; - - if(now < day.lastMeterReadTime) { + // If the timestamp is before the firware was built, there is something seriously wrong.. + if(now < FirmwareVersion::BuildEpoch) { return false; } - // There are cases where the meter reports before the hour. The update method will then receive the meter timestamp as reference, thus there will not be 3600s between. - // Leaving a 100s buffer for these cases - if(now-day.lastMeterReadTime > 3500) { + + // If the timestamp is before the last time we updated, there is also something wrong.. + if(now < day.lastMeterReadTime) { return false; } tmElements_t tm, last; breakTime(tz->toLocal(now), tm); breakTime(tz->toLocal(day.lastMeterReadTime), last); - if(tm.Hour != last.Hour) { - return false; - } - return true; + // If the timestamp is at the same day and hour as last update, we are happy + return tm.Day == last.Day && tm.Hour == last.Hour; } bool AmsDataStorage::isMonthHappy(time_t now) { diff --git a/src/AmsToMqttBridge.cpp b/src/AmsToMqttBridge.cpp index 2da481c0..bdddb396 100644 --- a/src/AmsToMqttBridge.cpp +++ b/src/AmsToMqttBridge.cpp @@ -1577,6 +1577,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; }