Trying to set a trigger id for a conditional trigger later in the automation

I’m trying to set a trigger id further down in an automation to be used later, but it never shows up as an option when choosing a “When triggered by” step. It only shows the two original trigger ids from the “When” section in the automation, not any I set in the “Then do” section.

I started to type out exactly what the automation is doing and what I’m trying to do but it got really complicated, heh. So as a general inquiry, is anyone setting trigger ids further down in their automations? If so, could you share how you’re doing one?

-Ryan

“When” translates to trigger when switching to Yaml format.
“Then do” translates to action when switching to Yaml format.

As the name implies, trigger id can only be used in triggers. By the sounds of things, you’re trying to somehow add a trigger id in the actions part and expect the condition section to recognise it.

Tell us what you’re attempting to do and show your automation (formatted correctly), and we’ll try to help.

Hi Ryan,

You cannot set a trigger_id, they are created by the automation when there is a trigger.

You could create some other kind of helper and make decisions off of that, or set a variable, but some of that stuff involves using actual YAML and not just the limited UI stuff.

Yea using a helper was where I was leaning next but wasn’t sure I was missing something. When setting a “wait for trigger” action it gives the option to set an id for it, which implies it can be used in some way, but I haven’t figured out how. The YAML is below, but basically what the automation is doing is opening our driveway gate and garage when we get home.

Maybe I’m going about this automation all wrong, but I start the automation and trigger actions depending on how close we are to home. I don’t want the gate opening if I’m just walking the dog down the street so the steps are:

  1. When entering the “Neighborhood” zone, which is about 10 minutes out, start automation and wait up to 30 minutes for the next trigger
  2. When turning onto our street (another zone), open the gate
  3. When entering Home zone, open garage

The problem is the “Street” zone isn’t much larger than the Home zone (and I can’t make it larger, because I don’t want the gate opening too early), so sometimes due to gps/phone lag we go from Neighborhood zone directly to Home zone. So I have “wait for 2 triggers”, one entering street zone, one entering home zone, and open the gate on either. But then I’m not sure how to trigger opening the garage if I went straight to home zone. So I added a trigger id “straight_to_home” to the “entering home zone” trigger, but that id isn’t available later in the automation for the conditions to trigger opening the garage.

Confusing to explain, sorry. But if it’s known we can’t set ids on triggers further in the automation, then that kind of answers the question anyway.

description: ""
trigger:
  - platform: zone
    entity_id: person.mariya
    zone: zone.neighborhood
    event: enter
    id: mariya_coming_home
  - platform: zone
    entity_id: person.ryan
    zone: zone.neighborhood
    event: enter
    id: ryan_coming_home
condition: []
action:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: zone.home
        below: 1
    enabled: true
  - choose:
      - conditions:
          - condition: trigger
            id: mariya_coming_home
        sequence:
          - wait_for_trigger:
              - platform: zone
                entity_id: person.mariya
                zone: zone.street
                event: enter
              - platform: zone
                zone: zone.home
                event: enter
                entity_id: person.mariya
                id: straight_to_home
            timeout:
              hours: 0
              minutes: 30
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
      - conditions:
          - condition: trigger
            id: ryan_coming_home
        sequence:
          - wait_for_trigger:
              - platform: zone
                entity_id: person.ryan
                zone: zone.street
                event: enter
              - platform: zone
                zone: zone.home
                event: enter
                entity_id: person.ryan
                id: straight_to_home
            timeout:
              hours: 0
              minutes: 30
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
  - device_id: 457f845642e34f9be816737e6c8ce45e
    domain: cover
    entity_id: cover.driveway_gate
    type: open
  - choose:
      - conditions:
          - condition: trigger
            id: mariya_coming_home
        sequence:
          - wait_for_trigger:
              - platform: zone
                entity_id: person.mariya
                zone: zone.home
                event: enter
            timeout:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
      - conditions:
          - condition: trigger
            id: ryan_coming_home
        sequence:
          - wait_for_trigger:
              - platform: zone
                entity_id: person.ryan
                zone: zone.home
                event: enter
            timeout:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
      - conditions:
          - condition: trigger
            id: straight_to_home
        sequence: []
  - action: script.open_garage
    metadata: {}
    data: {}
mode: single```

Please follow the Community Guidelines by properly formatting configuration blocks.

It looks like you should be using a Template condition that uses the wait variable.

Whoops, sorry about that. Fixed.

Taking a look at the wait variable, thanks for the lead on that!

One point I forgot to mention that isn’t spelled out in the docs is that you should store the wait.trigger data in a script variable immediately after the first Wait action. There is only 1 wait variable per script instance, so if you don’t store the data, it is lost when the second Wait action starts.

With the double wait series, I would probably do this as per person automations instead of cramming everything together and using multiple branches.

description: "Mariya Arrival Gate and Garage"
trigger:
  - platform: zone
    entity_id: person.mariya
    zone: zone.neighborhood
    event: enter
    id: mariya_coming_home
condition:
# This was by itself in an Or condition in the original...? 
  - alias: Check if someone is already Home
    condition: numeric_state
    entity_id: zone.home
    below: 1
action:
  - wait_for_trigger:
      - platform: zone
        entity_id: person.mariya
        zone: zone.street
        event: enter
      - platform: zone
        zone: zone.home
        event: enter
        entity_id: person.mariya
        id: straight_to_home
    timeout:
      minutes: 30
    continue_on_timeout: false
  - variables:
      wait_trigger_1: "{{ wait.trigger }}"  
  - device_id: 457f845642e34f9be816737e6c8ce45e
    domain: cover
    entity_id: cover.driveway_gate
    type: open
  - if:
      - condition: template
        value_template: "{{ wait_trigger_1.id != 'straight_to_home' }}"
    then:
      - wait_for_trigger:
          - platform: zone
            entity_id: person.mariya
            zone: zone.home
            event: enter
        timeout:
          minutes: 5
        continue_on_timeout: false
  - action: script.open_garage
    metadata: {}
    data: {}
mode: single

Damn, thanks for this. That’s easy to follow and I was trying to figure out how to the wait.trigger.id, so that clarified that nicely. Yea I tried to implement the above with the double-trigger automation and it got messy so I’ll separate them back out. They were separate originally but it was so duplicated, and with the addition of trigger ids it was just originally cleaner to combine them, but now I’m making it too complicated for that.

Good call out on the first condition being an OR. There were other conditions on continuing the routine (the dog being inside) but I removed them, so with just the one left no need for the OR.

Still have to test but this is a great starting point, thanks again :+1: