Simplifying 4 automations on front door into just 1?

I have 4 automations set up on my front door, which has a binary sensor attached (“binary_sensor.alarm_panel_pro_001fd8_zone_1”):

  1. If the door is left open for >5 minutes. Set a helper input_boolean “front door left open” to true, and send a push notification to my phone to tell me the door is left open
  2. If the door is left open >1 hour, send an urgent notification to my phone
  3. If the door is closed, turn off “front door left open”
  4. Once the door is eventually closed (i.e. when “front door left open” is turned off, in either of cases 1 or 2), send a push notification to my phone that the door has finally been closed.

The working Yaml for these is below (copy/pasted from automations.yaml, although I set these up in the GUI) - perhaps this is useful to others who want something similar.

However, as a programmer I find it a bit cumbersome (and likely fragile to future changes) to have 4 different automations tangled together in this way to control one coherent set of actions related to the front door.

Is there a better way to do this kind of thing? Whether built into HA or via an integration/a different mechanism to create automations that is more unified?

thx, Vince.

- id: '1700407367739'
  alias: 'Front Door: Notify if left open too long'
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 5
      seconds: 0
  condition: []
  action:
  - service: notify.mobile_app_vinces_iphone
    data:
      message: Front door has been open for 5 minutes
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.front_door_left_open
  mode: single
- id: '1700407839774'
  alias: 'Front Door: Notify if open for an hour'
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: 'off'
    to: 'on'
    for:
      hours: 1
      minutes: 0
      seconds: 0
  condition: []
  action:
  - service: notify.mobile_app_vinces_iphone
    data:
      message: 'URGENT: Front door open for an hour'
  mode: single
- id: '1715166779470'
  alias: 'Front Door: Closing'
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 0
  condition: []
  action:
  - service: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.front_door_left_open
  mode: single
- id: '1715166572466'
  alias: 'Front Door: Eventually Closed'
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_boolean.front_door_left_open
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: notify.mobile_app_vinces_iphone
    metadata: {}
    data:
      message: Front door is now closed
  mode: single

(thank you - post formatted correctly now)

Please see #11 in this topic to format the post correctly.
How to help us help you - or How to ask a good question - Configuration - Home Assistant Community (home-assistant.io)

But, basically, you can setup all triggers in one automation, give them each a different trigger_id, then choose on trigger_id for your actions.

Thank you. I’ve rewritten as this, which works in minimal testing so far:

alias: "Front Door: Notifications when left open"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: triggerDoorLeftOpen
  - platform: state
    entity_id:
      - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: "off"
    to: "on"
    for:
      hours: 1
      minutes: 0
      seconds: 0
    id: triggerDoorLeftOpenLonger
  - platform: state
    entity_id:
      - binary_sensor.alarm_panel_pro_001fd8_zone_1
    from: "on"
    to: "off"
    id: triggerDoorClosed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - triggerDoorLeftOpen
        sequence:
          - service: notify.mobile_app_vinces_iphone
            data:
              message: Front door has been open for 5 minutes
          - service: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.front_door_left_open
      - conditions:
          - condition: trigger
            id:
              - triggerDoorLeftOpenLonger
        sequence:
          - service: notify.mobile_app_vinces_iphone
            data:
              message: "URGENT: Front door has been open for 1 hour"
      - conditions:
          - condition: trigger
            id:
              - triggerDoorClosed
          - condition: state
            entity_id: input_boolean.front_door_left_open
            state: "on"
        sequence:
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.front_door_left_open
          - service: notify.mobile_app_vinces_iphone
            data:
              message: Front door is now closed
mode: single
1 Like

What do you use the input boolean for that you can’t use the binary_sensor for?

Other than that the Alert integration would negate the need for this automation and give you the option of repeated alerts with whatever time intervals you want:

alert:
  front_door:
    name: Front Door is open
    entity_id: binary_sensor.alarm_panel_pro_001fd8_zone_1
    state: "on" 
    repeat:
      - 5
      - 60
    can_acknowledge: true
    skip_first: true
    notifiers:
      - mobile_app_vinces_iphone

I used the input boolean to record the fact that a notification alert (door open, whether for 5 minutes or 1 hour) has been sent, in order to only send the “Front door is now closed” message if a previous “open” notification has been sent.

The purpose was to avoid sending “Front door is now closed” if the door has only been open for a few seconds/minutes.

Does that make sense? Is there a nice way to accomplish this without using an extra boolean?

I’ll look into the Alert integration in any case - sounds useful (thank you!)… And at first glance it looks as if it might also do my “Front door is now closed” thing as well.