Here are some snippets from what I do.
Note the action_data
here from my one automation:
- service: notify.mobile_app_xxx
data:
title: "Security"
# timer.rhs_garage_door_timer -> XXX's garage door
message: >-
{% set name = None %}
{% if trigger.event.data.entity_id | regex_search("lhs", ignorecase=True) %}
{% set name = "YYY's garage door" %}
{% elif trigger.event.data.entity_id | regex_search("rhs", ignorecase=True) %}
{% set name = "XXX's garage door" %}
{% else %}
{% set name = "The main gate" %}
{% endif %}
{% set cover_entity = trigger.event.data.entity_id | replace('_timer', '') | replace('timer.', '') %}
{% set cover_last_changed = states["cover"][cover_entity].last_changed %}
{{ name }} has been left open for {{ ((as_timestamp(utcnow()) - as_timestamp(cover_last_changed) + 5) // 60) | int }} min.
data:
apns_headers:
# group notifications by the timer entity
'apns-collapse-id': "{{ trigger.event.data.entity_id }}"
push:
category: "cover_open"
action_data:
# convert this to the cover entity to use in the automation that receives this
cover_id: "{{ trigger.event.data.entity_id | replace('_timer', '') | replace('timer', 'cover') }}"
timer_id: "{{ trigger.event.data.entity_id }}"
And in another automation this is how I access it:
- service: cover.close_cover
data:
entity_id: "{{ trigger.event.data.action_data.cover_id }}"
In my case, I have a timer that starts if the main gate or garage doors are opened. After the timeout, it will send a notification and in that notification I need to know which entity triggered it. I think this is similar to what you need.