Creating multiple timers switching same light instead of different ones (JSS)

If changing a var to a let works for you then maybe stop there? Keep it simple :slight_smile:

As I said, it is under review. But yeah. The simpler the better.

On the other hand. When getting the grasps of the array approach, this could be used across a wide variety of rules. It would be even more useful if stuff might change in the (near) future. Like you rightly pointed out, if data is stored outside rules it would always be available (unless you clear cache but how often does that happen while at the same time your rule needs that data).

I do think it works because it is not in the global scope as @rlkoshak mentioned. According to the docs:

let x = 1;
{
  let x = 2;
}
console.log(x); // logs 1

and my randomSwitch is effectively let x = 2 so inside another block.

I gave an example above. It’s just a function that returns a function. You pass arguments to the generator function and those arguments get “fixed” in the context of the function that’s returned.

Yes, it’s future proof and even works in other languages with similar problems, such as Python in some contexts. It’s not a feature of the language, it’s an approach.

After a few more testing rounds I can confirm that this is working for my specific case (see post 8).

Thanks to all for the support, suggestions and help! I’ve learned a great deal and there are more options to explore (and alway will be I guess :crazy_face:)