First, please use the code fences.
rule “PushButton of group gP”
when
Item gP changed
then
// waiting a second.
Thread::sleep(700)
// Foreach-Switch-is-ON
gP.allMembers.filter( s | s.state == ON).forEach[ i | i.sendCommand(OFF) ]
end
You had a comment in the line, therefore everything after that gets ignored
Do you use VS code to validate you code?