Reading the group item that changed group's state

So i have several zigbee contacts for my doors and windows all together in a group.When one contact opens ,group opens as well.What i want to do is,when i arm my alarm if a contact is OPEN i want to know who it is and announce it through my google homes.
What i am thinking is:

rule "alarm"
when Item ARM_ALARM changed to ON
then
if (gContacts.state==(OPEN)) {
    **read somehow who is the open contact that caused the group to open**
    say ("the "contact" is open,close it before you arm the alarm")
}
end

any ideas?

Bearing in mind there may be more than one window open when ou try to set the alarm, you’d want to iterate through the Group and filter for OPEN states.
That would produce a list.

an example

yes i understand,i read all the Design Pattern: Working with Groups in Rules but i cant get it…yet.I see that i can filter Open group contacts using
doors_windows_contacts.members.filter[i | i.state==OPEN]
but i cant get how to get the names …perhaps as a string??? so i can announce them.

Once you have your list, you may process that iteratively too.

sorry ,ur link says " Oops! That page doesn’t exist or is private."
many thnx for ur help mate

1 Like

thnx
so translating this example to my rule

rule "test"
when
    Item test received command
then

 val StringBuilder sb = new StringBuilder

     val openWindows = doors_windows_contacts.members.filter(s|s.state==OPEN).size
     if(openWindows > 0){
         doors_windows_contacts.members.filter( x | x.state == OPEN).forEach[ item |
             sb.append("window: " + item.label.toString + "\n")
         ]
         val String msg = sb.toString
         logInfo("status", "There are " + openWindows + " open windows:\n" + msg)
     }
end

i get in the logs

2021-09-18 19:03:37.620 [INFO ] [org.openhab.core.model.script.status] - There are 4 open windows:
window: Open Status
window: Open Status
window: Open Status
window: Open Status

the number 4 is right but it doesnt says which one is it.What am i missing here?

What are the labels of your Items? Would item.name suit you better?

1 Like

yeap thanx mate i got it now