I’m trying to create a template for speech output that uses a variable to get the relative time since the user’s status changed.
The template below works fine, but it’s not dynamic.
{% if is_state("device_tracker.beth", "home") %}
Beth is home
{%-else -%}
Beth left {{relative_time(states.device_tracker.beth.last_updated))}} ago
{%-endif%}
I can dynamically check the status of someone with
{% set user = "beth" %}
{% if is_state("device_tracker." + user, "home") %}
but I can’t figure out how to then dynamically get the last_updated variable and pass it into the relative_time function