[SOLVED] Timer not executing

  • Issue of the topic: i want to start a timer but its never executing
  • Please post configurations (if applicable):
    • Items configuration related to the issue

Switch testTimer “test timer”

  • Rules code related to the issue

rule “whatever”
when
Item testTimer received command ON
then
logInfo(“rule”, “strart timer trigger”)

var Timer myTimer = createTimer(now.plusSeconds(15), [ |
logInfo(“rules”, “Timer activated”)
])

end

  • If logs where generated please post these here using code fences:

2019-11-23 14:15:03.454 [INFO ] [.eclipse.smarthome.model.script.rule] - strart timer trigger

After the log “start timer trigger” nothing happens anymore.

I tried so many examples i found but i never get the code inside the [ brackets executes.
For all day now im trying but no success except going crazy.

What is strart? Perhaps tou meant start.

The typo obviously won’t fix it.

The scheduler is only able to execute a few timer blocks at once (though it can schedule a great many).
If you’ve been playing a lot, you may have used those up with errors or something.
Reboot and test your rule again.

1 Like

I agree with rossko57.

Here is an example of a working timer used with a motion sensor that may help or at least give some ideas for future rules.:grinning:

var Timer myTimer = null
rule "Motion OFF"
when
    Item Motion changed from OFF
then
    if (myTimer === null) {
        if  (Motion.state == ON) {
            myTimer = createTimer(now.plusSeconds(60), [ |
                if (Motion.state == ON){
                //do stuff
                }
            ])   
        }
    }
end

rule "BACK FROM ON"
when
    Item Motion changed from ON
then
    myTimer.cancel
    myTimer = null
end

Also note the "var Timer myTimer = null at the top of rule. For your case I don’t think you have to move it to the top but you can always give it a try if a reboot doesn’t help.

1 Like

Thanks a lot for the fast ansers. I tried now your code after restart (except im using my switch for testing instead of Motion):

var Timer myTimer = null
rule "Motion OFF"
when
    Item testTimer changed from OFF
then
    if (myTimer === null) {
        if  (testTimer.state == ON) {
            logInfo("rule", "start timer")
            myTimer = createTimer(now.plusSeconds(60), [ |
                if (testTimer.state == ON){
                //do stuff
                logInfo("rule", "timer executed")
                }
            ])   
        }
    }
end

rule "BACK FROM ON"
when
    Item testTimer changed from ON
then
    myTimer.cancel
    myTimer = null
end

Its kinda working but the time delay in the lock seems to be not what i set for the timer:

2019-11-23 15:02:33.545 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command OFF

2019-11-23 15:02:33.554 [vent.ItemStateChangedEvent] - testTimer changed from ON to OFF

2019-11-23 15:02:34.500 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘BACK FROM ON’: cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.cancel() on null

2019-11-23 15:02:56.693 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command ON

2019-11-23 15:02:56.721 [vent.ItemStateChangedEvent] - testTimer changed from OFF to ON

2019-11-23 15:02:56.736 [INFO ] [.eclipse.smarthome.model.script.rule] - start timer

2019-11-23 15:03:45.818 [vent.ItemStateChangedEvent] - date_today changed from 2019-11-23T15:02:45.760+0100 to 2019-11-23T15:03:45.774+0100

2019-11-23 15:04:20.927 [INFO ] [.eclipse.smarthome.model.script.rule] - timer executed

Is this normal?

Nope.

Try this change on the timer cancel.

rule "BACK FROM ON"
when
    Item testTimer changed from ON
then
    myTimer?.cancel
end

myTimer?.cancel solved the error message but still i have an additional delay of about 30 seconds on my 60 seconds timer (also tried another restart just to be sure):

2019-11-23 15:28:55.698 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command OFF

2019-11-23 15:28:55.717 [vent.ItemStateChangedEvent] - testTimer changed from ON to OFF

2019-11-23 15:29:01.169 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command ON

2019-11-23 15:29:01.182 [vent.ItemStateChangedEvent] - testTimer changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2019-11-23 15:29:01.210 [INFO ] [.eclipse.smarthome.model.script.rule] - start timer

==> /var/log/openhab2/events.log <==

2019-11-23 15:29:43.100 [vent.ItemStateChangedEvent] - date_today changed from 2019-11-23T15:28:43.083+0100 to 2019-11-23T15:29:43.083+0100

==> /var/log/openhab2/openhab.log <==

2019-11-23 15:30:33.382 [INFO ] [.eclipse.smarthome.model.script.rule] - timer executed

Change the timer from 60 to something different and see if you have the same 30 sec delay. Also are you running several other timing rules?

I’d guess your system is seriously overloaded. Are you expecting that time Item change at approx 40 secs past the minute, for example? Is that by a cron rule?

From the Karaf console run this command shell:threads --list |grep -i “ruleEngine” and post the output.

You may need to add org.eclipse.smarthome.threadpool:ruleEngine=20 in runtime.cfg if you have system rules that are overloaded.

1 Like

At 30 sec delay i get additional delay of about 13 seconds.
This is the first time Im using a timer.

How can i open Karaf console? never heard about this before, sorry

Have you tried cleaning the cache?

sudo systemctl stop openhab2

sudo openhab-cli clean-cache

sudo reboot

Other than that and not having all the info about your setup and system you may have to tweak the time till you have what you need. After that you need to check the regularly and verify the delay does not change.

1 Like

sudo openhab-cli console

For more on the console see The Console | openHAB

I think cleaning the cache as mentioned above should solve the delay issue especially if you have modified the rule multiple times during testing.

1 Like

Sorry i dont understand the question.
Just have this timer and when i turn my test switch on i expect the log “timer executed” 60 seconds after “start timer”

        logInfo("rule", "start timer")
        myTimer = createTimer(now.plusSeconds(60), [ |
            if (testTimer.state == ON){
            //do stuff
            logInfo("rule", "timer executed")
            }
        ])

In the events.log you showed us there is an Item updating called date_today, I was just curious about what was doing that in case it was a cron triggered rule and could give us more insight into your system.

1 Like

@Franco if you want something to turn off after a certain time you can use the Expire binding. I use this on several items e.g. a light that’s turned on will be turned off after a given time and no rule needed.

Example:

Switch OfficeLight "Office Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff55:power", expire="180m,command=OFF" }

This light will turn off 3 hours after being turned on. Just something to keep in mind for future home automation ideas.:wink:

1 Like

Ah, yes now i understand.

While experementing with my calendar events i configured this item:

DateTime date_today “[%1$td.%1$tm.%1$tY]” { channel=“ntp:ntp:local:dateTime” }

But i dont use it anymore. This item can be a problem because its updating too often?

Ntp once a minute should be no problem.

1 Like

Have you cleaned the cache and rebooted yet? This will help eliminate one possible cause for the delay.

1 Like