Need help to find wich item triggered the rule

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

Hi

New update…
I found for the error. One item didn’t had the persistence group, so it was not in the db4o file. For the rest, same, same difficulty :smile:
But I also find that the group item, once it’s triggered from CLOSED to OPEN, all the other items that follow in the group and that are change from CLOSED to OPEN or OPEN to CLOSED, does not trigger the rule. Any patch for that???

Thanks again
Jose

That is expected Group behavior. The Group is a rollup of all the Items that are members, not a proxy for those items.

Unfortunately you will either have to list all of the Zones Items as individual triggers, or make your rule flexible enough to trigger on Item Alarme received update, knowing that the rule will trigger multiple times for every change.

Hi

Thanks for the response.
In your experience, do i have an alternative besides listing all the zones
in the item section? Can i use regex in that case? My items are Zone* where

  • == 1 to 25?

Thanks again
Jose

Afraid not. You have to either use a group or list them all. And since the
group won’t do what you need …

Thanks

I Will do it as items individually into 1 rule

Jose