Best practices for Automation definitions?

Not sure if this belongs in here but I’ve a question about which “direction” people define their automations in.
Since trigger ID’s were introduced it is possible to write a single automation that has many triggers and many actions where the action depends on which thing triggered the automation.

I’ve got a number of buttons in a room and each one has 3 triggers single, double, and long and one is a 4 button scene controller with the same options. So I’ve got 2 options … I can write automations that are based around the action eg “Turn on the lights” where the triggers are the various buttons and only a single action not using trigger ID’s, or I can write them based around the trigger eg “Button 1” where there is a trigger for each of the buttons options (single, double, long) each with a trigger ID and then have multiple actions based on the trigger ID.

The first option can result in more Automations, it is simple to identify what is happening, but you have to look at the automation to identify all the triggers.
The second option could result in less Automations, but it can be tricky to identify exactly what the action is.

Obviously there isn’t necessarily a wrong or right answer here but what are peoples thoughts on the best way to go about defining automations ?

Personally I’m a fan of the old Unix approach - have your script/tool/automation do one thing, and do it well.

Yes, this means you end up with a higher count of automations, but this doesn’t cause any problems, and debugging any automation is a lot simpler.

Where I do diverge a little from this is that I tend to merge automations where there’s a common result desired from many starting points - so I may have multiple triggers that all result in the same set of lights being turned on (or off).

Yeah … that is my common use case for this question. However the buttons in question can do at least 3 things :slight_smile:

My question came from the fact that the other day I wanted to see what a button was programmed to do and searching through automations to work it out was a PITA but in writing it out I’ve had one of those DOH moments … that is where I look at the device and see what automations it is associated with rather than backtracking from the automation :rofl:

1 Like