it is case sensitive
the state is returned as NULL
(you can see also in your logs)
you can simplify the rule by using only 1 forEach with:
rule "Initialize switch states"
when
System started
then
gLights?.members.forEach[lamp |
logInfo("LAMP", lamp.name + " " + lamp.state.toString)
if (lamp.state != NULL) {
lamp.sendCommand(lamp.state.toString)
}
]
end
it is not as sophisticated as using a filter for the forEach statement but it works
Maybe your filter approach will work if you check for != NULL
Ps: did you have to use if (lamp.state.toString != NULL)
or the if (lamp.state != NULL)
worked? (without the .toString
part)