OH3: mapdb changedSince not working anymore

Since the update to Openhab 3.0 the changedSince command does not seem to work anymore with the mapdb persistance. I used this for items when I simply needed to know if an item has changed in the last minutes. Here is an example:

var boolean hasChanged = SW_Test.changedSince(now.minusMinutes(300), "mapdb")

This command now always returns false. When I use the same command with the rrd4j persistance it works. My item is correctly added to the mapdb persistance file. Also when I call SW_Test.lastUpdate(“mapdb”) I get the correct timestamp when the item has last changed.

Is this an issue in Openhab 3.0 or is this not supported on the mapdb persistance anymore?

This because mapdb stores only the last value and no historic data. From my point of view map db ist only to restore values at startup

That is correct, but for the changedSince command that should be all that is needed. The mapdb also stores the timestamp when the item was last changed, so the command should be able to just compare with this date as it did in OH 2.5. As I said I can also get to this date using the lastUpdate(“mapdb”) command. Or is there another reason why this command should not work anymore with mapdb?

But mapdb is only going to store the one value which is going to be the Item’s current state. You can’t actually tell when the item actually changed with that. For changed since to return true, it needs to look back and see if there item was different at any point between now and the time you pass in. F9r mapdb that will always be false because according to the database the item has been in it’s current state the whole time.

What you are probably after is to see if lastUpdate is before a certain time.

Note, there is no way for changedSince or anything else in the rule to know whether the value stored in mapdb was caused by a change, an update, a command, or just a periodic write.

If this has changed for oh 3, I agree with the change. The behavior in oh 2.5 was incorrect.

Ok I see your point. The changed date is there, but the item could simply be updated to the same state and this is not a change, just an update. I will rewrite my rules to use the rrd4j persistance.

@rlkoshak I’ve just discovered another strange issue with the changedSince command with rrd4j. On some Switch items the command always returns true, even if the value has not changed. This is the command I’m using:

SW_ZWAVE_Living_Humidifier.changedSince(now.minusMinutes(5), "rrd4j")

I’ve also checked the persistence data using the api. This is the rrd4j data for this item for today:

{
  "name": "SW_ZWAVE_Living_Humidifier",
  "datapoints": "49",
  "data": [
    {
      "time": 1611054000000,
      "state": "ON"
    },
    {
      "time": 1611054060000,
      "state": "ON"
    },
    {
      "time": 1611054060000,
      "state": "ON"
    },
    {
      "time": 1611054120000,
      "state": "ON"
    },
    {
      "time": 1611054120000,
      "state": "ON"
    },
    {
      "time": 1611054180000,
      "state": "ON"
    },
    {
      "time": 1611054180000,
      "state": "ON"
    },
    {
      "time": 1611054240000,
      "state": "ON"
    },
    {
      "time": 1611054240000,
      "state": "ON"
    },
    {
      "time": 1611054300000,
      "state": "ON"
    },
    {
      "time": 1611054300000,
      "state": "ON"
    },
    {
      "time": 1611054360000,
      "state": "ON"
    },
    {
      "time": 1611054360000,
      "state": "ON"
    },
    {
      "time": 1611054420000,
      "state": "ON"
    },
    {
      "time": 1611054420000,
      "state": "ON"
    },
    {
      "time": 1611054480000,
      "state": "ON"
    },
    {
      "time": 1611054480000,
      "state": "ON"
    },
    {
      "time": 1611054540000,
      "state": "ON"
    },
    {
      "time": 1611054540000,
      "state": "ON"
    },
    {
      "time": 1611054600000,
      "state": "ON"
    },
    {
      "time": 1611054600000,
      "state": "ON"
    },
    {
      "time": 1611054660000,
      "state": "ON"
    },
    {
      "time": 1611054660000,
      "state": "ON"
    },
    {
      "time": 1611054720000,
      "state": "ON"
    },
    {
      "time": 1611054720000,
      "state": "ON"
    },
    {
      "time": 1611054780000,
      "state": "ON"
    },
    {
      "time": 1611054780000,
      "state": "ON"
    },
    {
      "time": 1611054840000,
      "state": "ON"
    },
    {
      "time": 1611054840000,
      "state": "ON"
    },
    {
      "time": 1611054900000,
      "state": "ON"
    },
    {
      "time": 1611054900000,
      "state": "ON"
    },
    {
      "time": 1611054960000,
      "state": "ON"
    },
    {
      "time": 1611054960000,
      "state": "ON"
    },
    {
      "time": 1611055020000,
      "state": "ON"
    },
    {
      "time": 1611055020000,
      "state": "ON"
    },
    {
      "time": 1611055080000,
      "state": "ON"
    },
    {
      "time": 1611055080000,
      "state": "ON"
    },
    {
      "time": 1611055140000,
      "state": "ON"
    },
    {
      "time": 1611055140000,
      "state": "ON"
    },
    {
      "time": 1611055200000,
      "state": "ON"
    },
    {
      "time": 1611055200000,
      "state": "ON"
    },
    {
      "time": 1611055260000,
      "state": "ON"
    },
    {
      "time": 1611055260000,
      "state": "ON"
    },
    {
      "time": 1611055320000,
      "state": "ON"
    },
    {
      "time": 1611055320000,
      "state": "ON"
    },
    {
      "time": 1611055380000,
      "state": "ON"
    },
    {
      "time": 1611055380000,
      "state": "ON"
    },
    {
      "time": 1611055440000,
      "state": "ON"
    },
    {
      "time": 1611055440000,
      "state": "ON"
    }
  ]
}

The state in the data is always on, but the command always returns true for some reason. Also the lastUpdate date is also always updated every minute. And for some reason the persistence api returns every timestamp multiple times.

Any idea what could be wrong here? I already tried to delete the rrd file, but that didn’t fix the problem.

It might well be a bug, Switch handling capability is new to numeric rrd4j.

Do you have any updates regarding this issue? I had to switch to influxdb to find out when my switch changed the last time, but my Influxdb database runs on a different computer, so it is not as reliable as rrd4j.