(How) is it possible to get the Entity that triggered an Automation, in a Script called from that Automation?
In the Automations, i can append Data to the call of each Script, and hand over the {{ trigger.entity_id }} by that.
But (how) is it natively possible to evaluate inside the called Script, what triggered the Automation before?
More Context:
I want to streamline my growing Notifications from HA. Depending on Devices and their Values, different notifications get fired.
E.g. if the Temperature in the Freezer is higher that -16°, all Users get a a silent Notification.
If it stays higher than that for more than 30 Minutes, an Alarm gets triggered.
If the Sensor renders âunavailableâ, the Admin gets another (repeating) Notification.
There are many Notifications and even more to come. So it would be great if i would only have to call the corresponding Script, which know what Entity / State triggered the Automation before.
sequence:
- service: notify.level1_users # or whatever your notification service is called
data:
message: " The sensor {{ trig_id }} has the value {{ trig_val }}"
But as i want to call that generic Script from a lot of different Automations:
Edit:
I thought there might be possibilities with context, parent,⌠But i just donât get the Concept, and blindly tested State objects - Home Assistant werenât successful.
Then in your script you should be able to access the properties of that object:
sequence:
- service: notify.level1_users # or whatever your notification service is called
data:
message: " The sensor {{ trig_object.entity_id }} has the value {{ trig_object.to_state.state }}"
Totally untested. May not work.
As for the previous trigger object properties, you will have to store them globally somehow. Either by publishing to an mqtt topic or by using this trick (read the whole rest of the topic):
Too bad Thank you very much for instant clarifiing! Saves me a lot of Time for DiggingâŚ
Really interesting how creative ppl get!
I thought about doing it the âcheapâ way - updating Helper in the Automation, and react on those.
Or i might come back to my first thought, and continue with (trying to) Blueprint that, namely baked-in data passing to the Script.
Thank you so much for both your instant and clear Clarification, and possible Solutions!