How do I display an image with the path stored in a sensor?

With the very elegant solution by @123 here I have a sensor now that contains the path to the image I want to display, but how do I get it displayed? With the elegance in the sensor, I don’t want to spoil it all by using state images, as it already has the image name stored inside it.

The value of the sensor is:

/local/imageX.jpg

I’ve tried a few things with picture card

image: {{ sensor.sensor_image }}
image: {{ value.sensor.sensor_image }}
image: {{ states.sensor.sensor_image }}

But none of them displays the image, and the gui shows:
Expected a value of type string | undefined for image but received {"[object Object]":null}.

I can write the image path directly, so the images are there.

2 Likes

I would first play in the image dev template and see if i get the right value from it. You can also just do the full url instead of a local load (presuming that is what it does now)

1 Like

try
image: [[[ return states['sensor.sensor'].attributes.entity_picture ]]]

Anyone know how to do this? I tried KEM_Hass’s solution in my lovelace raw config and it just moaned about a missing comma in the YAML validation and wouldn’t let me save.
Thanks

did you have any solution? I have a similar problem

1 Like

The way I have it set is like this:

entity: sensor.koleskab_image
image: /local/samsung0.jpg
show_name: false
show_state: false
state_image:
  '0': /local/images/fridge-samsung0.png
  '1': /local/images/fridge-samsung1.png
  '2': /local/images/fridge-samsung2.png
  '3': /local/images/fridge-samsung3.png
type: picture-entity

Not very elegant…

I would love to be able to show an image with a ‘templated’ path like
/local/images/fridge-samsung{{ states(‘sensor.koleskab_image’) }}.png
But it doesn’t work…

1 Like

Thank you for this i made a sensor which took the baseurl+state(sensor.symbol)+.png
the string is the correct url but image can’t use it the cdn i’m getting images from has at least 80 weather icons probably more but your solution is the only one I have found that works it’s a real shame there seems to be no way to just change the url path for the image with a sensor state other than this method.

Hello @fribse ,

I have something similar to your request. Maybe you can aplly the same conf like me. But with my conf, the log of system shows me an error, but is working well at the end.

I have a sensor to show me the Moon phases with PNG images, and my sensor is this:

  • platform: template
    sensors:
    fase_lunar_imagen:
    friendly_name: ‘Fase Lunar’
    value_template: “{{ states.sensor.fase_lunar.state }}”
    entity_picture_template: " /local/moon_phases/{{ states.sensor.fase_lunar.state }}.png "

Maybe is not the best way to do it, but is complicated for me understand sometimes the language sentences.

In the above example, be careful with spaces, because are wrong, but the code is ok

1 Like