Find group containing an item where the group is nested

You can get a list of all the direct members of a Group using:

MyGroup.members

You can get a list of all the members of the Group including subgroups using:

MyGroup.allMembers

You can get a list of all the Groups an Item is immediately a member of using:

triggeringItem.getGroupNames

But there is no way I know of it get the list of ALL groups up hierarchy the Item may be a member of.

So assuming that triggeirngItem is directly a member of gBlueRoom

if(triggeringItem.getGroupNames.contains("gBlueRoom")) {
    // member of gBlueRoom code
}

However, if triggeringItem is NOT a direct member of gBlueRoom (i.e. it is a member of a Group under gBlueRoom) I know of no way to discover that short of:

if(gBlueRoom.allMembers.findFirst[ i | i.name == triggeringItem.name] !== null) {
    // triggeringItem is a member of gBlueRoom or a subgroup of gBlueRoom
}

The problem is filter returns a List even if there is only one match. There is no members method on a List. You would need to do something like:

gRoom.members.filter[i| i instanceof GroupItem]forEach[g as GroupItem | g.members.filter[device | device.name == triggeringItem.name].forEach[device | sb.append(", " + device.name) ]]