Items that belong to two groups

Hi,

Maybe this is expecting too much, but as I mainly program i languages where the “set” idea is important, i tend to want to think in sets.

Ok, so if I have a group gOutsideLights that contain all lights outside. Now, some of them are dimmable, so I store these in a separate group also gDimmable. I can get all members of each group using e.g. gOutsideLights.allMembers and do stuff like gOutsideLight.members.forEach(i | i.sendCommand(ON)).

Ok, but some dimmable lights will then go to full blast, and that is not what I want, so it would be preferable to handle dimmable lights separately in my rule. However, what is then the most elegant way of getting the list of items that are members of both groups?

Thanks!

Fredrik

There are a couple of approaches you can use.

I’m just typing these in so I don’t know if the syntax/method names are exactly right.

Filter out the dimmers:

gOutsideLight.members.filter[l|l instance of DimmerItem].forEach

Filter based on group membership:

gOutsideLight.filter[l|l.groups.contains("gDimmable")]

I’m not sure the method to get the groups is right but it returns a List<String> I think. I have no access to Designer right now.

You can use an if statement in the forEach with instanceof which is what I would do if you want to do something with the dimmers as well.

1 Like

Looks like exactly the thing I need. I will try them out once I get back to my Designer.

Thanks!

I just wanna note that this perfectly matched my case:

I define groups from location perspective and functional perspective. For example:

Switch ZW_Switch_Stairs "Stairs" (gLights,gEntrance) 

Now I can switch on all lights in the entrance by using the following line of code:

gEntrance.members.filter[l|l.groupNames.contains("gLights")].forEach(i|i.sendCommand(ON))
1 Like