SOLVED: Action template challange

Hi,
I’m running my head against the wall with the below automation.
I want to see what triggers the automation and then send a message depending on which trigger, triggered the automation.
I can’t seem to find any examples on this, only ones with friendly name, but i cannot use that because i use dynamic friendly names on two of the triggers.

- alias: Notify - Presence Home
  trigger:
    platform: state
    entity_id: sensor.status_family, sensor.status_jeppe, sensor.status_kitt
    to: 'home'
  action:
    service: notify.pushoverjeppe
    data_template:
      title: "Hass.io - Presence Home"
      message: >
        {% if trigger.entity_id == sensor.status_family %}
          {{ "All home." }}
        {% elif trigger.entity_id == sensor.status_jeppe %}
          {{ "Jeppe is home." }}
        {% elif trigger.entity_id == sensor.status_kitt %}
          {{ "Kitt is home." }}
        {% endif %}

Thank you very much for your inputs on this!
Cheers!

You need to encompass the sensor entity_id’s in single or double quotes to make them strings.

- alias: Notify - Presence Home
  trigger:
    platform: state
    entity_id: sensor.status_family, sensor.status_jeppe, sensor.status_kitt
    to: 'home'
  action:
    service: notify.pushoverjeppe
    data_template:
      title: "Hass.io - Presence Home"
      message: >
        {% if trigger.entity_id == 'sensor.status_family' %}
          {{ "All home." }}
        {% elif trigger.entity_id == 'sensor.status_jeppe' %}
          {{ "Jeppe is home." }}
        {% elif trigger.entity_id == 'sensor.status_kitt' %}
          {{ "Kitt is home." }}
        {% endif %}
2 Likes

Was about to post it… But you are faster…:blush:

1 Like

Ohh my, this has been bugging me for days. You are a legend! :smiley:

@dearlk you are as well :slight_smile:

No im not. Im just a new kid in the block…

1 Like

You could also make a map:

- alias: Notify - Presence Home
  trigger:
    platform: state
    entity_id: sensor.status_family, sensor.status_jeppe, sensor.status_kitt
    to: 'home'
  action:
    service: notify.pushoverjeppe
    data_template:
      title: "Hass.io - Presence Home"
      message: >
        {% set mapper = {
          'sensor.status_family':'All home.',
          'sensor.status_jeppe':'Jeppe is home.',
          'sensor.status_kitt':'Kitt is home.'} %}
        {{ mapper[trigger.entity_id] }}
1 Like

Could you elaborate on that? Is it a pushover feature or?

Cheers!

It’s not really a feature, it’s just using a dictionary to map known names to known responses. Dictionaries can be used for anything. So what it’s doing is using a key to map to a phrase. In this instance we are mapping the entity_id ‘sensor.status_family’ to the phrase ‘All home’. to extract the information out of the mapper, we use []. So we use the variable trigger.entity_id as the key to extract the information, because trigger.entity_id should be equal to ‘sensor.status_family’, ‘sensor.status_jeppe’, or ‘sensor.status_kitt’. You’ll run into issues if you don’t have a map for an entity id thats in the trigger. Only way for this to happen is if you add an entity_id to your trigger but not your map.

1 Like

Ahh. I see.
That’s a really neat way to do it. Thank you very much for you time and for extending the solution further and teaching me a new method.

You Sir, are great! :slight_smile:

1 Like