Get device which triggered an automation or script and send a notification to it

Hi, I have a bunch of users registered in my Home Assistant and also some automations and scripts which send notifications. Right now I am using notification groups to send notifications to multiple devices. I am trying to find a way to send notifications just to the device which triggered the automation or script.

In case of an automation, there is the trigger.entity_id variable. But I can’t seem to send a notification to a device by its entitiy_id.

For scripts, I couldn’t find a way how to identify the device which triggered the script.

Is something like that possible in HomeAssistant?

Thank you in advance.

Look into context.user_id.

Thank you. I could find the notify service with this template

{{ states.person | selectattr('attributes.user_id', 'eq', context.user_id) | map(attribute='attributes.device_trackers') | first | map('replace', 'device_tracker.', 'notify.mobile_app_') | list }}

This template assumes that the device_tracker id and the notify service id have the same name at the end.

1 Like