Trigger Automation Only When Another Automation Was Triggered?

Hello, is there any good way to trigger an automation only when another automation was triggered?
Here’s the situation. I have an automation that send me a notification when my internet is down for 5 minutes. And send another notification when my internet is up again. The problem is, sometimes my internet is down for a few seconds and then up again. So I got a notification that send me a notification saying my internet is up. I only want the notification only when my internet is truly down/up. Here’s my current yaml file:

- alias: WAN Down Notification
  trigger:
  - platform: state
    entity_id: binary_sensor.ping_wan
    to: 'off'
    for: '00:05:00'
  action:
  - service: notify.mobile
    data:
      title: 'WAN is down'
      message: 'internet is down for more than 5 minutes'
- alias: WAN Up Notification
  trigger:
  - platform: state
    entity_id: binary_sensor.ping_wan
    from: 'off'
    to: 'on'
  action:
  - service: notify.mobile
    data:
      title: 'WAN is up again'
      message: 'internet is up again, yay!'

Thanks before :slight_smile:

Added two lines at the end of each automation to only activate the “up” notification when the “down” notification fires, and an initial_state in the “up” automation to turn it off on HA restart.

- alias: WAN Down Notification
  trigger:
  - platform: state
    entity_id: binary_sensor.ping_wan
    to: 'off'
    for: '00:05:00'
  action:
  - service: notify.mobile
    data:
      title: 'WAN is down'
      message: 'internet is down for more than 5 minutes'
  - service: home_assistant.turn_on
    entity_id: automation.wan_up_notification

- alias: WAN Up Notification
  initial_state: false
  trigger:
  - platform: state
    entity_id: binary_sensor.ping_wan
    from: 'off'
    to: 'on'
  action:
  - service: notify.mobile
    data:
      title: 'WAN is up again'
      message: 'internet is up again, yay!'
  - service: home_assistant.turn_off
    entity_id: automation.wan_up_notification

Sorry I wasn’t clear enough. I don’t want to turn off automation. The problem is, sometimes my internet went down for only a while (less than 5 minutes), and I don’t want to get ‘WAN is up again’ notification if my internet is only down for less than 5 minutes.
Here’s what happen if my internet is only down for less than 5 minutes:

  1. The first automation doesn’t give me any notification
  2. Then I got a notification about my internet is up again.

What I want it to happen if my internet is down for less than 5 minutes:

  1. The first automation doesn’t give me any notification
  2. The second automation doesn’t give me any notificaiton

Is there a way to get this done? What I want is the second automation doesn’t trigger if the first automation didn’t trigger. Maybe using condition?

Sorry, You updated your post and now this makes sense to me. I’ll try this out now. Thank you :slight_smile:

EDIT: It totally WORKS. Thank you so much :smiley:

1 Like

It can be done using a single automation employing a wait_for_trigger.

- alias: WAN Down-Up Notification
  trigger:
  - platform: state
    entity_id: binary_sensor.ping_wan
    to: 'off'
    for: '00:05:00'
  action:
  - service: notify.mobile
    data:
      title: 'WAN is down'
      message: 'internet is down for more than 5 minutes'
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.ping_wan
      from: 'off'
      to: 'on'
  - service: notify.mobile
    data:
      title: 'WAN is up again'
      message: 'internet is up again, yay!'

How it works:

  • The automation is triggered when the binary_sensor’s state changes to off and remains that way for at least 5 minutes.
  • A notification is sent informing you ‘WAN is down’.
  • The automation waits until the binary_sensor’s state changes to on.
  • A notification is sent informing you ‘WAN is up’.

The second notification is sent only if both triggers occur in the described order.


NOTE

You could even add a for: '00:00:05' to the State Trigger in wait_for_trigger so that it will report ‘WAN is up’ only if it has been up for at least 5 seconds.

1 Like

Thanks! Sorry I just read your post. Seems like this is a better way because it only need one automation to work. :smiley:

Yes, it’s done with just one automation but the real benefit is the added flexibility. Both wait_for_trigger and wait_template are suitable for handling situations like yours where a specific sequence of events must occur before there is an action. In your case, you want to be notified when the internet service is restored but only if was previously down for at least 5 minutes.

In addition, wait_for_trigger and wait_template support a timeout. In other words, instead of waiting forever, it can have an optional time limit. For example, when the timeout expires, it can send you a different notification (“Internet down for more than 2 hours.”) or take a different action from the default one.