Sensor value as a part of path to image

Hi, I need help with a simple configuration. I want to use a sensor to populate the path/filename of an image to show on my dashboard. Picture entity card or otherwise.

The sensor I have publishes an TitleId: for example “0100B7C00933A000”. I want to show a image with the path media-source://media_source/local/Server/TitleID.jpg
That would then translate to media-source://media_source/local/Server/0100B7C00933A000.jpg, or what ever that sensor value is.

I have tried a bunch of options but no luck, templating and such. Because the syntax has changed from a lot of the previous examples, I don’t know how to make this happen.

I appreciate any help with this basic config.
Thanks!

As far as a template goes this should work

# This concatenates the `media_content_id` string and sensor result in a template
media_content_id: "{{ 'media-source://media_source/local/your_media_directory/' ~ states('sensor.your_sensor_id') ~ '.jpg' }}"
# or, this inserts the template into the `media_content_id` string
media_content_id: "media-source://media_source/local/your_media_directory/{{ states('sensor.your_sensor_id') }}.jpg"

Thanks! Good advice I’m sure. I’ll read up on that.
Can I use this with a Picture Entity card? Or do I need to use some kind of media card?

I can solve it by using separate lines for each ID, but this is too much manual work:

show_state: true
show_name: true
camera_view: auto
fit_mode: cover
type: picture-entity
entity: sensor.nintendo_switch_k_current_game_title_id
state_image:
  0100d71004694000: >-
    media-source://media_source/local/Server/0100d71004694000.jpg
  01006e001823c000: >-
    media-source://media_source/local/Server/01006e001823c000.jpg
show_entity_picture: false

etc. etc.

The Picture Entity card does not have a media-source: option.

secondly it does not support templates. Not many core cards do.

Either use a third party card that does support templating or create a template image and display that entity in your dashboard.

Maybe you should give us a full picture of what you’re trying to do so that we can help you better, my advice is useless with the context you gave after my answer… See Rusty’s post.

I’ll read up more, for sure, thanks for your help. Super appreciated!
Gonna read up on your suggestions, but I’m not too familiar with yaml I’m afraid

I set up the integration Switch Assistant (GitHub - ErSeraph/switch-assistant: Switch Assistant connects your Nintendo Switch to Home Assistant through MQTT · GitHub)
And I have this sensor that provides the TitleID for the game that is currently being played. I want to show the Cover art for that game. I have scripted an export of all the images/covers for the games and named them the same as the ID that the sensor is presenting.
Now I need to show them whenever a game is played.

If you have any more pointers or maybe examples, I would love that. It makes learning way faster.

Thanks guys

What is the entity id of this sensor and in which directory are your images stored (e.g. config/lwww/titles/…)

The sensor is a MQTT sensor with entity id sensor.nintendo_switch_k_current_game_title_id
and the directory is a mapped network share. media-source://media_source/local/Server/

I’m almost certain that won’t work. They have to be stored locally.

The picture entity card can use media-source images (it’s there in the UI picker), but it doesn’t have the ability to use a templated ID.

A template image can generate a key from an ID, but I don’t believe template image have any access to media-source files, it can only generate a URL, and that will not have the appropriate authorization keys added.

So you might be stuck for the moment from the core side. It would probably be a good feature request to make though.

The closest you can get for now is to move all your images to the /www/ folder and reference them with template image.

I managed to solve all this using the Media-Source Image Card GitHub - luixal/lovelace-media-source-image-card: A Lovelace custom card for showing images stored in Media Source · GitHub

It supports media-Source and templating!

:smiley:

I find it kinda weird that templating isn’t supported everywhere. It should be a core feature.