As @JJ_Reynolds links to, use a Map, not a List. You can use the name of the Item related to the Timer as the key.
On JS Scripting, my Announcing the initial release of openhab_rules_tools (installable through openHABian) has a utility called TimerManager which handles the management of multiple timers for you. In a UI rule it would look something like:
var {timerMgr} = require('openhab_rules_tools');
var timerMgr = privateCache.get('timerMgr', () => new timerMgr.TimerMgr());
var vLightName = event.itemName.split("_").get(1);
timerMgr.check(vLightName, 'PT1M', () => { console.info('timer ran'); }, false, null, ruleUID+'_'+vLightName);
When check
is called, if a timer doesn’t exist it creates one. The arguments are:
- key: unique identifier for the Timer, usually best to use an Item name
- timeout: anything supported by
time.toZDT()
, in this case it’s an ISO8601 Duration string for one minute - function: the function to call when the timer expires.
- reschedule: when true, if the timer already exists it will be rescheduled using the timeout
- flapping function: an optional function to call if
check
is called and the timer already exists - name: a name you can give to the timer so if there is an error in the timer function, you can identify what timer it came from