Items that belong to two groups


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?



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:


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.


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:

1 Like