Automation to check multiple entities every x minutes and notify about triggered entity

I would like to create a single automation that sends me an alert notification every 10 mins that my car has one of its sensors open or unlocked.

There are nine entities I wish to monitor. One working solution would be to create 9 separate automations, but I wondered if it’s possible to create a more elegant single automation solution that involves templates please?

Here are two out of nine automations I’m using. The key thing I need is for a notification to be sent every 10 mins until I’ve either locked the car or disabled the notification, so I thought I needed a time_pattern trigger rather than an entity state change trigger.

  - alias: Car unlocked
    initial_state: 'on'
    trigger:
      - platform: time_pattern
        minutes: '/10'
    condition:
      - condition: state
        entity_id: binary_sensor.audi_doors_lock
        state: 'on'
        for:
          minutes: 20
      - condition: state
        entity_id: device_tracker.audi_position
        state: 'home'
      - condition: state
        entity_id: input_boolean.car_disable_notification
        state: 'off'
    action:
      - service: notify.mobile_app_iphone
        data:
          title: "Car is Unlocked!"
          message: "Lock the car you fool!"
          data:
            push:
              sound:
                name: default
                critical: 1
                volume: 1.0

  - alias: Window Open
    initial_state: 'on'
    trigger:
      - platform: time_pattern
        minutes: '/10'
    condition:
      - condition: state
        entity_id: binary_sensor.audi_windows
        state: 'on'
        for:
          minutes: 20
      - condition: state
        entity_id: device_tracker.audi_position
        state: 'home'
      - condition: state
        entity_id: input_boolean.car_disable_notification
        state: 'off'
    action:
      - service: notify.mobile_app_iphone
        data:
          title: "Car Window Open!"
          message: "You've left a window open!"
          data:
            push:
              sound:
                name: default
                critical: 1
                volume: 1.0 

If it wasn’t for the time_pattern trigger requirement, I could specify all my entities within trigger and refer to the triggered entity in the notification, but the constant nagging to lock the car is more important.

I’ve thought about using another time_pattern automation to trigger another automation, but I’ve read that conditions are ignored if you do that so would be no use for me.

I could create multiple OR conditions, but then I wouldn’t be able to send a message relating to a specific entity, eg window left open, or door unlocked, or boot open, etc.

Thanks in advance.

Take a look at the alert.

1 Like

Thank you, I didn’t know about the Alert integration!

Having looked into this a bit, it seems the inability to specify a condition (eg alert only if the car is at home) means I can’t really use Alerts. From what I’ve read, the only way would be to create nine separate binary_sensor templates that includes being at home with each car sensor, and then alerting on those. That still may be a better way than using automations, but I’m still open to options. :slight_smile:

@jarrah did you find a better option? I’m searching for the same solution.

@4ybaka I just ended up using multiple OR conditions which works well enough.

automation:
  - alias: Car unlocked
    initial_state: 'on'
    trigger:
      - platform: time_pattern
        minutes: '/5'
    condition:
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.audi_avant_doors
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_doors_lock
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_hood
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_parking_light
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_trunk
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_trunk_lock
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: binary_sensor.audi_avant_windows
            state: 'on'
            for:
              minutes: 18
          - condition: state
            entity_id: lock.audi_avant_door_lock
            state: 'unlocked'
            for:
              minutes: 18
      - condition: state
        entity_id: device_tracker.life360_me
        state: 'home'
        for:
          minutes: 18
      - condition: state
        entity_id: input_boolean.car_disable_notification
        state: 'off'
    action:
      - service: notify.teleme
        data_template:
          message: 'The car has been left unlocked.'
      - service: notify.mobile_app_iphone
        data:
          title: "Car is not safe!"
          message: "You've left something open on the car you muppet!"
          data:
            push:
              sound:
                name: "Sherwood_Forest.caf"
                critical: 1
                volume: 1.0