Using devices' zone to condition script run

I switched to NFC tags to open my garage doors when the interference from neighboring got too bad to ignore (or something else is happening).

It's so cool, it feels like magic. It works really well…almost too well though, so I'm trying now to add a zone condition to limit their reach.

The way I set them is the following:

Due to iOS's…well, you know, "quirks"—Let's say. Scanning tags would mean confirming those scans, which isn't great while driving. So I worked around it by instead having the tag mean nothing in Home Assistant but merely activate a shortcut in iOS, which in turn runs the script in Home Assistant that temporarily switches on a relay for the desired gate needed to open.

I can't tie specific devices or even cars to one person because we share them, so I need to evaluate dynamically the device use to activate the script. I'm not sure if I can use trigger evaluation because I believe this is considered a manual run, therefore there is no trigger.

I've been looking into templates, this required me to go through domains, entities, states and triggers (at the most recent). The closest I got to figuring it out was in states; they have a context attribute which has a user_id field. Maybe if I found some way to correlate that with that user's devices' most recent activity, which would have to be right at the moment when it's connecting to execute the script, maybe?, It's far from perfect, it has room for error, I have not the first idea of how I would go about it yet, but there's nothing that suggests to evaluate current connection origin*, that would be awesome…and wishful thinking—I don't know, I'm very lost here.

*: though I found the origin field in events, it's basically a boolean though, but it has context and therefore user_id and that should bring me closer to device_tracker. :crossed_fingers:

Could you point me out to the right direction please? I'll do my homework if need be.

Thanks!

Can you give a little more detail about the method you are using for this?

It would also be helpful to us if you download and share the json from the script's Trace. Make sure to obfuscate any personal information as needed.

please check ‘Fire Event’ as Home Assistant shortcut action in iOS. This allows you to add json dictionary with whatever parameter you want (like userID). Then you have a custom event trigger and you can use those parameters in HA automation.