Template inside a Picture Entity Card

For my frontdoor I’m working on a way to see who rang the doorbell. First I set an input_datetime and use this to store the image and to display the image.

service: input_datetime.set_datetime
target:
  entity_id: input_datetime.deurbel_history_1
data:
  timestamp: '{{ now().timestamp()|int }}'
service: camera.snapshot
target:
  entity_id: camera.voordeur
data:
  filename: >-
    /config/www/camera_voordeur/voordeur_{{
    (state_attr("input_datetime.deurbel_history_1","timestamp")) }}.jpg

Images are stored locally with the timestamp. An example of an image is:
https://XXXXXX.duckdns.org:8123/local/camera_voordeur/voordeur_1620338171.0.jpg

So far everything is working.

I was trying to get a picture entity card to display the latest image. Unfortunately I can’t seem to get the template working. It works in developer tools but it will not in a picture entity card.

type: picture-entity
image: >-
  /local/camera_voordeur/voordeur_{{
  (state_attr("input_datetime.deurbel_history_1","timestamp")) }}.jpg
entity: input_datetime.deurbel_history_1
show_name: false

Got it working by creating a camera to display the image:

camera:
  - platform: generic
    name: Deurbel_history_1
    still_image_url: https://XXXXXX.duckdns.org:8123/local/camera_voordeur/voordeur_{{ (state_attr("input_datetime.deurbel_history_1","timestamp")) }}.jpg

This can now be displayed with a Picture Entity card:

type: picture-entity
entity: camera.deurbel_history_1
camera_image: camera.deurbel_history_1

Also had to change the timestamp to an INT in the post above. For some reason th etimestamp is not the same when you write it compared to when you read it to fetch your image (looks like a bug).

2 Likes