How display photo?

Hi,

I made a sensor, which contains the path and filename of a photo :

Now I want to display that photo, but this seems not to work…

type: picture
image: '{{ states(''sensor.random_photo'') }}'

Must be something stupid, but…

You are missing the fact that most core cards do not support templates.

Create a template image and put that in a picture entity card.

configuration].yaml

template:
  - image:
      - name: My Picture 
        url: "{{ states('sensor.random_photo') }}"

Card:

type: picture-entity
show_state: false
show_name: false
camera_view: auto
entity: image.my_picture
1 Like

I have a separate template.yaml file, how can I put it there ?

I tried this, but get an error :

- trigger:
    - platform: time_pattern
      seconds: "/10"
  sensor:
    - name: random_photo
      state: >
        {{ state_attr('sensor.photo_album', 'file_list')|random |replace("config/www","local") }}


- image:
    - name: My Picture 
      url: "{{ states('sensor.random_photo') }}"

image

The schema for the home assistant helper extension needs updating. I get the same warning in VSCode:

Untitled

Do a config check then restart if it passes.

I did forget one thing though. You need a trigger to update the image. e.g.mine:

- trigger:
    - platform: time_pattern
      minutes: "/30"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
  image:
    - name: Astroweather
      url: http://www.7timer.info/bin/astro.php?<redacted>

    - name: Cloud Cover +6hrs
      url: http://www.skippysky.com.au/Tasmania/cloud_total/tas_006_cct.png

    - name: Cloud Cover +12hrs
      url: http://www.skippysky.com.au/Tasmania/cloud_total/tas_012_cct.png

    - name: Cloud Cover +24hrs
      url: http://www.skippysky.com.au/Tasmania/cloud_total/tas_024_cct.png
      
    - name: Cloud Cover +33hrs
      url: http://www.skippysky.com.au/Tasmania/cloud_total/tas_033_cct.png

OK, it seems to work (I think) :

But it’s not displayed :

My sensor has the correct value :

image

Putting that value directly in the card works fine :

What am I missing ?

In Developer Tools → States, what do you see when you click on the “i” button next to the image entity?

And can you share your template config?

Nothing too :

image

Here are my templates :

- trigger:
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    - platform: time_pattern
      seconds: "/10"
  sensor:
    - name: random_photo
      state: >
        {{ state_attr('sensor.photo_album', 'file_list')|random |replace("config/www","local") }}


- trigger:
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    - platform: state
      entity_id:
        - sensor.random_photo
  image:
    - name: My Picture 
      url: "{{ states('sensor.random_photo') }}"

What does this return in the template editor:

"{{ states('sensor.random_photo') }}"

That’s a path not a url. Not entirely sure if that is supported.

Also do you have either:

default_config:

Or

image:

In your configuration.yaml file?

I have default_config

Changed the sensor and now it is working :partying_face:

    - name: random_photo
      state: >
        {{ state_attr('sensor.photo_album', 'file_list')|random |replace("/config/www","http://192.168.1.6:8123/local") }}

Thank you Tom !

1 Like