I was having issues with the speed of some of my rules (delay between switch press and light turning on was too long) and after some debugging, located the problem: using members.findFirst
is causing delays. Specifically, lines like:
var root_name = "" + triggeringItem.name.split('_').get(0) + "_" + triggeringItem.name.split('_').get(1) + "_" + triggeringItem.name.split('_').get(2) + "_"
var state_item = LightVirtual.members.findFirst[ i | i.name == root_name + "State"]
var brightness_item = LightVirtual.members.findFirst[ i | i.name == root_name + "Brightness"]
var brightness_mem_item = LightVirtual.members.findFirst[ i | i.name == root_name + "BrightnessMemory"]
var colortemp_mem_item = LightVirtual.members.findFirst[ i | i.name == root_name + "ColorTempMemory"]
In this case, the code takes about 400ms to run with a group size of around 200 members–this is too long.
Short of decreasing the group size, is there a faster way to do this? Is there a method I can use provided that I have the exact name of the item like items.get(name)
as is possible in the MainUI widgets with items[<item name>]
?