Dynamic entity

Hi,

i tried to use the same card for different content belonging to the value of another entity. Tried to do something like:

type: custom:mushroom-person-card
entity: person."{{ states('sensor.kuchendienst_heute')|lower }}

Didn’t work.
Is there any solution for these kind of contructs for the entity itself? I found solutions for styling and so on. For me the question is really about the entity attribute…

Thanks for any hints.

Use custom:config-template-card for this. Using this card you can create variable containing state of your sensor, manipulate it to add person prefix and then use this variable as entity in mushroom card. I use similar logic to determine last used media player (based on its state change) and then provide this as entity to card displaying media info. You can get a glimpse from code below:

type: custom:config-template-card
entities:
  - sensor.current_media # this is entity that template card will for state changes
variables:
  - states['input_select.media_players'].state # this is later referred as ${vars[0]}. Helper contain list of possible media players and selection is done by automation.
  - states[vars[0].replace('media_player', 'sensor') +
    '_album_description'].attributes.album_art # this is later referred as ${vars[1]}. This variable finally holds the URL to currently played album art from most recent madia_player used.
element:
  type: image
  image: ${vars[1]} # this is how above created variable is used in any card
...... # irrelevant part of card configuration

Please note that templates used in this card are JS, not jinja…