[SOLVED] Test each Member of Group

Hello,
I would like to switch a few lamps if the brightness is blow 70%

Without Group:

if (WZ_Haengelampe_Color.state != 70) 

            {
if (WZ_Haengelampe_Color.state <= 70) 

            {

                WZ_Haengelampe_Color.sendCommand(randHue+","+randSat+","+70) //70% Helligkeit

            }

With Group something like…:

gLampen_WZ_Motion_Einschalten.members.forEach[item|item.sendCommand(randHue+","+randSat+","+70)]

I’m not sure what you question is, but I think you would like to test each member of the group if it is below 70.

Almost right, try this:

gLampen_WZ_Motion_Einschalten.members.forEach[item | 
  if (item.state as Number <70) {
      item.sendCommand(randHue+","+randSat+","+70)
  }]

It works. Thank you

You could also use a filter to get just the Items you are interested in, instead of the conditional statement…

gLampen_WZ_Motion_Einschalten.members.filter(GenericItem item | item.state as Number < 70).forEach[item | 
    item.sendCommand(randHue + "," + randSat + ", 70")
]
1 Like