OH3 UI Timer Rule


I’m trying to create a 5min timer inside a rule using OH3 UI DSL Script.

var Timer timer = null
timer = createTimer(now.plusSeconds(300), [ |
            logInfo("Timer Rule", "Retrigger 5min")

But this gives me following error.
Cannot refer to the non-final variable timer inside a lambda expression; line 4, column 135, length 5

I think it has to do that the variable timer is not global.
How can I do this with a OH3 UI rule? Thanks

I think you are probably right
Cant evaluate timer so returns an error
Global variable sit outside the rule, perhaps this cant be done with OH3 at the moment?

I’d also like to know the correct way to define this in OH 3 via MainUI. However, it will work if you use a file based rule

var Timer timer = null

rule "Timer Rule"
    Item XXXXX received update

 timer = createTimer(now.plusSeconds(300), [ |
            logInfo("Timer Rule", "Retrigger 5min")


I could use something like:

Thread::sleep (300000) // 5min

But I think it is i not a good idea?

Did you get anywhere with this ?

I certainly would be interested in this using the UI. It is such a basic functionality, that should be a default rule.


A method of using “globals” in the UI environment is shown here using ‘this’

Actually, I figured out, that at least for switches and the likes, you don’t need any scripting at all.

MainUI has a timer/counter item, that can be added to for example a switch. If the switch is triggered “ON” again during the countdown, the countdown restarts.


Marlow, can you share how you created the timer item. I have a cell in my overview layout that I wish to implement a timer. I looked at “Configure Cell” and “Edit YAML” but did not find where I could set a timer. That particular cell toggles between “ON” and “OFF” I wish to set a 30 minute timer when that cell is pressed and then switch to another cell.


I can do better. I actually made a video a few days ago, how to implement a motion sensor in OpenHAB, that shows, how I build the timer.



Thank you. It was very useful!

Thank you Marlow, your video helped me alot to better understand the timers and rules.