I would say it is actually the template itself or now() (not sure, since I did not check the code) that is triggering the automation every minute to evaluate it, so per definition/documentation this should be available at the moment it is evaluated.
You can find this kind of solution all over the forum, so I am pretty sure it worked before.
Also with state_attr(this.entity_id, 'last_triggered') it is working correctly right now, just triggering log errors when editing.
I use this in event_data on an event trigger, though I added that code only like a week ago. This is on an automation trigger, not a wait_for_trigger. Pretty sure I tested this in a separate automation test case and it worked fine, though I never checked the logs for errors when editing the automation…
Edit: Here is a test case that shows this working in event_data of an event trigger. Traces shows that origin gets populated with this.entity_id and properly matched by the trigger.
Please post a link to the documentation indicating this is available for use in an automation’s triggers section.
Please post a link to a working example.
From personal experience, I have used this in conditions and actions but never in triggers. I know I once tried to use it in the trigger of a Trigger-based Template Sensor and it failed to work (it’s undefined). However, that’s not the exactly the same as for an automation.
BTW, I asked another Regular user to test the example I posted above and they reported the same result (this is undefined errors). They used 2025.1.0 and I used 2024.12.5 for the test.
Referencing this with your automation’s Template Trigger is clearly failing for you (and for me and for another person who tested it) on both the current version of Home Assistant and the previous one.
Mayhem_SWE reports that this is working in an automation’s Event Trigger.
We have conflicting reports for how this is being handled within an automation’s triggers section. It would appear that there’s a missing clue to explain the disparity.
event triggers are limited_templates only, I’ll review the code again, but I’m fairly positive that this will not work in any triggers (limited or not) inside an automation.
I am not stating that it is not working for me with state_attr(this.entity_id, 'last_triggered'), there is a screenshot with the trigger successfully firing.
Right now I am just making aware of the fact that it triggers log errors, which should be fixed in my opinion. The trigger seems to fire on now() every minute and only then is evaluated, after which this should be available as per documentation.
The now() within the template caused it to be evaluated every minute, and every time it attempted to evaluate the template, it failed to be successful because this was reported to be undefined.
Is that what you mean by “successfully firing”?
Or do you mean that at some point in the template’s evolution (because it has clearly changed from what’s shown in your first post to later posts) the Template Trigger actually served to trigger the automation and produce a trace?
It explains why the original template shown in the OP’s first post was subject to the error (it referenced attributes) whereas later, when the template was modified to NOT use attributes, its behavior changed. It also explains why this.entity_id works for Magnus.