members.sortBy[lastUpdate].last does not work

I have such rule:

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

My item file
Group:Contact:OR(OPEN, CLOSED) gAllAlarmSensors
Contact PIRDetectorSalon “PIR” (gAllAlarmSensors) { mcp23017="{ address:21, pin:‘B2’, mode:‘DIGITAL_INPUT’}" }

and influxdb persistence:
Items {
* : strategy = everyUpdate
}

What is wrong, why I there is " There is no queryable persistence" message ?

Michal

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]

2017-10-30 23:27:50.766 [INFO ] [.eclipse.smarthome.model.script.FILE] - gAllAlarmSensors[gAllAlarmSensors (Type=GroupItem, BaseType=ContactItem, Members=8, State=OPEN, Label=null, Category=null)]
2017-10-th30 23:27:50.818 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Intruder_alarm': null

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!")
2 Likes

Now it works :slight_smile: Thank you