Hi everybody.
Here is the problem. I have more than 20 zones that have a unique rule for each. These rules get triggered when the contact changes state (closed/open) and a new time / date in postupdated to a zoneX_update.
rule “Update temps Zone1”
when
Item Zone1 changed from “CLOSED” to “OPEN” or
Item Zone1 changed from “OPEN” to “CLOSED”
then
var String date = sdf.format( new Date() )
Zone1_update.postUpdate(date)
if(Zone1.state == CLOSED) logInfo(“Activite”, “Detection de FEU OUVERT”)
if(Zone1.state == OPEN) logInfo(“Activite”, “Detection de FEU FERMEE”)
end
I would like to have a unique rule that includes all the zones and finds the one that is being updated. Once it’s found, I would like to have $ZONE_update to be postupdated.
Here is the items:
Group:Contact:OR(OPEN,CLOSED) Alarme “Tous les contacts [(%d)]” (All)
Group Persistence “Items persistence”
Contact Zone1 “Feu [MAP(contact.map):%s]” (rdc_corridor,Alarme,Persistence)
String Zone1_update “Feu [%s]” (Persistence)
Here is the persistence file:
Items {
Persistence* : strategy = everyChange, restoreOnStartup
}
I tried to have this rule woirking with others items, and it gives me an java error. I know that the items are different from above but they have the same base groups and persistence…It was easier for me to test.
Thread::sleep(250) // give persistence time to populate lastUpdate
val mostRecent = Interrupteurs?.members.sortBy[lastUpdate].last as SwitchItem
logInfo(“Activite”, "Most recent is " + mostRecent.name)
Error:
2015-10-27 21:49:00.552 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Update time sensors’
java.lang.NullPointerException: null
at org.eclipse.xtext.xbase.lib.ListExtensions$1.compare(ListExtensions.java:84) ~[na:na]
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:356) ~[na:1.8.0]
at java.util.TimSort.sort(TimSort.java:216) ~[na:1.8.0]
at java.util.Arrays.sort(Arrays.java:1435) ~[na:1.8.0]
at java.util.Collections.sort(Collections.java:230) ~[na:1.8.0]
at org.eclipse.xtext.xbase.lib.ListExtensions.sortInplaceBy(ListExtensions.java:87) ~[na:na]
at org.eclipse.xtext.xbase.lib.IterableExtensions.sortBy(IterableExtensions.java:786) ~[na:na]
at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729) ~[na:na]
Thanks for your help
Jose