[SOLVED] Help with a light timer rule

hi all, im looking for a little help with a light timer rule. im getting an error in the logs and im not sure what’s causing it.

2018-12-16 13:50:02.077 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Motion Timer in the Kitchen': cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.reschedule(org.joda.time.base.AbstractInstant) on null

my rule file is as follows

var Timer KitchenLightsTimer = null
val int timeoutMinutesMorning = 60 // choose an appropriate value
val int timeoutMinutesDay = 60 // choose an appropriate value
val int timeoutMinutesAfternoon = 60 // choose an appropriate value
val int timeoutMinutesEvening = 60 // choose an appropriate value
val int timeoutMinutesNight = 60 // choose an appropriate value
val int timeoutMinutesBed = 5 // choose an appropriate value

rule "Kitchen_Motion_Timer ON"
when
	Item Lounge_Motion  received update ON
then 
 	Kitchen_Motion_Timer.sendCommand(ON)
end


rule "Kitchen_Motion_Timer OFF"
when
	Item Kitchen_Motion_Timer  received update OFF
then 
	sendCommand(Kitchen_Light, "0")
	sendCommand(Kitchen_PendantLightLeft, "82,55,0")
	sendCommand(Kitchen_PendantLightCenter, "82,55,0")
	sendCommand(Kitchen_PendantLightRight, "82,55,0")
	postUpdate(All_Lights, OFF)
end



rule "Motion Timer in the Kitchen"
when
    Item Kitchen_Motion_Timer received update ON
then
    if((KitchenLightsTimer == null) && (vTimeOfDay.state == "MORNING")) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesMorning ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesMorning ))
	sendNotification(“***********, "Kitchen Light Timer Has Been Reset!!")
    }
    if(KitchenLightsTimer == null) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesDay ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesDay ))
	sendNotification(“*********”, "Kitchen Light Timer Has Been Reset!!")
    }
    if(KitchenLightsTimer == null) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesAfternoon ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesAfternoon ))
	sendNotification(“***********”, "Kitchen Light Timer Has Been Reset!!")
    }
    if(KitchenLightsTimer == null) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesEvening ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesEvening ))
	sendNotification(“************”, "Kitchen Light Timer Has Been Reset!!")
    }
    if(KitchenLightsTimer == null) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesNight ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesNight ))
	sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
    if(KitchenLightsTimer == null) {
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesBed ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
        KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesBed ))
	sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
end





rule "Motion Sensor Kitchen Lights"

when
	Item Kitchen_Motion_Timer changed to ON
then
	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (Kitchen_Motion_Timer.state == "MORNING"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (vTimeOfDay.state == "DAY"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (vTimeOfDay.state == "AFTERNOON"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (vTimeOfDay.state == "EVENING"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (vTimeOfDay.state == "NIGHT"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((All_Lights.state == OFF) && (Someones_Home.state == ON) && (vTimeOfDay.state == "BED"))
	{
	sendCommand(Kitchen_PendantLightCenter, "82,55,5")
	postUpdate(All_Lights, ON)
	}
end

any ideas or help would be appreciated, this is my most complicated rule to date!

You have a logical error on this condition:

    if((KitchenLightsTimer == null) && (vTimeOfDay.state == "MORNING")) {

Your KitchenLightsTimer could be null, but because the time of day is not morning, thus the flow goes into the else clause where you reschedules on a null KitchenLightsTimer var.

Don’t you need to use === to compare against null?

Yes you do!

All instances of KitchenLightsTimer == null need to read KitchenLightsTimer === null

thanks guys for the help so far. the lights are now turning on but im not getting a notification to say that the timer has been reset.

this is what I have now.

var Timer KitchenLightsTimer = null
val int timeoutMinutesMorning = 60 // choose an appropriate value
val int timeoutMinutesDay = 60 // choose an appropriate value
val int timeoutMinutesAfternoon = 60 // choose an appropriate value
val int timeoutMinutesEvening = 60 // choose an appropriate value
val int timeoutMinutesNight = 60 // choose an appropriate value
val int timeoutMinutesBed = 5 // choose an appropriate value

rule "Kitchen_Motion_Timer ON"
when
	Item Lounge_Motion  received update ON
then 
 	Kitchen_Motion_Timer.sendCommand(ON)
end


rule "Kitchen_Motion_Timer OFF"
when
	Item Kitchen_Motion_Timer  received update OFF
then 
	sendCommand(Kitchen_Light, "0")
	sendCommand(Kitchen_PendantLightLeft, "82,55,0")
	sendCommand(Kitchen_PendantLightCenter, "82,55,0")
	sendCommand(Kitchen_PendantLightRight, "82,55,0")
	postUpdate(All_Lights, OFF)
end



rule "Motion Timer in the Kitchen"
when
    Item Kitchen_Motion_Timer received update ON
then
    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "MORNING")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesMorning ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "MORNING") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesMorning ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}


    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "DAY")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesDay ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "DAY") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesDay ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}


    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "AFTERNOON")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesAfternoon ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "AFTERNOOON") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesAfternoon ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}


    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "EVENING")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesEvening ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "EVENING") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesEvening ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}


    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "NIGHT")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesNight ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "NIGHT") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesNight ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}


    if((KitchenLightsTimer === null) && (vTimeOfDay.state == "BED")) {
	sendNotification(“**********”, "Kitchen Light Timer Has Been Created!!")
        KitchenLightsTimer = createTimer(now.plusMinutes(timeoutMinutesBed ), [|
            Kitchen_Motion_Timer.sendCommand(OFF)
            KitchenLightsTimer = null
        ])
    }
    else {
    		if(vTimeOfDay.state == "BED") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesBED ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }
}

end





rule "Motion Sensor Kitchen Lights"

when
	Item Kitchen_Motion_Timer received command ON
then
	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "MORNING"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "DAY"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "AFTERNOON"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "EVENING"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "NIGHT"))
	{
	sendCommand(Kitchen_Light, "100")
	sendCommand(Kitchen_PendantLightLeft, "82,55,100")
	sendCommand(Kitchen_PendantLightCenter, "82,55,100")
	sendCommand(Kitchen_PendantLightRight, "82,55,100")
	postUpdate(All_Lights, ON)
	}


	if	((Someones_Home.state == ON) && (vTimeOfDay.state == "BED"))
	{
	sendCommand(Kitchen_PendantLightCenter, "82,55,5")
	postUpdate(All_Lights, ON)
	}
end


Not sure if you are wondering whether the corresponding parts of your rule execute or if you are having an issue with the way notifications are configured. If you are interested in the former, just add loginfo("my rule", "put text of notifications here") statements and you can see in your log-file what is happening.
For the latter, I would suggest to open a new thread.

I don’t think the else part of the rule is triggering. I’ve changed the notification to.

			loginfo("my rule", "Kitchen Light Timer Has Been Reset")

and im not seeing anything in the logs searching for “Kitchen Light Timer Has Been Reset” any ideas?

ok its my stuff up. spot the typo!!

 else {
    		if(vTimeOfDay.state == "AFTERNOOON") {
        		KitchenLightsTimer.reschedule(now.plusMinutes(timeoutMinutesAfternoon ))
			sendNotification(“**********”, "Kitchen Light Timer Has Been Reset!!")
    }

changing AFTERNOOON to AFTERNOON and all is well.

thanks guys for your help.

Great…if you are interested in simplifying your rules (avoiding all the repetitive if clauses for example), this may help

and this one

thanks, I started off with
Design Pattern: Motion Sensor Timer
but I wanted to make it work for the different times of day and the above is the best way that I could think of. if you or anyone else have any ideas or the time to show how too do it more efficiently im really keen too learn.