Multiple automations to control a single entity or bundle into one automation?

I have a number of automations to control the outdoor lights at the front of my house:

  1. When my device tracker is getting close to home - turn on the lights, then off again after 20mins
  2. When I open the garage door (i.e. from inside the house) - turn on the lights, then off again after 20mins
  3. When the doorbell rings - turn on the lights then off again after 20mins.
  4. If motion is detected - turn on the lights then off again.

As you see, quite a bit of repitition.

What are everyone’s rule of thumb for managing these multiple automations? Do you configure each in a discrete automation? Or do you bundle them into one, with multiple triggers? How do you prevent one automation from trampling on the other, if they are separate?

Cheers,
Whytey

In your case since the actions are all the same then use one automation with multiple triggers.

Other cases might not work out like that so each case needs to be decided individually for what makes for the easiest maintainability.

I write automations for one purpose. I think this makes it easier to maintain. I also try to write automations that will survive a reboot.

The automations may be similar but do they operate on the same lights? You could also do a blueprint to make it easier to write.

Here is an example with motion sensor:

- id: 'Study Light on and off Via Motion'
  alias: Study Lights On and Off via Motion
  description: Control Study Lights with Shelly Motion Detection
  mode: single
  trigger:
  - id: 'on'
    platform: state
    entity_id: binary_sensor.shellymotionsensor_60a423c66d96_motion
    to: 'on'
  - id: 'off' 
    platform: state
    entity_id: binary_sensor.shellymotionsensor_60a423c66d96_motion
    to: 'off'
    for:
      minutes: 5
  condition: []
  action:
  - choose:
    - conditions:
      - "{{ trigger.id == 'on' }}"
      - "{{ states('light.study_cans_current_value') == 'off' }}"
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.sonoff_100153c279
      - condition: template
        value_template: "{{ states('sensor.shellymotionsensor_60a423c66d96_luminosity') | float(0) < 200 }}"
      - service: light.turn_on
        target:
          entity_id: light.study_cans_current_value
        data:
          brightness_pct: "{{states('input_number.brightness') | float(0)}}"
    - conditions:
      - "{{ trigger.id == 'off' }}"
      - "{{ states('input_boolean.vacuum') == 'off' }}"
      sequence:
      - service: light.turn_off
        target:
          entity_id: light.study_cans_current_value
      - service: switch.turn_off
        target:
          entity_id: switch.sonoff_100153c279
    default: []