How to trigger an automation from another automation but only if the 2nd automation is on

I have a circuit that I want to turn on for 5 seconds then turn off. 10 seconds later I want to turn another circuit on for 5 seconds then off. But, I want to be able to chose whether that 2nd circuit is turned on based on toggling a second automation on or off.

So, I have two automations set up.

- id: '1535300995148'
  alias: Automation1
  trigger:
  - at: '11:32'
    platform: time
  condition: []
  action:
  - data:
      entity_id: switch.sonoff_4ch_pro__r1_channel
    service: switch.turn_on
  - delay: 5
  - data:
      entity_id: switch.sonoff_4ch_pro__r1_channel
    service: switch.turn_off
  - delay: '10'
  - data:
      entity_id: automation.Automation2
    service: automation.trigger
- id: '1535301295580'
  alias: Automation2
  trigger:
  - platform: template
    value_template: '9999'
  condition:
  action:
  - data:
      entity_id: switch.sonoff_4ch_pro__r3_channel
    service: switch.turn_on
  - delay: '5'
  - data:
      entity_id: switch.sonoff_4ch_pro__r3_channel
    service: switch.turn_off

I’m just using a time trigger for automation1 while testing. I added a blank template trigger to automation2 because without a trigger it would automatically toggle off.

The automations run as intended, but toggling automation2 off in the HA control panel does not stop it from running. I even tried adding a condition to automation2 that would only allow it to run if automation2 was toggled on. That didn’t work. Is there a good way around this?

I tried adding a third automation in between automation 1 and 2 that used the condition that automation2 was toggled on. That didn’t work either.

- id: '1535303479506'
  alias: automation3
  trigger:
  - platform: template
    value_template: '9999'
  condition:
  - condition: state
    entity_id: automation.automation2
    state: 'on'
  action:
  - data:
      entity_id: automation.automation2
    service: automation.trigger

You must be building up to something more complicated, because right now there doesn’t seem to be any reason to have any automations at all. It would seem these should be scripts.

But, if you do want automations, and you’re trying to get the first to run the second, but only if the second one is on, I’d recommend using a custom event instead of the automation.trigger service. (I’ve never played with the automation.trigger service, but my guess is, based on what you say, it works like manually triggering an automation, which doesn’t care about the automation’s triggers and conditions - it just causes the automation’s actions to run regardless.)

You can use a custom event like this:

  action:
    ...
    - event: run_2nd_automation

- id: '1535301295580'
  alias: Automation2
  trigger:
    platform: event
    event_type: run_2nd_automation
  action:
    ...

Awesome! Thanks, that’s what I’m after.