STSC
(STSC)
January 2, 2021, 1:35pm
1
Hello,
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")
timer.reschedule(now.plusSeconds(300))
])
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
garyfree
(Gary Free)
January 2, 2021, 1:44pm
2
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?
Sunny
(Sunny)
January 2, 2021, 1:53pm
3
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"
when
Item XXXXX received update
then
timer = createTimer(now.plusSeconds(300), [ |
logInfo("Timer Rule", "Retrigger 5min")
timer.reschedule(now.plusSeconds(300))
])
end
STSC
(STSC)
January 2, 2021, 5:14pm
4
I could use something like:
Thread::sleep (300000) // 5min
But I think it is i not a good idea?
Marlow
(.)
March 4, 2021, 3:08am
5
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.
/M
rossko57
(Rossko57)
March 4, 2021, 12:06pm
6
A method of using “globals” in the UI environment is shown here using ‘this’
That’s what Timers are for. You haven’t found anything because this is not the best way to handle this in OH. While it’s theoretically possible to create rules from rules, you will have to a pretty deep dive into openHAB internals to figure out how to do it. And then you’ll probably be wanting to write your rules in text rules files in Python or JavaScript. Ultimately you will discover it’s way more trouble than it’s worth and, given that you are not trying to figure out how to do this with Time…
Marlow
(.)
March 6, 2021, 8:24pm
7
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.
/M
tdlr
(Tony De La Rosa)
March 12, 2021, 12:45am
8
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.
Thanks.
Marlow
(.)
March 12, 2021, 1:21am
9
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.
/M
2 Likes
tdlr
(Tony De La Rosa)
March 12, 2021, 3:43am
10
Thank you. It was very useful!
Youns
(Youness)
June 21, 2023, 8:43pm
11
Thank you Marlow, your video helped me alot to better understand the timers and rules.
Regards
Youness