Help with group-based rule triggering multiple times

Hello, I wrote a flexible rule for my flood sensors that allows me to add additional flood sensors by adding them to a group. The issue that I am seeing is that the rule is triggered twice when one of the group members transitions to the state of OPEN. To the extent it matters, the group currently has two members. The rule is below:
rule “Flood Sensor Notification"
Item gFloodSensor received update
logInfo(“Flood Sensor Rule”, “Received Update”)
if(gFloodSensor.members.filter(s | s.state == OPEN).size > 0) {
logInfo(“Flood Sensor Rule”, “At least one sensor is OPEN, sending pushover notification.”)
var OPENFlood = gFloodSensor.members.filter(x | x.state==OPEN).map[].join(”, ")
pushover(("The following sensor(s) are reporting a flood: " + OPENFlood + “.”), 1)

The group member, cSumpPumpFlood, only transitioned once:

2016-04-16 22:33:10 - cSumpPumpFlood state updated to OPEN
2016-04-16 22:33:15 - cSumpPumpFlood state updated to CLOSED

I want the rule to trigger every time a group member transitions to OPEN. Would changing the trigger to “changed to OPEN” fix the issue? I was concerned that it might result in the rule only triggering for the first group member transitioning to OPEN, but I want follow up notifications if additional group members transition to OPEN while the first member is still OPEN.

You got it :slight_smile:

Luckily, you can use

Item gFloodSensor received update OPEN

as a trigger, too.

Have you look at this post. It seems related…

Thank you. Unfortunately, this treats the group as an AND function, so the rule was only triggered when all members of the group were OPEN, and the rule was still triggered twice.

Thank you for the post. It looks like my desired behavior is not going to occur with a simple change to the trigger setup. First, I tried a reentrant lock and sleep timer, but that didn’t help. I also tried rate-limiting with a DateTime variable, but that didn’t work either. It seems like I’ll need to setup some form of counter based off of the number of group members.

Sure, you have to define the group as follows:

Group:Contact:OR(OPEN, CLOSED)  gFloodSensor     "Open Flood Sensors [(%d)]"               <contact>


Another possibility is to use a JSR223 rule and generate the rule trigger dynamically from the group members. This assumes group members don’t change after the triggers are defined at rule load time.