JS 2021 Sharing timers between rules UI


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?


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 .

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.

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).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.