Errors in the role

In the log I have the following errors. Where he made a mistake in the role?

2016-12-30 13:48:44.975 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Swiatlo garaz2': cannot invoke method public abstract boolean org.openhab.model.script.actions.Timer.cancel() on null

Rules:

import org.openhab.model.script.actions.*
var Timer timer_garaz = null

rule "Swiatlo garaz2"
	when
		Item Swiatlo changed
	then
		if(timer_garaz==null && GarazLight.state==ON){
           	timer_garaz = createTimer(now.plusMinutes(5)) [| 
		sendCommand(buzzer, ON) 
		sendCommand(led1, ON) 
		Thread::sleep(500)
		sendCommand(led1, OFF) 
		sendCommand(buzzer, OFF) 
		Thread::sleep(500)
		sendCommand(GarazLight, OFF)
		timer_garaz = null
		]
		}
		else if(GarazLight.state==OFF)
		{	
		timer_garaz.cancel
		}
end

As stated in the error message, the rule engine tries to call .cancel() of your timer on a null reference. There seems to be a issue with your if-clauses when GarazLight.state is OFF or something like that - you should indent the content of your clauses so that it is more readable. :wink:

You could put a null-check around the .cancel() call you you could simply write:

else if(GarazLight.state==OFF)
{	
	timer_garaz?.cancel
}

(note the ?, which does a null-check before calling cancel). See the Xtend documentation for that.

Greetings,
Wolfgang