Template in a template assistance

Not sure the best way to handle this. I have three possible triggers, and I want to change my template based on with entity triggered the automation, but the value I want to use is not based on that entity .

  - alias: Notify who unlocked door with timestamp
# this will send you a message telling you which slot was used to unlock the door and will use the
# name set in the input text for the door as it's friendly name.  If you dont want to get notified
# when you are home use the appropiate condition. 
    - platform: state
        - sensor.frontdoor_action
        - sensor.backdoor_action
      to: 'Keypad Unlock'
# This is for an FE599 Schalge lock, they handle events differntly, this will only trigger if a differnt code is used to unlock the door.  Best I could do currently
    - platform: state
        - sensor.garagedoor_code
    - condition: numeric_state
      entity_id: sensor.ha_runtime_in_minutes
      above: 1
#   - condition: state
#     entity_id: input_select.house_mode
#     state: 'Away'
    - delay:
        seconds: 2
    - service: notify.pushbullet_notifications
        message: " At {{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} on {{ now().strftime('%d %b %Y') }} " 
        - email/[email protected]
        title: "{{ trigger.to_state.attributes.friendly_name }} unlocked by {{ states.sensor.backdoor_code.state }}"

The Section I’m trying to figure out is the last line

 title: "{{ trigger.to_state.attributes.friendly_name }} unlocked by {{ states.sensor.backdoor_code.state }}"

Specifically I need this “{{ states.sensor.backdoor_code.state }}” to be different based on the trigger

need it to be backdoor code if sensor.backdoor_action was the triger
frontdoor_code if sensor.frontdoor_action was the trigger
for garage the trigger IS sensor.garagedoor_code.

I thought about another sensor like “Last unlocked code” that would show who unlocked any of the doors and use that, but i could not figure out how to do that based on these triggers.

I’m not 100% sure of the actual logic that you need, but you could use an if/else statement. something like:

  {{ trigger.to_state.attributes.friendly_name }} unlocked by
  {% if  trigger.entity_id = 'sensor.backdoor_action' %}{{states.sensor.backdoor_code.state}}
  {% elif trigger.entity_id = 'sensor.frontdoor_action' %}{{states.sensor.frontdoor_code.state}}
  {% else %}{{states.sensor.garagedoor_code.state}}
  {% endif %}
1 Like