pablo
(pablo)
July 10, 2023, 5:02pm
1
Hello
I need to share a timer between 2 rules in JS using cache, but it seems I don’t know how to store and retrieve the timer.
When I use
var doorOpenTimer = cache.shared.get('doorOpenTimer');
it retrieves a integer (1) that seems to be a private handle.
Any examples, pointers on how to share timers between rules?
Thanks
rlkoshak
(Rich Koshak)
July 10, 2023, 5:07pm
2
How did you create and store the timer in the cache in the first place?
Note, that setTimer
and setInterval
are the standard JavaScript functions which only return an integer. https://openhab.org/addons/automation/jsscripting/#timers
What I don’t know is if the “global” clearTimeout
mentioned there is global to all JS Scripting rules or just the one rule.
If you want a standard openHAB Timer, use https://openhab.org/addons/automation/jsscripting/#createtimer which creates a Timer Object .
pablo
(pablo)
July 10, 2023, 5:28pm
3
Thank you, the store in the cache is correct but the ID for the timers seems to bel starting at 1 for each rule so they are private to the rule. The cache stores value not reference so I will try the createTimer to check if the handle is global to all rules or not.
And i have to correct some other rules also.
rlkoshak
(Rich Koshak)
July 10, 2023, 5:46pm
4
I use createTimer
with the cache
all the time. Since it saves the Object you can share Timers between rules (assuming you use the shared cache).
system
(system)
Closed
August 21, 2023, 9:47am
5
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.