Picture card with dynamic image

I want a picture card with the following:

type: picture
image: /local/snaps/snapshot-camera-voorkant-{{ states('counter.camera_voorkant_snapshot_counter') }}.jpg?raw=true
alt_text: Snapshot bewegingsdetectie

However the dynamic part (the state of the counter) doesn’t work. Is there a way to make this work?

The image is string so you can’t use templates there.
What you can do is to link to a static image/webpage and then replace the image on that image/webpage.

If you are trying to display the most current snapshot on your dash AND the counter resets after x amount of snapshots, you can use local file entities with conditional cards. Where each snapshot had it’s own local file entity. If the counter just continues to increase this will not work.

Use the counter as the entity in the conditional card. If the counter was at 5 you would use

image

It would display the card with snapshot 5 and hide the others.

First thanks for all the replies.

I have solved it in another way using the Gallery-card. The YAML is this:

type: custom:gallery-card
title: Laatste 10 snapshots
entities:
  - sensor.snaps
menu_alignment: Bottom
maximum_files: 10
caption_format: ' '

The sensor.snaps is a folder item in my configuration:

sensor:
  - platform: folder
    folder: /config/www/snaps

The script is as follows:

service: camera.snapshot
data:
  filename: >-
    '/config/www/snaps/snapshot-camera-voorkant-{{
    states("counter.camera_voorkant_snapshot_counter") }}.jpg'
target:
  device_id:

I now added the following to the configuration:

homeassistant:
  allowlist_external_dirs:
    - /config
  whitelist_external_dirs:
    - /config

And this allows the automation to store the files in the snaps folder.

Kind regards,
Jeroen

Unless something has changed www did not need to be added to the allowlist_external_dirs. It is shared by default. I don’t have it in my allow list and I was able to add the sensor and write to a file in a sub directory of www. Perhaps remove the entry from allowlist_external_dirs.

If things haven’t changed /www is not a good place to store photo as it is not protected by HA’s auth system. I use /media for snapshot storage, that path needs to go in the allow list.