Avoiding device conflicts with multiple automations?

How do you avoid conflicts with automatons that control the same device?

Is there any way to have some kind of global states/function-calls that will let me keep things more organized, and let me keep the light on “if A or B or C said it should be on”?

For example, I have a floor lamp I have a few times I’d like it to be on:
-Based on time of day (morning/evening based on sunrise/sunset)
-Based on if we are home (any time of day)
-Based on future motion/door sensor, for X minutes after entering the room

  • I have the time of day working well (on at X, off at sunrise, on at sunset, off at X)
  • I have working “if we leave home during the day” (device trackers in a group) working to shut off lights but it then gets complex to keep track of edge cases where if we leave after sunset it will turn off when it should stay on because of condition #1
  • I forsee many more complicated edge cases when I add in a door/motion sensor, I’d like to make it turn on for X minutes after the door is opened…but then I don’t know how I will keep it from turning off if you come home near sunset and it should stay on until the specified time

I feel like there has to be a better way than making dozens of interdependent conditions in dozens of automations that interact with overlap…if this was normal code instead of YAML I’d make function calls to “OR” together, or a global integer counting how many things want a device to be on which can increment +1 when another thing wants it on, or decrement -1 when it wants to go off) and then compare if >0 conditions want it on. But I don’t see a way to do that here.

You can do that if you want. Look at the ‘input_*’ integrations.

input_number, input_text, input_datetime, input_select, input_boolean

These are all input devices that you can easily set from any automation to keep track of global state things.

I don’t personally use it, but this is a perfect example of why Node Red is so powerful…and popular.

Take a look at some of the flow diagrams:

You can define all of your flows and group them together into a single thing. And if you suddenly want to tie other info other places, you can do that.

If you don’t like the gui approach of Node Red, why not look at AppDaemon. You simply write everything you want in python!

Interesting, that GUI approach looks kind of neat. Basically drawing out the flow-charts I more or less what I end up doing as a preparation step before writing code…and if that can be the actual direction that could save a step (and be better than comments!)

If you are familiar with python, you can take a look at AppDaemon.

Well, I was about to ask a similar questions from a slightly different point of view.
My use case:
I have an extractor fan that I want to switch on when either humidity or temperature gradient is above a set threshold.
When it happens, I set an appropriate input_boolean (I put them in a group) so I could see what exactly switched on my fan. Actually, every automation checks if the group is on and proceeds only if it’s off.
The trouble is sometimes I notice both input_booleans on - in theory it shouldn’t happen, but it does. Apparently it’s because automations run independently and there is no immediate way to change state of an entity.
In my case it’s not a big deal but I presume it might be a huge problem for some.