Template that includes a specific attribute of an entity

Hey guys,
i want to display a specific attribute of an entity in my dashboard.
How can i create a template sensor that has the “countdown” attributes of the following antity as a state or attributes?
Thank you!

stop_id: "8910"
stop_name: Feuerwache Am Steinhof
departures:
  - line: 46B
    direction: Wilhelminenberg
    platform: "1"
    time_planned: 2026-01-18T15:29:00.000+0100
    time_real: 2026-01-18T15:29:00.000+0100
    countdown: 13
    barrier_free: true
    folding_ramp: false
    type: ptBusCity
    disturbances: []
  - line: 46B
    direction: Wilhelminenberg
    platform: "1"
    time_planned: 2026-01-18T15:44:00.000+0100
    time_real: 2026-01-18T15:44:00.000+0100
    countdown: 28
    barrier_free: true
    folding_ramp: false
    type: ptBusCity
    disturbances: []```
{{ state_attr('sensor.example', 'departures') | map(attribute='countdown') | list  }}
1 Like

This works, thank you so much!!

Last question: I would like to add “min” as a suffix to the values, how would i do this in your code?

AFAIK, there’s no built-in function to iteratively append strings across a list, so one way to do it is use a macro and the apply function:

{% macro append(root,post)%}{{- root~post -}}{% endmacro %}
{{ state_attr('sensor.example', 'departures') 
| map(attribute='countdown') | map('apply', append, ' min') | list }}
1 Like

Awesome, thank you so much! I lied with “last question”, cause i have another one ^^

Your initial code gives back a list of 3 attributes, but i would limit it to just 2 values. Is this possible?

Sure, use list slicing

{% macro append(root,post)%}{{- root~post -}}{% endmacro %}
{{ ( state_attr('sensor.example', 'departures') 
| map(attribute='countdown') | map('apply', append, ' min') | list )[:2]  }}
1 Like

It’s possible to use regex_replace for that purpose.

{{ ( state_attr('sensor.example', 'departures') 
  | map(attribute='countdown') |  map('regex_replace', '(\d+)', '\\1 min') | list )[:2]  }}


Regex pattern explanation

(\d+) is a capturing group designed to grab any number of digits.

\\1 is a backreference that contains whatever was found by the first capturing group. Half the battle of getting this to work is knowing that Home Assistant’s flavor of regex uses a double-backslash for backreference.


EDIT

Corrected the regex pattern.

2 Likes