sendCommand to items which are in two groups

Hello!
i would like to send a command to all items in my groups “Lights” and “First_Floor”. Is this possible?
I’m looking for something like

<groupname>?.members.forEach

can this be done with a simple code?

cheers

Yes,for example like this:

<groupname>.members.forEach(item | { item.sendCommand(OFF) } )   

hmm. this works also with two groups? how to seperate the groupnames?

Yes. :roll_eyes:

<groupname1>.members.forEach(item | { item.sendCommand(OFF) } ) 
<groupname2>.members.forEach(item | { item.sendCommand(OFF) } ) 

i want to send command to items which are linked two BOTH groups, not send 2 different commands to the items of two groups.

Ok. You’re looking for an intersection.

I suggest to create a third group, which contains exactly the intersection.

I create a group for each of my use cases. An item may be a member of as many groups as you like. Just separate all the groups with a comma in the item definition.

i know that, i was just looking for a way to avoid obsolete groups…

I have no idea if or how this is possible.

I also can’t think of any benefit this could bring. Out of interest, could you explain the benefits you want to achieve?

example:
i have a group for lights and a group for each floor.
so i have to create a new group for each floor > floor1_lights, floor2_lights

item:
light_example1 (lights,floor1,floor1_lights) <<< would be great if i had not to insert a new group to every item!

Ok.

I think of it the other way round.

The group definition has to be done exactly once, while the intersection calculation has to be done on every access. I always opt for “once” over “every access”.

Is this what you need?

Group floor1
Group lights

Group floor1_lights (floor1, lights)

Item light1 (floor1_lights)

for nested groups you could use <groupname1>.allMembers.forEach(item | { item.sendCommand(OFF) } )

oooohhhhhhh!
makes sense! thank you very much!