Generating a dynamic variable name in a rule

Hi, i want to get an Alexa notification, when a window is open for longer than X minutes. I need for every room one timer and thought about variables with a dynamic name. is this possible? Something like

Switch Window_RoomA
    Window_RoomA changed to ON
    var Timer ("windowTimer_" + triggeringItemName.split('_').get(1)) = null

Is this somehow possible? When trying this method, i am getting this error:
Configuration model 'Fenster.rules' has errors, therefore ignoring it: [20,71]: no viable alternative at input '='


Not possible, it just doesn’t work like that.

For your particular problem, store instead your Timer references in a Map, which is like an “array” keyed by arbitrary names - Item name, for example.
See example in “Group findFirst”

Something very similar is possible (or will be possible in the new release): You can use the privateCache or the sharedCache for this, it supports put() and get() and even auto-cancels timers when the script file is unloaded. In the end it is a Map, but with some special features (like the mentioned auto-cancel for timers).

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