Set last tripped/alarm date, or last action date to an item - best practice?

Yes. item.lastUpdate("mapdb") or you can change your default persistence to be mapdb. Personally I always specify which persistence I want to grab things from.

I changed my rule to this:

rule "Licht State Changed"
when
        Item Licht received update // NOTE: the rule will trigger multiple times per event
then
        Thread::sleep(500) // give persistence time to catch up
        val haveHistory = Licht.members.filter[l|l.lastUpdate("mapdb") != null]
        val mostRecent = haveHistory.sortBy[lastUpdate].last
        if(mostRecent == null) logError("Test Licht", "Failed to find most recent")
        else if(mostRecent.state == ON){
                val dt = gLichtZeit.members.filter[dt|dt.name == mostRecent.name+"_last_switched_on").head
                if(dt == null) logError("Test Licht", "Failed to find " + mostRecent.name+"_last_switched_on")
                else dt.postUpdate(new DateTimeType)
        }
end

I only added mapdb to this line:

val haveHistory = Licht.members.filter[l|l.lastUpdate("mapdb") != null]

But the rule isn´t working anymore. I get no updates on my items anymore.

Can someone tell me, whre i have to add (“mapdb”) in the rule above to use mapdb instead of rrd4j?

I have tested some more places, where i added mapdb, but i always got errors… I think the one position where i added mapdb in the rule above was not enough.

Ate you sure MapDB is working? I’d you change it to rrd4j in the call to last update does it work?

Yes, MapDB is working.

Since i installed MapDB, after an Openhab restart all my items are filled with the last value. Before all values changed to — or undefined and i had to wait, until the next update from the devices starts.

If i remove (“MapDB”) and add the items back to the rrd4j persistence, it is working again.

If i remove the Items from rrd4j persistence, the old value from MapDB stays forever and a trigger doesn´t change the value.

Maybe i have to add mabdb to the other val also (val mostrecent)? or is the line i wrote it in the only one and it is enough for the rule to work?

Could it be, that the rule is not working the first minutes of starting openhab?

When restarting openhab, i get many many errors from this rule, but after some minutes no more erors in the log and it seems that the rule is working now with mapdb…

Can i make a delay in the rule, so that the rule will be first triggered after a minute or so?

Indeed, the second call to lastUpdate needs to have “mapdb” as well (haveHistory.sortBy[lastUpdate("mapdb")].last)

Thanks, now no more errors on startup of openhab.

sorry for bumping to this old question.

what is the differenz between:

if(door.state == OPEN)
{
gDoorSensorsTime?.members.filter(dt|dt.name == door.name+"_Last_Opened").head.postUpdate(new DateTimeType)
}

if(door.state == OPEN)
{
gDoorSensorsTime.members.filter(dt|dt.name == door.name+"_Last_Opened").head.postUpdate(new DateTimeType)
}

for what is the “?” used to?

solved

Maybe someone can have a look in this thread?

The rule isn´t working anymore, since upgrade to OH2 or 2.1 snapshaot, can´t say the right date.

With OH1.9 it was working like a charm.