Hey everyone, I wanted to share my experience and ask for some tips on optimizing automation rules for toggle devices. I’ve been working with an IKEA Tradfri E1810 device that only sends a toggle signal, not a direct ON/OFF command. This has led me to create a rule that checks the current state and toggles accordingly. However, I’ve noticed some delays and repeated triggers, which I believe are due to the script not setting a flag quickly enough to prevent multiple executions.
Here’s a snippet of my current setup:
plaintext
var source, target, allready_in_execution;
var thread = Java.type(‘java.lang.Thread’)
source = ctx[‘sourceButton’];
target = ctx[‘targetButton’];
if (!allready_in_execution) {
allready_in_execution = true;
items.getItem(target).sendCommand(items.getItem(source).state);
}
thread.sleep(500);
allready_in_execution = false;
The logs show that the script is being triggered multiple times before the flag can be set, which I suspect is causing the delay. I’ve tried adjusting the sleep timer and ensuring the flag is properly reset, but I’m still seeing the issue. Does anyone have suggestions on how to optimize this without changing the overall approach?
I’d love to hear if others have encountered similar challenges and how they resolved them. Maybe there’s a more efficient way to handle the state checks or a different method to prevent multiple triggers. Any insights would be greatly appreciated!
Cheers,
[Your Name]