Using trigger in Conditions

I’m trying to do something in a choose block in an automation using the trigger of an event as the condition. Here is a test showing what I want to do:

    trigger:
    - platform: state
      entity_id: input_boolean.button
      to: 'on'
    - platform: event
      event_type: automation_reloaded
    mode: restart
    action:
      - choose:  # Do this ONLY after an Automation reload
          - conditions:
              - condition: template
                value_template: "{{ trigger.event_type == automation_reloaded }}"
            sequence:
              - service: homeassistant.toggle
                entity_id: input_boolean.dummy

I don’t think I’m using the trigger in the condition correctly, and there is very little info in the Docs on this particular trigger. Actually, this condition is ALWAYS true, both when I reload automations AND when I click the input_boolean. What am I missing?

What happens if you try this?

value_template: "{{ trigger.event_type == 'automation_reloaded' }}"

I tried that, unfortunately. Nothing happens, so the template evaluates to false all the time.

try:

value_template: "{{ trigger.event == 'automation_reloaded' }}"

Thanks finity, I tried that too, with and without the quotes. Same as what Tom suggested: nothing happens, template evals to false. I guessed at trigger.event earlier not knowing if that was even a ‘thing’.

Actually, I think that the format of my OP is correct. The problem is that once an Event has fired, then its state, as far as the Condition statement is concerned, is (and remains) true until a restart. Somehow though, the trigger logic code can discern an actual event trigger from the state of the ‘automation_reloaded’ being true, because it will trigger over and over correctly, firing the automation - it just fails the Condition in all other cases. The use case above may not have been considered when coding the Conditions logic, or there is just not enough data available for this event to discriminate in the Condition. Either way, I’m stuck here with no solution. Maybe I’ll poke around in the src when I get some time.

    action:
    - choose:  # Do this ONLY after an Automation reload
      - conditions: "{{ trigger.platform == 'event' }}"
        sequence:
        - service: homeassistant.toggle
          entity_id: input_boolean.dummy
2 Likes

Taras, that worked!!

After rereading the docs here, I never would have guessed to use that particular string - and I’ve been using the trigger.entity_id functionality. We could definitely use some more documentation and examples on this topic.

Or maybe it’s just me who missed it. :wink:

EDIT: and I just verified that the quotes are REQUIRED around event or it doesn’t work. For future reference.

They are required because you are comparing trigger.platform to a string value. If you don’t quote the word event it’s interpreted as being the name of a variable (a non-existent variable so the comparison always evaluates to false).

Your automation uses two triggers and each one relies on a different platform. That makes it easy to determine which one triggered the automation by simply checking trigger.platform.

1 Like

See, that kind of information would be useful in the Docs. :upside_down_face:

Thanks for the help!