updatedSince leads to wrong results

I migrated this topic from google groups

Hi There,

I build this simple rule:

rule "warnIfNoTemperatureWasUpdated"
when
   Time cron "0 /2 * * * ?"
then
    TemperatureKNX?.members.forEach[element1,index1|
     if (!element1.updatedSince(now.minusMinutes(30)) {
        logError("Heating Control","State of KNX Temperature Item: "+element1.name+" has not been updated since: "+element1.lastUpdate)
     }
  ]
end

And I would expect, that a message will be logged if the Item wasn’t updated for at least 30 minutes.

But I get this:

2015-09-03 09:20:00.137 [ERROR] [.o.model.script.Heting Control] - State of KNX Temperature Item: Temperature_OD_Window_Livingroom has not been updated since: Thu Sep 03 09:17:00 CEST 2015

2015-09-03 09:24:01.057 [ERROR] [.o.model.script.Heting Control] - State of KNX Temperature Item: Temperature_OD_Window_Livingroom has not been updated since: Thu Sep 03 09:22:00 CEST 2015

As you can see, the error is written but the last update was 3minutes before.

Has anybody an idea what went wrong?

One Idea at google groups was, that I have setup a different default persistence provider but I can say: No, I only setup one provider (rrd4j) and this is my default.

Bests
PascalTurbo

Maybe I found the solution myself. rrd4j persistence was configured as “everyChange” but some values may not change within 30min.

With rrd4j it is best to save values every minute. Otherwise certain things won’t work, such as charting and historical calls like you have seen.

Rich

But this would cause the thing to absurdity. I need the information how long a sensor wasn’t updated. If I save the value every minute the last update would always be one minute ago.

It may be absurd but it is a limitation of rrd4j. When you don’t save the values every minute rrd4j stops behaving as expected as the data gets older. If you don’t want to save values every minute you may consider using a different persistence engine.

That being said, I think (though haven’t tested it myself) that openHAB is smart enough to know the difference between a value saved because of an update verses one just saved because a minute has passed. In other words, the updatedSince should work as expected even if you save the values every minute though I know it won’t always work if you don’t have an update for extended periods of time if you don’t save the data every minute in rrd4j. This is a side effect of how it thins the data as it gets older.

Because I ran into this problem again (and google showed me my own post on top). I’ve solved this in the past using InfluxDB. I thought, that it should be fixed with OH2, but it isn’t:

gTemperature.members.forEach[ i | logInfo("Develop", "Updated since 30min: '" + i.updatedSince(now.minusMinutes(30),"mapdb") + "'" + " LastUpdated: '" + i.lastUpdate("mapdb") + "'")]

Obviously this isn’t a rrd4j problem. MapDB is able to tell me the correct lastUpdated Information, but it seems to do the wrong calculation.

2018-10-30 14:30:15.108 [INFO ] [lipse.smarthome.model.script.Develop] - Updated since 30min: 'true' LastUpdated: '2018-10-30T12:52:29.054Z'
2018-10-30 14:30:15.110 [INFO ] [lipse.smarthome.model.script.Develop] - Updated since 30min: 'true' LastUpdated: '2018-10-30T12:35:06.327Z'
2018-10-30 14:30:15.112 [INFO ] [lipse.smarthome.model.script.Develop] - Updated since 30min: 'true' LastUpdated: '2018-10-30T14:13:43.985Z'
2018-10-30 14:30:15.115 [INFO ] [lipse.smarthome.model.script.Develop] - Updated since 30min: 'true' LastUpdated: '2018-10-30T13:16:11.488Z'