Is it a bad habit to use multiple automation triggers and if statements in the actions?

I have the habit of putting multiple triggers into automations and using if conditions to control what is being done depending on the trigger. I do this to reduce the number of components for every solution by only needing one automation rather than 2 or 3.

Is this a bad habit that may cause issues that I may not think about? I do consider multiple calls and the possible need to change mode to e.g. queued.

An example (never mind the mismatch of entity with name of automation):

alias: Mattress safety timer handler
description: ""
trigger:
  - platform: state
    entity_id:
      - light.studio_window
    to:
      - "on"
      - "off"
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.mattress_safety_timer
condition: []
action:
  - if:
      - alias: Check if on/off trigger
        condition: template
        value_template: "{{ trigger.idx == \"0\" }}"
    then:
      - alias: Handle on/off events
        if:
          - condition: template
            value_template: "{{ trigger.to_state == \"on\" }}"
            alias: Check on/off
        then:
          - service: timer.start
            metadata: {}
            data: {}
            target:
              entity_id: timer.mattress_safety_timer
        else:
          - service: timer.cancel
            metadata: {}
            data: {}
            target:
              entity_id: timer.mattress_safety_timer
    else:
      - service: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.studio_window
    enabled: true
mode: single

1 Like

This is pretty normal, not a bad habit. I wouldn’t over think it.

2 Likes

Good to know. Thanks!

And then there was the ‘switch’ statement. Let there be light. – The Book of Algol 60 by John McCarthy (1960)

:wink:

You could give each trigger an id and use choose in the action based on trigger id.

I regretted not using it from the start :stuck_out_tongue: now I’m too lazy to fix it.

Same thing with giving id’s as suggested by @jeffcrum