I spent a while looking for an easier way to dynamically select an entity to show in a dashboard based on a template (i.e. based on other state/computation) – an indirect reference to an entity, if you will. My use case was that I have sensors that track the entity_id of the camera of each of the last 5 recognized objects from my 30+ cameras and want to show a custom card for each of those 5 cameras in that sliding window of events. Using 5 condition cards and repeating the 30 cameras each time could’ve worked but obviously would’ve needed to be YAML that I generated programmatically (which I do plenty, but seemed wrong here).
This is what I came up with using custom:auto-entities
's template and custom:layout-card
to turn the entities:
list from auto-entities
into a single custom card of my choosing for the dynamically-selected entity.
- type: custom:auto-entities
card:
type: "custom:layout-card"
card_param: cards
filter:
template: >-
{{{ "entity": state_attr('sensor.camect_latest_event', 'cam_entity_id'),
"type": 'custom:camect-card' }}},
I’m posting to both share this technique – which seems plenty general and useful – and also to ask if there’s a better way. I’m pretty confident that there should be a better way as simple things should be simple and although I’ve made this fairly idiomatic, it’s nuanced compared to just being able to specify an entity with a template directly.
Feedback?