Show different images depending of sensors value

HA v0.101.3:
I would like to show different icon depending on the value a sensor has. The sensors values are 0, 1 ,2 and 3.
I though the picture-glance or picture.entity-card would be the solution, but I did not get it to run.

type: picture-entity
name: Homee
entity: sensor.homee_status
state_image:
  '0': /local/images/home.jpg
  '1': /local/images/away.jpg

But I see this error in the card configuration editor:
Expected a value of type `undefined` for `state_image` but received `{"0":"/local/images/off.jpg","1":"/local/images/on.jpg"}`.

The result is the same when I quote the values with single- or double quotes like “0”…

Following - I’d love to be able to more easily change icons (esp. if we could in Lovelace!). But, for now, I’m relegated to creating duplicate sensors and hand-crafting/creating the .png icon files from MDI…

    xc90_doors:
      value_template: >-
       {% if is_state('lock.xc90_door_lock','locked') %}
         Locked
       {% else %}
         Unlocked
       {% endif %}
      entity_picture_template: >-
        {% if is_state('lock.xc90_door_lock','locked') %}
            /local/lock-blue.png
        {% else %}
          {% if is_state('device_tracker.volvo_unknown','home') %}
            /local/lock-open-blue.png
          {% else %}
            /local/lock-open-yellow.png
          {% endif %}
        {% endif %}

This one reads the status of my Volvo integration door lock sensor lock.xc90_door_lock and then displays custom icons for me.

I’m seeing the same error on my picture-entity card that was once working.

Here’s my code:

type: picture-entity
entity: person.person1
state_image:
  home: /local/person1.png
  not_home: /local/person1_bw.png
Expected a value of type `undefined` for `state_image` but received `{"home":"/local/person1.png","not_home":"/local/person1_bw.png"}`.]

What’s weird is this is still working for person2 as shown:

type: picture-entity
entity: person.person2
state_image:
  home: /local/person2.png
  not_home: /local/person2_bw.png

Got it to run with:

type: horizontal-stack
cards:
  - entity: sensor.homee_status
    image: /local/images/unbekannt.png
    name: Homee
    show_name: false
    show_state: false
    state_image:
      '0': /local/images/home.png
      '1': /local/images/sleeping.png
      '2': /local/images/away.png
      '3': /local/images/vacation.png       
    type: picture-entity
2 Likes

Thanks for this solution, it worked great from me as well.