Are you triggering the automation by listening for the tag_scanned event? If so you do get a device_id associated with that but as far as I know there’s no dynamic way to link a device_id to a specific device unless you possibly monitor the config files so you’d have to manually create a table associating each device_id with the correct device name. I would consider that hard coding it, so the below method is much better in my opinion. The only prerequisite is that the mobile users be logged into a user with a person associated with them, and the device they’re using is set as a device tracker for their person entity. This is pretty much the default whenever you add a new user and the companion apps automatically add the device as a tracker when they first log in.
What will work in any automation triggered by a user no matter the type would be to check for the user_id in the trigger context. This allows you to figure out the person entity that triggered the automation.
Once you’ve taken the user_id and linked it back to the correct person entity, you can look at the entity’s associated device trackers. Now that you have the device_tracker entities, you can attempt to call the notify service for each companion app device.
This relies on you linking the devices to their user as device trackers, which you have likely already done. You can also link more than one device if you’d like to notify multiple personal devices.
This template here gets the the person entity of the associated user,
person_entity = {{ (expand(states.person) | selectattr('attributes.user_id','==',trigger.event.context.user_id) | first).entity_id }}
That’ll give you a person entity_id such as person.alex
From there you can grab the tracker device entities
{{ state_attr(person_entity , "device_trackers") | map("lower") |
map("replace", "device_tracker.", "notify.mobile_app_") | list }}
This converts your device_tracker entity_id to the best guess for the notify service, one issue that could exist is that you could have dedicated device tracker devices that don’t have a notify service linked to them, but that’s pretty rare and more than likely this will be from your companion app which should work.
From here, you have a list of the notify service names for each device associated with the user who triggered the automation, you can use this list in a repeat for each
building action inside the automation with the list as the repeat item. From there you can have a service call action inside the repeat block which takes in the action
line, action: "{{repeat.item}}"