I have the following rule which syncs 2 devices. Most of the time, this works great except some times the lights start bouncing on/off. I can stop this by disabling/enabling the rule which seems to reset the condition.
I have two switches though only one is the master switch (Switch A). The second switch (Switch B) controls the device but the switch itself is not physically reachable and thus I rely on the Switch A to control the Switch B’s load.
The rule (below) monitors the state change of Switch A … first if Switch A is turned on and thus turns Switch B off, and then does the same for an off condition.
In general, this works fine. Except occasionally we seem to ping pong … on and off … on and off until I disable the rule from the API.
On thing that I have observed is that it will take the Rule disable several seconds before the blinking stops. I suspect that multiple rules are fired off which may be the cause.
I tried to mitigate this by writing my driver to ignore an “on” or “off” command if the switch is already on or off. That way, I am not generating useless events.
While this works in general, we have the occasional blinking action. Of course, it happens at inopportune times when going to bed or leaving the house. Getting to the computer to remedy the rule is not convenient.
Any ideas on how I can change the rule to avoid the race condition. I again suspect that multiple threads of the rules are fired off when this condition occurs but there is no way to verify this. I am not aware of how to test if one copy of the rule thread is currently active so that I could stop the loop.
That is an interesting one. Stopping the light turning on and off is one thing, but that doesn’t mean the Rule isn’t still looping, and why on earth is it looping in the first place?
Out of curiosity, have you tried the Rule without using the changes conditions? By that I mean just using equals without wrapping them in changes. I’d imagine they are redundant but I’d also expect them to be harmless.