Custom Images for Entities in Lovelace Entity Card

I’ve been using the template platform for sensors to create little images inside of the UI circles that change when the state of the underlying entity changes.

Those sensors don’t control the entities, however.

Is there a way to use entity_picture_template to customize any entity? It seems that the only entities that respond to the entity_picture_template are sensors.

The goal is to add the entities to an entity card in Lovelace with more than just an Icon to indicate On or Off, etc. I’d like the actual PNG file that I’ve created for on/off status to be displayed in the card instead of the mdi:icon.

are you referring to the basic entity card? This type of customization depends on the card and the basic entity card just emulates a normal card in home assistant.

If you want crazy image customization and placement, I suggest the picture elements card. You can pretty much do whatever you want.

Currently, I have binary_sensors to detect is a device_tracker is home or away solely for the purpose of adding a small circle with a picture of the person in it. When they are here, the picture is in color. When they are not here, it is black and white.

It doesn’t seem to be that I can do this with any entities other than sensors. If I add any entities card to Lovelace, they default to one of the MDI icons unless it’s a sensor.

There doesn’t seem to be, through customize.yaml, a way to use images to customize the entity icons (like the sensors in the normal UI). The problem with that is that a sensor doesn’t offer direct control of the entity that is sensed.

Pulled directly from the link I sent you in the picture element card that does exactly what you want:

IMAGE ELEMENT
CONFIGURATION VARIABLES
type
(string)(Required)image

entity
(string)(Optional)Entity to use for state_image and state_filter and also target for actions.

tap_action
(string)(Optional)none, more-info, toggle, navigate, call-service

Default value: more-info

navigation_path
(string)(Optional)Url path to navigate to (e.g. /lovelace/1)

service
(string)(Optional)Service to call (e.g. light.turn_on)

service_data
(object)(Optional)The service data to use.

image
(string)(Optional)The image to display.

camera_image
(string)(Optional)A camera entity.

state_image
(object)(Optional)State-based images

filter
(string)(Optional)Default CSS filter

state_filter
(object)(Optional)State-based CSS filters

style
(object)(Required)Position and style the element using CSS.

Default value: position: absolute, transform: translate(-50%, -50%)

more specifically:

state_image
(object)(Optional)State-based images

Here is example config of said object:

    - type: image
      entity: light.bed_light
      tap_action: toggle
      image: /images/light_bulb_off.png
      state_image:
        'on': /images/light_bulb_on.png
      state_filter:
        'on': brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)
        'off': brightness(80%) saturate(0.8)
      style:
        top: 35%
        left: 65%
        width: 7%
        padding: 50px 50px 100px 50px

But what if I have more entities
for example, light.bed_light1 and light.bed_light2
A chi solve their states in one card:

When light.bed_light1 and light.bed_light2 is OFF then image_off.jpg
When light.bed_light1 is ON and light.bed_light is OFF then image 1-ON.jpg
When light.bed_light1 is OFF and light.bed_light is ON then picture 2-ON.jpg
And finally when is ON both light.bed_light1 and light.bed_light2 then image_ON.jpg

I don’t know how to write this can anyone advise me?
Thanks

You can’t do that without custom cards.

I have done something similar for a fridge freezer picture showing if the fridge door, freezer door or both are open.

First, I set up a sensor:

    fridge_status:
      friendly_name: "Fridge Status"
      value_template: >-
        {% if is_state('binary_sensor.fridge', 'on') and
        is_state('binary_sensor.freezer', 'off') %}
          fridge
        {% elif is_state('binary_sensor.freezer', 'on') and
        is_state('binary_sensor.fridge', 'off') %}
          freezer
        {% elif is_state('binary_sensor.freezer', 'on') and
        is_state('binary_sensor.fridge', 'on') %}
          both
        {% elif is_state('binary_sensor.freezer', 'off') and
        is_state('binary_sensor.fridge', 'off') %}
          closed
        {% else %}
          none
        {% endif %}

Then in a picture elements card:

  - type: image
    entity: sensor.fridge_status
    image: /local/images/fridge-and-freezer-closed.png
    state_filter:
      "unavailable": grayscale(100%) drop-shadow(0px 0px 2px Red)
      "fridge": drop-shadow(0px 0px 2px LightBlue) saturate(200%)
      "freezer": drop-shadow(0px 0px 2px LightBlue) saturate(200%)
      "both": drop-shadow(0px 0px 2px LightBlue) saturate(200%)
    state_image:
      "closed": /local/images/fridge-and-freezer-closed.png
      "fridge": /local/images/fridge-open.png
      "freezer": /local/images/freezer-open.png
      "both": /local/images/fridge-and-freezer-open.png
    style:
      top: 28%
      left: 90%
      width: 10%

icons8-fridge-80 icons8-fridge-and-freezer-open-80 icons8-fridge-freezer-open-80 icons8-fridge-fridge-open-80

1 Like

fridge sensor is introduced into /config/configuration.yaml ???
Then a picture elements card created in HA?
Do I understand correctly?

Yes that’s it, the fridge_sensor is in configuration.yaml under

sensor:

Thank you everything works I still need to resolve a fixed address for the pictures.
I have HA on Synology and /local/…/picture/xy.png doesn’t work.
Otherwise, thank you very much for your help
The sensor and card work great

Thanks for your example, but doesn’t work on my side…It keeps asking for an image

Try quotes around all your states

"gft": 
"restafval":

etc

Assume you have saved those images in the www folder ?

I edited the card through Configuration > Lovelace-dashboards > YAML-editor.
When surrounding the states with quotes they disappear as soon as I hit ‘save’.

And yes, the images are in the www/afval folder

The style: is missing

At the bottom I added an extra image, which is probably the image the elements are placed on. I my case just a square white rectangle. Thereafter styled the image…

image

type: picture-elements
elements:
  - type: image
    entity: sensor.afvalwijzer_today
    name: Vandaag
    state_image:
      gft: /local/afval/kliko_groen.png?v=1
      restafval: /local/afval/kliko_grijs.png?v=1
      pmd: /local/afval/kliko_pmd.png?v=1
      Geen: /local/afval/kliko_geen.png?v=1
    style:
      top: 5%
      left: 5%
      right: 1%
      width: 50%
      transform: 'scale(.5,.5)'
  - type: image
    entity: sensor.afvalwijzer_tomorrow
    name: Morgen
    state_image:
      gft: /local/afval/kliko_groen.png?v=1
      restafval: /local/afval/kliko_grijs.png?v=1
      pmd: /local/afval/kliko_pmd.png?v=1
      Geen: /local/afval/kliko_geen.png?v=1
    style:
      top: 5%
      left: 55%
      right: 10%
      width: 50%
      transform: 'scale(.5,.5)'
image: /local/afval/kliko_back.png