Template to get a list of entities matching name pattern

I want to make a History Graph dashboard panel showing all device tracker entities. The trick is, I want it to stay up to date automatically, as more entities are added over time. Is this possible using a jinja template? I can get a list of entities like this:

{{ expand(states) | select("match", ".*device_tracker.*") | list }}

That returns a list of TemplateState objects. So I’m looking for a way to converter that into a list of entity ID strings, so I can insert it like this:

type: history-graph
entities:
  - {{ list of entities}}
{{ expand(states.device_tracker) | map(attribute='entity_id') | list }}

However, none of the official Cards (except for the Markdown Card) supports the use of Jinja2 templates. So you cannot use a template where you indicated in the history-graph example.

FWIW, some custom Cards support templating but I am not familiar with a custom version of the History Graph card.

What/which information from the device tracker are you referring to ?, You do know there are quite some “details” OF Various sort !
Which you in no way can show in a History graph, unless it would be Humongeous
Or is it just the entity-name and state home/not_home ?

BTW: your template, does first expand ALL states, then match to a name(device_tracker), and list all device_trackers And ALl it’s attributes

You don’t want that in 1 Graph, even if you could, Yes you “potentially” could “follow” their “Changes” … if you are “quick” enough, and your electrical bill will rize, well until your HA or disk gets “Tired”

{% for state in states.device_tracker -%}
  {{ state.name }}: {{ state.state }}
{% endfor %}

This will give you name/state , but as Taras say, nothing you can use in History_card, directly

Oh shoot. I was hoping templates could be used anywhere. Thanks for the tip, this is the code I was looking for, but yeah it doesn’t work.

type: history-graph
entities:
{% for state in states.device_tracker -%}
  - {{ state.entity_id }}
{% endfor %}

I’m interested to see how many BT devices pass by my house, and also to learn more about how some BT devices randomize their MAC address. I guess Home Assistant is not the right tool for this, I just thought it might be an easy starting point.

type: custom:auto-entities
card:
  type: history-graph
filter:
  include:
    - domain: device_tracker
2 Likes

I Had/have in my Edit-above :wink: , but removed it, bc i was really not sure what Elliot want, nor how

1 Like