Best way to combine automations or simplify automations that are very similar?

Hey all,

So i have an automation for a remote, if the sensor = 1, turn on light, if sensor = 2 turn off light, if sensor = 3 run routine, etc etc.

I currently have to create 7 automations per remote and I feel like its a bit overkill, is there a better way to do this? Right from the UI its a bit hard to tell.

There are lots of ways to do this, but, from the UI is probably the most tedious.

  1. If you use a text editor and edit the YAML directly you can copy and paste the automation and then change the entities.

  2. With YAML anchors you can eliminate some of the repetition.

  3. Using a script that takes a few variables may help to make your automations smaller.

  4. a python_script can help reduce the amount of code required in the script

  5. Pyscript, AppDaemon, or NodeRed can help reduce this even more and simplify the code entirely.

  6. Pyscript and AppDaemon both support the concept of “Apps” allowing you to to configure each set of automations with only a few lines of config (probably YAML).

  7. At the Home Assistant conference in December, it is likely that a new feature called “Blueprints” will be announced that may simplify this greatly.

This sounds like this is the type of use case the chooser logic was created for.

Thanks alot this was perfect!

1 Like