Foreach Could not invoke method: sendCommand on instance: null

Hi,

this is part of my rules file that should switch all lights of a group (group only contains lights) with one action:

gruppeOG?.members.forEach[sw|
logInfo('rules','Schalte an: ' + sw.name)
sendCommand(sw, ON)
]

this is the output:

2017-02-07 17:15:18.188 [INFO ] [org.openhab.model.script.rules] - Schalte an: eg_og_licht_treppe
2017-02-07 17:15:18.194 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Szenen-Verwaltung': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null

I can’t see what I did wrong… Can anybody help? Thanks!

Try:

gruppeOG?.members.forEach[sw|
logInfo('rules','Schalte an: ' + sw.name)
sw.sendCommand(ON)
]

Ref:

@Dim Thank you very much. This works now! Great!

1 Like