Contact Rule is executed up to three times

Hi,

i´m using this rule to update my open door contacts:

var String conOpened = “”

rule “Kontakte Erdgeschoss”
when
Item gErdgeschossTuersensoren received update
then
logInfo(“SystemRules”, “Rule ‘Kontakte Erdgeschoss’ started”)
val numOpened = gErdgeschossTuersensoren?.members.filter(contact | contact.state == OPEN).size
gErdgeschossTuersensoren?.allMembers.filter(s | s.state == OPEN).forEach(contact | conOpened = conOpened + contact.name + “, “)
logInfo(“SystemRules:Kontakte Erdgeschoss”,”” + conOpened + " wurde geöffnet")
EGContactsCount.postUpdate(numOpened)
conOpened = “”
logInfo(“SystemRules”, “Rule ‘Kontakte Erdgeschoss’ completed”)
end

Now, when i “open” OR “close” one of the contacts the rule is executed three times and i´m not sure why.
I´ve checked the “events.log” an there is only one event

EGWohnzimmerTuersensor state updated to OPEN

best regards

This is known behavior when listening for updates to group items. events.log must not log group item updates.

Update events can happen any number of times to any item, not just group items. Normally you would listen for “changed” instead of “received update” if you only wanted to know when the item’s state changed.

Hi watou,

thx for the fast reply. So in my case will it work with “changed”? Because i think the item(group) it self is not changed or?

Short answer is I don’t know! But I wonder if you made your Group item a Group:Contact:OR(OPEN, CLOSED) item, if the changed trigger would work? The benefit is that if any door is open, the group item should say OPEN (if you put a “[%s]” placeholder in the label).

To piggy back on @watou’s answer.

You can configure a group so it changes when all the members in the group go from one state (e.g. CLOSED) to when one or more of them change state (e.g. OPEN). But the change in the Group’s state will only happen once. For example, if you have four doors and they are all CLOSED then the Group’s state would be CLOSED. Open Door1 and the Group will change from CLOSED to OPEN. Open Door2 and the Group’s state will not change because it is already open. The Group’s state will not change again until all the doors are CLOSED again.

This is subtle behavior that a lot of newcomers do not catch right away so I thought I’d take the opportunity to elaborate here.

In your particular case I do not think that would work the way you want because you appear to be keeping an Item up to date with the count of OPEN doors in the group. So I think your options in this case are to be aware of and live with the fact that it executes multiple times for every update or change your rule trigger to trigger on each door separately instead of the Group.

Here is an example @guessed wrote for setting his Nest to away if a window is open.

Hi,

ok, so it seem the example is at the moment the best solution. I’ve created a new rule an based on the example an its working.
Thx watou and Rich

best regards