I have created many automations successfully, so I understand “how” to create them.
My question is more “procedural” in general.
Example: Motion sensor to turn a light on when motion detected and turn off the light when motion no longer detected.
Should this be broken into two SEPARATE automations? What are the benefits of this method?
Should these two actions be combined into ONE automation and use UNTILs or WHILEs to control flow within the automation? This would mean the automation would continue to run “in the background” until some condition forces a STOP.
Making it messier and harder to find your automations.
Pulling your hair when you don’t find the automations is also a cost saving (no need to cut your hair).
Yes. I think so.
No…
You can set up several triggers in the same automation and use the choose to set an action based on the trigger.
I just picked the first automation I have with this setup:
At the “best practices” level, I think the answer is “what method seems the most intuitive to you”. There is an old saying in systems development that 80% of the cost of any system is in its maintenance. So you want to make it as easy as possible to find / fix / improve things down the road. Where would you look for it first? That is where you should put it!
It makes no difference - they all go in the same yaml file. A long automation may well use more resources than several short ones simply because of all the branches and conditions it requires.
As @PecosKidd says, ease of maintenance is the important thing. In six months you won’t remember how the damn thing worked - take whatever approach is going to make things easier for you.
On that subject, good organisation and annotation can make a lot of difference: