rule "Intruder_alarm"
when
Item gAllAlarmSensors changed from CLOSED to OPEN or
Item gAllAlarmSensors changed from NULL to OPEN
then
Thread::sleep(300)
logInfo( "FILE", "gAllAlarmSensors["+gAllAlarmSensors.lastUpdate("PIRDetectorSalon")+"]")
val sensor = gAllAlarmSensors.members.sortBy[lastUpdate].last
When event appear I got:
2017-10-30 22:38:58.189 [WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id 'PIRDetectorSalon'
2017-10-30 22:38:58.194 [INFO ] [.eclipse.smarthome.model.script.FILE] - gAllAlarmSensors[null]
2017-10-30 22:38:58.244 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Intruder_alarm': null
Because your log statement is all kinds of wrong. What are you trying to log out with gAllAlarmSensors.lastUpdate("PIRDetectorSalon")? It is pretty close to nonsensical.
Your next line is the correct way to work with lastUpdate.
If you ever want to pass a String to lastUpdate, it expects the name of the persistence engine to use. This lets you query for data in your non-default persistence. That is what the error means. You have no persistence engine named “PIRDetectorSalon”.
By mistake I inserted wrong text (it was test only). Proper one:
rule "Intruder_alarm"
when
Item gAllAlarmSensors changed from CLOSED to OPEN or
Item gAllAlarmSensors changed from NULL to OPEN
then
Thread::sleep(300)
logInfo( "FILE", "gAllAlarmSensors["+gAllAlarmSensors+"]")
val sensor = gAllAlarmSensors.members.sortBy[lastUpdate].last
and for this I’ve got null. I think problem is with sortBy[lastUpdate]
All members of gAllAlarmSensors must have a state (i.e. they cannot be NULL) and they all must be persisted by your default persistence or else lastUpdate returns null.
You can filter these problem items out using:
val sensor = gAllAlarmSensors. members.filter[sensor | sensor.lastUpdate != null].sortBy[lastUpdate].last
if(sensor == null) logWarn("FILE", "Something is amiss, no Item has a valid lastUpdate!")