Trigering only if another automation was triggered

Hi, New to automations in home assistant but trying things out.

I have 2 automations and have added a delay into the first one which works great and has stopped false notifications but as there was a false notification my second one keeps notifying me, can anyone think of a way I can only run the second automation if the first one has indeed been triggered?

Automation1:

alias: Off Grid
description: Tesla notified we are off grid
trigger:
  - platform: state
    entity_id:
      - binary_sensor.my_home_grid_status
    from: "on"
    to: unavailable
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.my_home_grid_status
    state: unavailable
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.my_home_grid_status
    state: unavailable
  - service: notify.alexa_media_office
    data:
      message: >-
        The power is out and the house is now running on battery, turn off any
        unwanted devices.
      data:
        type: tts
  - service: notify.alexa_media_kitchen_echo_show_8
    data:
      message: >-
        The power is out and the house is now running on battery, turn off any
        unwanted devices.
      data:
        type: tts
    enabled: false
  - service: notify.alexa_media_hallway
    data:
      data:
        type: tts
      message: >-
        The power is out and the house is now running on battery, turn off any
        unwanted devices.
    enabled: false
mode: single

Automation 2:

alias: On Grid
description: Tesla notified we are back on grid
trigger:
  - platform: state
    entity_id:
      - binary_sensor.my_home_grid_status
    from: unavailable
    to: "on"
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.my_home_grid_status
    state: "on"
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.my_home_grid_status
    state: "on"
  - service: notify.alexa_media_officea
    data:
      message: The power to the house has been restored
      data:
        type: tts
  - service: notify.alexa_media_kitchen_echo_show_8
    data:
      message: The power to the house has been restored
      data:
        type: tts
    enabled: false
  - service: notify.alexa_media_hallway
    data:
      data:
        type: tts
      message: The power to the house has been restored
    enabled: false
mode: single

Is there a reason why using a duration on your triggers instead multiple delays would not work?

You can use a template condition to compare the current time to the last triggered time of automation 1, you will just need to decide what time difference you want to use.

alias: On Grid
description: Tesla notified we are back on grid
trigger:
  - platform: state
    entity_id:
      - binary_sensor.my_home_grid_status
    from: unavailable
    to: "on"
    for: "00:02:00"
condition: 
  - alias: Test if Off Grid automation was triggered in the last 6 hours
    condition: template
    value_template: "{{ now() >= state_attr('automation.off_grid', 'last_triggered') + timedelta(hours=6) }}"
action:
  - service: notify.alexa_media_officea
    data:
      message: The power to the house has been restored
      data:
        type: tts
  - service: notify.alexa_media_kitchen_echo_show_8
    data:
      message: The power to the house has been restored
      data:
        type: tts
    enabled: false
  - service: notify.alexa_media_hallway
    data:
      data:
        type: tts
      message: The power to the house has been restored
    enabled: false
mode: single

FWIW, you can make the automation more compact by using the generic notify.alexa_media service and listing the target media players:

  - service: notify.alexa_media
    data:
      data:
        type: tts
      target:
        - media_player.example_hallway
        - media_player.kitchen_echo_show_8
        - media_player.officea
      message: The power to the house has been restored
    enabled: false

Thats awesome thanks so much, I think i learned about 5 things from that reply!

Is there a list of all the state attributes available that I can use?

Thanks

The state attributes of any entity can be seen in the States tab of the Developer Tools

Additionally, an entity’s state object contains a number of other properties which are available through templating.

1 Like

Thanks again!