Sending On/off commands for switches only when it makes sense

I am having troubles to combine AND and OR statements in a rule. My script works but it sends anOn or an Off command even when it is not necessary. In this case the command wifi ON command is sent even when the wifi is already ON. For whatever reason I struggle to find the right setup and mainly the brackets make me mad. Can anybody please give a suggestion how to do that?

var Timer Timer_Wifi_DG

rule "Wifi timer"
when
	Item zwave_device_414e6662_node10_alarm_motion changed or
	Item zwave_device_414e6662_node7_alarm_motion changed
	
then
	if((zwave_device_414e6662_node10_alarm_motion.state==ON) ||  
		zwave_device_414e6662_node7_alarm_motion.state==ON)	

	{
		if(Timer_Wifi_DG!==null) {
    		Timer_Wifi_DG.cancel
    		Timer_Wifi_DG = null
				    	}
fboxWifi24.sendCommand(ON)
fboxWifi50.sendCommand(ON)

	} 
	else if ((zwave_device_414e6662_node7_alarm_motion.state==OFF) ||  zwave_device_414e6662_node10_alarm_motion.state==OFF) {
	 
		Timer_Wifi_DG = createTimer(now.plusSeconds(5400)) [| 

fboxWifi24.sendCommand(OFF)
fboxWifi50.sendCommand(OFF)

 ]
	}
	
end

Replace with

if (fboxWifi24.state != ON) {
   fboxWifi24.sendCommand(ON)
}

For some reason, I didn’t think you could restrict commands. Great, it makes life easier. Thank you very much.