How to 'createTimer' and 'Timer.cancel' when item change state?

Again, thank you.

I need to learn how to decode those error messages. I was looking at the line where the error message was showing.

I’m using the rrd4 persistence with (Does that help me or should I use another persistence?)

Strategies {
	// for rrd charts, we need a cron strategy
	everyDay	: "0 0 0 * * ?"
	everyHour	: "0 0 * * * ?"
	everyMinute : "0 * * * * ?"
}

Items {
	* : strategy = everyChange, restoreOnStartup
}

When reading about rules in general I’ve seen different signs ==, >=, <=, !=, >, <

== This one I know - value has to be what it equals but the others I’m unsure of.

I’ve added you new code and will keep an eye on things :slight_smile:

BR Søren

Comparison:

a == b -> true if a is equal to b (in the meaning of 1=1)
a >= b -> true if a is greater than or equal to b
a <= b -> true if a is less than or equal to b
a != b -> true if a is not equal to b
a > b  -> true if a is greater than b
a < b  -> true if a is less than b

a = b -> set a to the value of b (in difference to the first...)

Thank you, Udo.

That actually makes sense :relaxed:

If you plan on doing any charting you will want to use the everyMinute strategy for those Items. Beyond that rrd4j is a decent choice.

Personally I use a three tiered approach.

  1. Everything gets saved by MapDB and I use MapDB for restore on startup. MapDB is a good choice for this because it only saves the most recent value so it doesn’t grow and can save all data types.

  2. Things I want to chart or reference historic data about get saved to rrd4j using the everyChange and everyMinute strategy. rrd4j is nice because it doesn’t grow beyond a certain point but it can only save numerical data.

  3. Things I want to keep accurate data for a long time or want to analyze or chart using an external charting package I would use MySQL or InfluxDB. I don’t actually have a need for this right now so don’t actually have it set up in my environment.

I assign Items to the different tiers by using Groups.

That little parameter made a hole lot of difference :slight_smile: - Now the charts suddenly looks as I was expecting.

Your three tiered approach sounds like a good solution, I’ll have to look into that.

1 Like

Thanks for the link @rlkoshak :slight_smile:

I’m finding my 30 min notification unreliable. I have a equivalent notification set up in Domoticz so I’m able to check if things are working in each system. I also have a notification setup to notify every time a garage door is opened including taking a snapshot with a 18 secs delay. That works everytime.

This is how things look

Rule:

var Timer garagedoor1Timer = null
var String Message7 =				'Garage | Port 1 har stået åbent i 30 minutter! sent from openHAB'

// This rule sends a telegram notification if garagedoor has been open for 30 min.
rule "Send telegram Notification | Garagedoor 1 open for 30 min."
when
    Item Garage_Port_1_State_Closed changed to CLOSED
then
    if(garagedoor1Timer == null || garagedoor1Timer.hasTerminated) {
    	garagedoor1Timer = createTimer(now.plusMinutes(30), [|
    		garagedoor2Timer = null
    	sendTelegram((TelegramBots), (Message7))
    	])      		
	}
end

rule "Cancel telegram Notification | Garagedoor 1 open for 30 min."
when
    Item Garage_Port_1_State_Closed changed to OPEN
then
     if(garagedoor1Timer != null) garagedoor1Timer.cancel() //Terminate timer if door is closed before the timer ends
end

Item:

Contact Garage_Port_1_State_Closed				"Status: Lukket | Port 1"									<garagedoor>		(Garage) 									{ihc="<0x19f35a"}

I have installed mapdb persistence pr. your advice:

Strategies {
	default = everyChange
}

Items {
	* : strategy = everyChange, restoreOnStartup
}`

Hi
Are anyone able to see any errors in the above post. I’m having issues with this rule. Sometimes it is working (usually when I’m testing) and other times it will not send a notification.

I’m clueless at the moment as to what I should be looking at.

I tried to put logInfo in the rule, and sometimes I got this:

2016-05-26 21:39:46.514 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Notifications.rules'
2016-05-26 21:40:01.006 [ERROR] [org.quartz.core.JobRunShell   ] - Job DEFAULT.2016-05-26T21:40:01.004+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: org.eclipse.xtext.xbase.impl.XClosureImplCustom@6d9197 (explicitSyntax: true) threw an unhandled Exception: 
java.lang.RuntimeException: The name '<unkown>' cannot be resolved to an item or type.
	at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:67) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluateArgumentExpressions(XbaseInterpreter.java:751) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:712) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor213.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:69) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor215.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:28) ~[na:na]
	at com.sun.proxy.$Proxy78.apply(Unknown Source) ~[na:na]
	at org.openhab.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44) ~[na:na]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-all-2.1.7.jar:na]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]
2016-05-26 21:40:01.022 [ERROR] [org.quartz.core.ErrorLogger   ] - Job (DEFAULT.2016-05-26T21:40:01.004+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: org.eclipse.xtext.xbase.impl.XClosureImplCustom@6d9197 (explicitSyntax: true) threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
	at org.quartz.core.JobRunShell.run(JobRunShell.java:224) ~[quartz-all-2.1.7.jar:na]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]
Caused by: java.lang.RuntimeException: The name '<unkown>' cannot be resolved to an item or type.
	at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:67) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluateArgumentExpressions(XbaseInterpreter.java:751) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:712) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor213.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:69) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor210.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor215.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:28) ~[na:na]
	at com.sun.proxy.$Proxy78.apply(Unknown Source) ~[na:na]
	at org.openhab.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44) ~[na:na]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-all-2.1.7.jar:na]
	... 1 common frames omitted
2016-05-26 21:40:02.442 [INFO ] [o.o.m.s.S.                    ] - Timer_null_minutter tilbage
2016-05-26 21:40:08.853 [INFO ] [o.o.m.s.S.                    ] - Timer startet_null_minutter
2016-05-26 21:40:56.901 [INFO ] [o.o.m.s.S.                    ] - Timer_org.openhab.model.script.internal.actions.TimerImpl@3fa960_minutter tilbage
2016-05-26 21:41:47.274 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Notifications.rules'
2016-05-26 21:45:45.954 [ERROR] [org.quartz.core.JobRunShell   ] - Job DEFAULT.2016-05-26T21:45:45.945+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: org.eclipse.xtext.xbase.impl.XClosureImplCustom@e78269 (explicitSyntax: true) threw an unhandled Exception: 
org.eclipse.emf.common.util.WrappedException: org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [JvmVoid:  (eProxyURI: Notifications.rules#xtextLink_::0.2.6.2.0.1.1.0.0.8.7.1.1.0.0::0::/1), <null> <unkown> <XNullLiteralImpl>, null, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@1a13e38, org.eclipse.xtext.util.CancelIndicator$1@bddb36]
	at org.eclipse.xtext.util.Exceptions.throwUncheckedException(Exceptions.java:23) ~[na:na]
	at org.eclipse.xtext.util.PolymorphicDispatcher$DefaultErrorHandler.handle(PolymorphicDispatcher.java:41) ~[na:na]
	at org.eclipse.xtext.util.PolymorphicDispatcher.handleNoSuchMethod(PolymorphicDispatcher.java:304) ~[na:na]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:286) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.assignValue(XbaseInterpreter.java:849) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAssignment(XbaseInterpreter.java:844) ~[na:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_75]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor206.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_75]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_75]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:28) ~[na:na]
	at com.sun.proxy.$Proxy78.apply(Unknown Source) ~[na:na]
	at org.openhab.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44) ~[na:na]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-all-2.1.7.jar:na]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]
Caused by: org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [JvmVoid:  (eProxyURI: Notifications.rules#xtextLink_::0.2.6.2.0.1.1.0.0.8.7.1.1.0.0::0::/1), <null> <unkown> <XNullLiteralImpl>, null, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@1a13e38, org.eclipse.xtext.util.CancelIndicator$1@bddb36]
	... 23 common frames omitted

A quick scan of the code reveals that in you timer code you are setting garagedoor2Timer to null inside your garagedoor1timer which send wrong. I think you want to set garagedoor1timer to null there.

Once again, thank you @rlkoshak

I have been looking and looking at the code, but that I did not notice.

Just for good measure if other people sees this thread.

I wanted to share my experience implementing a timer rule to automatically close my garage doors after a 20 minute wait during specified hours. Thank you for your code as it was invaluable for my novice coding skills. I have two Chamberlain/Liftmaster MyQ garage door openers, I created the doors as Roller Shutter items and I still am using OpenHAB v1.8, so the check for open and closed is slightly different than yours.

I have had one issue with the door openers where they sometimes get into a locked state, rapidly flashing timer button, that keeps the rule from operating the door. These openers flash like this when someone crosses the safety sensor but typically reset after 10 seconds. I will follow up with the manufacturer regarding this issue.

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer

var Timer timer_GD1 = null
var Timer timer_GD2 = null

rule "Close_Garage_Doors_At_Night"
	when
		// Check if door should be closed every 10 minutes between 11pm & 6am
		// CRON "Sec Min Hour DayOMon Mon DayOWeek Year"
		Time cron "0 0/10 0-5,23 * * ?"
	then
		logInfo("MyQ", "Starting Close_Garage_Doors_At_Night Rule")
		var SCGS=SingleCarGarageDoor.state  //check state of garage rollershutter: 0=UP 100=DOWN
		logInfo("MyQ", "Checking if SINGLE car garage should be closed after 11pm.. ["+SCGS+"]")
		if(SingleCarGarageDoor.state == 0) {  //check if door is UP, then start 20Min timer to close
			logInfo("MyQ", "SingleCarGarageDoor is open after hours, leaving open for 20 minutes then closing...")
			timer_GD1 = createTimer(now.plusMinutes(20)) [|   //create a timer to close door after 20Min
				logInfo("MyQ", "SingleCarGarageDoor is being closed...")
				sendCommand(SingleCarGarageDoor, DOWN) //close rollershutter door
				logInfo("MyQ", "SingleCarGarageDoor was closed by rule 11pm-6am...")
                                timer_GD1.cancel  //stop the timer
			        timer_GD1 = null  //reset the timer
			]
		}
		var TCGS=TwoCarGarageDoor.state
		logInfo("MyQ", "Checking if TWO car garage should be closed after 11pm.. ["+TCGS+"]")
		if(TwoCarGarageDoor.state == 0) {
			logInfo("MyQ", "TwoCarGarageDoor is open after hours, leaving open for 20 minutes then closing...")
			timer_GD2 = createTimer(now.plusMinutes(20)) [|
				logInfo("MyQ", "TwoCarGarageDoor is being closed...")
				sendCommand(TwoCarGarageDoor, DOWN) 
				logInfo("MyQ", "TwoCarGarageDoor was closed by rule 11pm-6am...")
                               timer_GD2.cancel  //stop the timer
			       timer_GD2 = null  //reset the timer
			]
		}
end	

Dear all,

I am trying to achieve the same with the following rules, checked the remarks above but cannot find my error.

Aim is to get a notification if the garagedoor has been opened for more than a defined timeframe; if its closed within the timeframe, no notification shall be sent.

Please note, that the seconds are only used for testing, in reality I will change it to minutes.

Can you please advise?

Thanks so much,
db


import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*



var Timer extended_timer
var Timer unusual_timer

var EXTENDED_GARAGE_DOOR_TIME_SECONDS = 10
var UNUSUAL_GARAGE_DOOR_OPENED_SECONDS = 15

var SLEEP_TIME = 10


rule "Garage Door open for extended period of time sends notification"
        when
                Item zwave_device_XXX_node104_sensor_binary changed to ON
        then
                if (zwave_device_XXXnode104_sensor_binary.state == ON) {
                        extended_timer = createTimer(now.plusSeconds(EXTENDED_GARAGE_DOOR_TIME_SECONDS)) [|
                                pushover("Garage door has been open for an extended period of time");
                        ]}
                 else {
                        if(extended_timer!=null) {
                                extended_timer.cancel
                                extended_timer = null
                        }
                }
        end

rule "Garage Door open for unusual period of time closes door and sends notification"
        when
                Item zwave_device_XXX_node104_sensor_binary changed to ON
        then
                if (zwave_device_XXX_node104_sensor_binary.state == ON) {
                        unusual_timer = createTimer(now.plusSeconds(UNUSUAL_GARAGE_DOOR_OPENED_SECONDS)) [|
                                pushover("Garage door has been open for an unusual period of time.  Door has been automaticaly closed");
                        ]
                } else {
                        if(unusual_timer!=null) {
                                unusual_timer.cancel
                                unusual_timer = null
                        }
                }
        end ```

I get the following error:

2017-11-06 22:49:34.857 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘garagedoor.rules’, using it anyway:

The use of wildcard imports is deprecated.

Maybe you could have a look here to have some advice?

Hi sintei,

thanks so much for your remarks. I am a bit struggling with translating this into my “world”; I´m not too familiar with the programming.

Would you possibly be able to give some advise on how to use “my timers”?

Thanks and best regards,
Carl

1 Like

First thing, the [INFO] line in openhab.log: It says ‘The use of wildcard imports is deprecated.’ The meaning is, the first two lines in your rule file are wrong. Luckily you don’t need none of them any more, as they are now built in.

Second, your rule is triggered explicitly by Item zwave_device_XXX_node104_sensor_binary changed to ON
So the rule will never be triggered to stop the timer.
You don’t need two rules either.

rule "Garage Door open for unusual period of time closes door and sends notification"
when
    Item zwave_device_XXX_node104_sensor_binary changed 
then
    if (zwave_device_XXX_node104_sensor_binary.state == ON) {  //Door is open
        if(extended_timer!=null)  //timer already exists, for whatever reason, so cancel it
            extended_timer.cancel
        extended_timer = createTimer(now.plusSeconds(EXTENDED_GARAGE_DOOR_TIME_SECONDS)) [| //start timer for extended message
            pushover("Garage door has been open for an extended period of time")  //message is sent if timer expires
        ]
        if(unusual_timer!=null)  //timer already exists, for whatever reason, so cancel it
            unusual_timer.cancel
        unusual_timer = createTimer(now.plusSeconds(UNUSUAL_GARAGE_DOOR_OPENED_SECONDS)) [| //start timer for unusual period message
            pushover("Garage door has been open for an unusual period of time.  Door has been automaticaly closed")  //message is sent if timer expires
            // closedoor.sendCommand(ON) 
        ]
    }
    else {  //Door is already closed, so cancel both timers
        unusual_timer.cancel
        unusual_timer = null
        extended_timer.cancel
        extended_timer = null
    }
end

Of course the line // closedoor.sendCommand(ON) has to be changed to something meaningful, so that the door is closed automatically.

1 Like

Dear Udo,

thanks for your help - I get the feeling, I´m getting closer to my goal… :slight_smile:

I have modified it accordingly:


var Timer extended_timer
var Timer unusual_timer

var EXTENDED_GARAGE_DOOR_TIME_SECONDS = 10
var UNUSUAL_GARAGE_DOOR_OPENED_SECONDS = 15

var SLEEP_TIME = 10


rule "Garage Door open for unusual period of time closes door and sends notification"
when
    Item zwave_device_XXX_node104_sensor_binary changed 
then
    if (zwave_device_XXX_node104_sensor_binary.state == ON) {  //Door is open
        if(extended_timer!=null)  //timer already exists, for whatever reason, so cancel it
            extended_timer.cancel
        extended_timer = createTimer(now.plusSeconds(EXTENDED_GARAGE_DOOR_TIME_SECONDS)) [| //start timer for extended message
            pushover("Garage door has been open for an extended period of time")  //message is sent if timer expires
        ]
        if(unusual_timer!=null)  //timer already exists, for whatever reason, so cancel it
            unusual_timer.cancel
        unusual_timer = createTimer(now.plusSeconds(UNUSUAL_GARAGE_DOOR_OPENED_SECONDS)) [| //start timer for unusual period message
            pushover("Garage door has been open for an unusual period of time.  Door has been automaticaly closed")  //message is sent if timer expires
            // closedoor.sendCommand(ON) 
        ]
    }
    else {  //Door is already closed, so cancel both timers
        unusual_timer.cancel
        unusual_timer = null
        extended_timer.cancel
        extended_timer = null
    }
end

For whatever reason, I still get the notified after the defined period of time, independantly if the door has been closed or not.

Any other thoughts? I checked various options and “played around” with timers but all of them didn´t work…

Thanks for your help - its a hard time!

Regards,
db

Hi community,

not sure if anyone else has an idea how to solve my issue? Keep on being notified - the rule doesn´t work…

Any advise and tipps are highly appreciated!

Kind regards,
db

Hi,

I think your rule is missing a few if clauses to check door state after the timer expires. Now it just sends a message and nothing else.

/Miika

Hi Miika,

any ideas what is wrong? I have no clue… Tried many options, also the ones mentioned in the forum…

Please help…

Regards,
db