Help requested: Preventing automations from fighting over the same actuator
Hey all,
I have a question about an architectural problem I'm facing.
TLDR: I cannot figure out how to prevent one automation from undoing the work that another automation just did. One automation can turn on a light because of X. Then, when X is still relevant, unrelated Y could tell another automation to turn that light off, not even knowing about X.
The main question is how you manage devices that should be controlled by multiple events.
For example. Let's say you're going to watch a movie during daytime. I could write an automation that checks for that, then tells the curtains to close if it's daytime. But there is already another automation that also checks if the sunlight is very bright today (and would heat up my house) so it will close or open the curtains based on weather information.
Hopefully you see where I'm going with this. I do not want my sun/heat blocking automation to open my curtains when I'm watching a movie during daytime. But adding a condition to the sun/heat blocking automation will inevitably make my automation more complex.
I want to keep these concerns separated, but also want to prevent automations with another goal to prevent actuating something that is in that state because another automation put it there and has more priority now. Basically when one automation has done something to an actuator, how can I prevent another automation from undoing that when it's fired a little later.
It's almost like I need a mutex on my actuator lol.
This is just a little example, but there are many situations where you'd have two or more automations controlling for example a single light.
I have not solved this and I'm not sure if Home assistant has the ability to solve this in a pretty way.
Things I've thought about
- Disabling automations with automations: Personally I think this is ugly because in the HA interface there is no way to know if the automation is disabled because I need to fix something still, or because it is temporarily disabled. Also, this introduces some state that requires recovering whenever HA is restarted for some reason. It would allow a higher priority automation to disable the lower prio one and re-enable when the situation changed. But how does one determine priority correctly? In the example mentioned before: If movie is turned on during daytime but it's heavily clouded. The curtains can stay open. Then I'd want the curtains to be closed later whenever the sun returns and I'd want the other automation to be enabled still.
- Creating helper binary sensors like "is_movie_on" or "is_it_sunny" that are composed of various inputs to condense it down to just a on/off. Then abstract those by creating another helper sensor that can take in all the different sensors and state of the to be actuated thing and then use that as a trigger for automations and let that decide which automation must be fired. This can work but may be a little complex in knowing which helper sensor is used for which automation eventually. I figure it can grow out of hand quite quickly
What do you guys think? Have you tackled this? Do you experience similar issues? Is there an alternative? Is your cat watching you reading this post?