Help simplifying automation

Hello…

I would gladly accept some help to simplify this automation.

Using template, I build a sensor.east_main_gate which have three modes: “Closed”, “Pedestrian_mode” and “Car_mode”.

I also have an additional “binary_sensor.small_gate_status”.

I want to achieve the following:

  1. Call a script to take snapshot when “binary_sensor.small_gate_status” is either open/closed.
  2. Call a script to take snapshot when the man gate is either pedestrian or car mode.
  3. Send a notification when small gate remains open for more than 2 minutes with the latest snapshot.
  4. Send a notification when main gate is not closed within 5 minutes with the latest snapshot.
alias: Gate Notification
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.small_gate_status
  - platform: state
    entity_id:
      - sensor.east_main_gate
    from: Closed
    to: Pedestrian_mode
    for:
      hours: 0
      minutes: 0
      seconds: 22
  - platform: state
    entity_id:
      - sensor.east_main_gate
    from: Closed
    to: Car_mode
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - sensor.east_main_gate
    to: Closed
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.small_gate_status
    to: "on"
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: small_gate_remained_open
  - platform: state
    entity_id:
      - sensor.east_main_gate
    to: Pedestrian_mode
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: left_in_pedestrian
  - platform: state
    entity_id:
      - sensor.east_main_gate
    to: Car_mode
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: left_in_car
condition: []
action:
  - service: script.camera_outdoor_front_snapshots_east_main_gate
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - choose:
      - conditions:
          - condition: trigger
            id: small_gate_remained_open
        sequence:
          - service: notify.mobile_app_cph
            data:
              message: Small Gate Remained opened for > 2 Minutes
              title: Alert! Small Gate
              data:
                image: >-
                  local/snapshots/outdoor_camera_2/snapshot_east-main-gate-latest.jpg
      - conditions:
          - condition: trigger
            id: left_in_pedestrian
        sequence:
          - service: notify.mobile_app_cph
            data:
              message: Gate Remained in Pedestrian Mode for > 5 Minutes
              title: Alert! Gate in Pedestrian
              data:
                image: >-
                  local/snapshots/outdoor_camera_2/snapshot_east-main-gate-latest.jpg
      - conditions:
          - condition: trigger
            id: left_in_car
        sequence:
          - service: notify.mobile_app_cph
            data:
              message: Gate Remained in Car Mode for > 5 Minutes
              title: Alert! Gate in Car Mode
              data:
                image: >-
                  local/snapshots/outdoor_camera_2/snapshot_east-main-gate-latest.jpg
mode: single