Managing Multiple Timers in Javascript OH3

Please use code fences, not quotes, for code. How to use code fences

In answer to your question, use a function generator that you can pass values to.

function waitToChangeOccupanceGenerator(callingTimerId) {
  return function() {
    for(ArrayIndex ...
  }
}
...
ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(DelayPeriod), waitToChangeOcupancy(123));

But, for reference, I’ve a TimerMgr JavaScript library that odes all that management of multiple timers for you. openhab-rules-tools/timer_mgr at main · rkoshak/openhab-rules-tools · GitHub

Or, if you don’t want to rely on an external library, at least use a dict instead of an array to manage the Timers. Then you can just use the Item name as the index instead of needing to loop through the array.

1 Like