Script to Email Item State Report

I’m pretty certain you cannot change a var from inside a forEach lambda. You should be seeing errors mentioning something like “cannot use non-final variable”, at least that used to be the case.

There are two approaches you can use here to get past this problem. Use a StringBuilder or use a reduce.

import java.util.StringBuilder

...

    val insideLights = new StringBuilder()
    insideLights.add("*** Inside Lights ***")
    ...
    gIN_Lights.members.forEach[ item | insideLights.add("\n" + item.label + " : " + item.state) ]

or

    val insideLights = "*** Inside Lights***" + gIN_Lights.members.reduce[ msg, item | msg = msg + "\n" + item.label + " : " + item.state ]

There are additional examples of this in Design Pattern: Working with Groups in Rules.