Simple templating question for last_changed

Can I template the last changed attribute of an entity_id?

e.g. If I pass a script a variable which is an entity_id can that script then determine the last changed value for that entity?

service: script.my_script
data:
  triggered_by: trigger.id

In script.my_script is there a correct syntax to do this?

- condition: template
  value_template: >
    {% set last_changed = states.triggered_by.last_changed %}

Use bracket notation:

- condition: template
  value_template: >
    {% set last_changed = states[triggered_by].last_changed %}
...
1 Like