Trigger.entity_id Not Working as Expected

In the following automation, whatever is returned for entity_id (not sure how I can see this) when I turn on one of the designated fans does not match as expected and therefore fails to start the appropriate timer. I’ve tried trigger.from_state.entity_id and trigger.to_state.entity_id, and neither of those work.

alias: Timer - start timer20
description: ''
trigger:
  - platform: event
    event_data:
      entity_id: switch.fan_master_bath
      control: DON
    event_type: isy994_control
  - platform: event
    event_data:
      entity_id: switch.fan_master_toilet
      control: DON
    event_type: isy994_control
  - platform: event
    event_data:
      entity_id: switch.fan_pool_bath
      control: DON
    event_type: isy994_control
condition: []
action:
  - service: timer.start
    data:
      entity_id: |
        {% if (trigger.entity_id) == 'switch.fan_master_bath' %}
          timer.master_bath30
        {% elif (trigger.entity_id) == 'switch.fan_master_toilet' %}
          timer.master_toilet30
        {% elif (trigger.entity_id) == 'switch.fan_pool_bath' %}
          timer.pool_bath30
        {% endif %}
mode: single

Note that a similar template with a slightly different trigger works just fine:

alias: Timer - cancel timers
description: ''
trigger:
  - platform: state
    entity_id: switch.fan_master_bath
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: switch.fan_master_toilet
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: switch.fan_pool_bath
    from: 'on'
    to: 'off'
condition: []
action:
  - service: timer.cancel
    data:
      entity_id: |
        {% if (trigger.entity_id) == 'switch.fan_master_bath' %}
          timer.master_bath20, timer.master_bath30, timer.master_bath40
        {% elif (trigger.entity_id) == 'switch.fan_master_toilet' %}
          timer.master_toilet20, timer.master_toilet30, timer.master_toilet40
        {% elif (trigger.entity_id) == 'switch.fan_pool_bath' %}
          timer.pool_bath20, timer.pool_bath30, timer.pool_bath40
        {% endif %}
mode: single

Any ideas?

Yeah, your first automation has event triggers, which don’t have an entity_id, so it doesn’t work.

Your second automation has state triggers that do have an entity_id, so it does work.

1 Like

If entity_id won’t work, in the first automation, any suggestions for an alternative approach to identify which trigger initiated the automation?

trigger.event.data.entity_id ?

1 Like
trigger.event.data.entity_id

Ninja’d by mf_social!

1 Like
action:
  - service: timer.start
    data:
      entity_id: "{{ trigger.event.data.entity_id.replace('switch.fan_', 'timer.') ~ '30' }}"
mode: single
1 Like

Thanks guys!

1 Like