[SOLVED] Alert on device not checking in

OH 3.1.0

For the life of me cannot see what is going on here, I have read numerous examples, and spent way too long messing with it, any pointers gratefully received.

Aim is simple(ish) fire off an alert if a device in a group has not sent in any update in the last X mins, some devices do not change, but send in repeat status, hence working with update.

The issue I am seeing is that despite the logs showing an update has not been received for over the specified length of time (5 mins atm) the logic is still marking the device as seen. (confirmed by log timestamp and output of item.lastupdate in the logs)

I am stumped, the logic seems sane…

Persistence:

 groupCheckIn_MAPDB* : strategy = everyUpdate, restoreOnStartup

Item

Switch sensorLoungeMotionSensor "Lounge Motion Sensor" <motion> (groupCheckIn_MAPDB) {channel="mqtt:topic:mosquitto:lounge:pir"}

Rule:

rule "Check-In Monitoring"

when
  Time cron "0 0/1 * * * ?"   // every 1 minute
then
  groupCheckIn_MAPDB.members.forEach[item |
    if (!item.updatedSince(now.minusMinutes(5),"mapdb")) {
     logInfo("Check-In", "Device not seen " + item.label + " " + item.lastUpdate())
    } else {
     logInfo("Check-In", "Device seen " + item.label + " " + item.lastUpdate())
    }
  ]
end

Log:

2021-06-30 17:36:00.280 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Cave Motion Sensor 2021-06-30T17:18:26+08:00[Asia/Singapore]
2021-06-30 17:36:00.281 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Lounge Motion Sensor 2021-06-30T17:18:37+08:00[Asia/Singapore]
2021-06-30 17:36:00.282 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Side Motion Sensor 2021-06-30T17:02:46+08:00[Asia/Singapore]

That may not be referring to the same database, it goes to the default persistence service. (That’s rrd4j in OH3, unless you’ve changed it.) I’d be specific so you know you’re looking at consistent data.
item.lastUpdate("mapdb")

For a completely different approach, you can use the expire feature to allow each individual Item to set itself UNDEF when updates stop coming, which also takes care of avoiding using stale data. Alerting then just listens for any Groupmember changing to UNDEF. No kludgy cron rules, it’s event-driven.

1 Like

Would be nice if that was the fix, sadly I have mabdp set as default, for completeness I have made the change all the same.

I am aware of the expire feature, I have a good number of sensors and was trying to avoid firing up a large number of expire timers, given the data should be in the db already.

As much as anything else, this should work and I hate to be defeated :slight_smile:

FIW I added extra logging:

when
  Time cron "0 0/1 * * * ?"   // every 1 minute
then
  groupCheckIn_MAPDB.members.forEach[device |
    if (!device.updatedSince(now.minusMinutes(5),"mapdb")) {
     logInfo("Check-In", "Device not seen " + device.label + " " + device.lastUpdate("mapdb") + " " + now.minusMinutes(5) + " " + device.updatedSince(now.minusMinutes(5)))
    } else {
     logInfo("Check-In", "Device seen " + device.label + " " + device.lastUpdate("mapdb") + " " + now.minusMinutes(5) + " " + device.updatedSince(now.minusMinutes(5)))
    }
  ]
end

Logs show:

2021-06-30 19:30:00.953 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Cave Motion Sensor 2021-06-30T19:27:18+08:00[Asia/Singapore] 2021-06-30T19:25:00.953065+08:00[Asia/Singapore] true
2021-06-30 19:30:00.956 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Lounge Motion Sensor 2021-06-30T19:25:59+08:00[Asia/Singapore] 2021-06-30T19:25:00.955736+08:00[Asia/Singapore] true
2021-06-30 19:30:00.959 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Side Motion Sensor 2021-06-30T17:02:46+08:00[Asia/Singapore] 2021-06-30T19:25:00.958506+08:00[Asia/Singapore] true

How on earth is that evaluating as true :man_shrugging:

Oh, I agree it ought to work in principle. I’m not very convinced lastUpdate() provides anything meaningful with mapdb, you certainly seem to be demonstrating that. Not all the persistence services provide all the functions, although we might expect a null return if is not supposed to work.

To eliminate timezone silliness, got any (or can make) an Item entry not updated for a full 24 hours?

moving to rrd4j seems to have solved the problem!

2021-07-01 08:29:02.609 [INFO ] [g.openhab.core.model.script.Check-In] - Device seen Cave Motion Sensor 2021-07-01T08:28:40+08:00[Asia/Singapore] 2021-07-01T08:24:02.598588+08:00[Asia/Singapore] true
2021-07-01 08:29:02.615 [INFO ] [g.openhab.core.model.script.Check-In] - Device not seen Lounge Motion Sensor 2021-07-01T08:23+08:00[Asia/Singapore] 2021-07-01T08:24:02.614686+08:00[Asia/Singapore] true
2021-07-01 08:29:02.620 [INFO ] [g.openhab.core.model.script.Check-In] - Device not seen Side Motion Sensor 2021-07-01T08:23+08:00[Asia/Singapore] 2021-07-01T08:24:02.620176+08:00[Asia/Singapore] true

Thanks for the pointers, would have taken me a lot longer to get to this point alone!