Change entity picture if I turn on a switch, run a script, scene etc?

Is it possible to change the entity picture if I turn on a switch, run a script, scene etc?

I’ve seen people doing it with icons for battery states (charging, not charging, charge percentage), and I’m just wondering if it’s possible to adapt something like that to my use case?

For example with this switch that turns on different scenes:

- platform: template
  switches:

    office_light_custom:
      value_template: "{{ is_state('office_light_custom', 'on') }}"
      turn_on:
        - service: scene.turn_on
          entity_id: scene.office_light_100
      turn_off:
        - service: scene.turn_on
          entity_id: scene.office_light_off

Is it possible when the switch is on to use:

entity_picture: /local/[email protected]


And when switched off to use (or just have this as the default icon):

entity_picture: /local/[email protected]

You can use icon_template for that.

icon_template (Optional): Defines a template for the icon of the sensor.

Example:

sensor:
  - platform: template
    sensors:
      day_night:
        friendly_name: 'Day/Night'
        value_template: '{% if is_state("sun.sun", "above_horizon") %}Day{% else %}Night{% endif %}'
        icon_template: '{% if is_state("sun.sun", "above_horizon") %}mdi:weather-sunny{% else %}mdi:weather-night{% endif %}'

For more info look here:

1 Like

Ah, so this works with ‘entity_picture’ as well, not just ‘mdi-icon-whatever’?

Thanks, I’ll look at this.

OK, I tried the code below and it didn’t work :disappointed:
(With and without quotes around ‘entity_picture: /local/[email protected]’ .)

- platform: template
  sensors:
    jays_desk_lamp_icon:
      value_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on")) %}On{% else %}Off{% endif %}'
      icon_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}"entity_picture: /local/[email protected]"{% else %}"entity_picture: /local/[email protected]"{% endif %}'

Any ideas on how to get it working?

Skip the “entity_picture” part.

I tried this below. It didn’t show any errors, but didn’t show any of the images either

- platform: template
  sensors:
    jays_desk_lamp_icon:
      value_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}On{% else %}Off{% endif %}'
      icon_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}/local/[email protected]{% else %}/local/[email protected]{% endif %}'

If you use the mdi icons it will work, I believe.

I use automation to turn on/off visibility of a group with one entity in it. The picture of the group is set but I think there is probably a way to have a on group and different off group for each entity. Its not the solution you were looking for but its a complicated alternative.

1 Like

Yeah, I realise that. But I’m wanting to change ‘entity_picture’ not mdi icons, hence the title :slight_smile:

Yeah, thanks but that’s not what I’m after.

I think you cannot do what you want atm hence my reply, maybe put a change request in and let people vote on it? I would probably vote for it :smiley:

1 Like

Yeah, I agree. I don’t think it would be possible at the moment.

I might put it in as a feature request :slight_smile:

@RobDYI can you please let me know how to show time history as it showing under Outside Motion Alert “1 second ago”?

Thanks

Check this out

This is exactly what I am trying to accomplish did anyone get it done?

No, I never managed to do it.

…actually, I’ve just found out how to do this :slightly_smiling_face:

If you look at this info on Template Switches (bottom of the page) you can use ‘entity_picture_template’ to change the images.

This is what I have but does not seem to change the icon to entity

sensor.moon:
  friendly_name: Moon
  entity_picture_template: >-
    {% if is_state('sensor.moon', 'New moon') %}
      /local/images/new-moon.png
    {% if is_state('sensor.moon', 'Waning crescent') %}
      /local/images/waning-crescent-moon.png     
    {% if is_state('sensor.moon', 'Waxing crescent') %}
      /local/images/waxing-crescent-moon.png
    {% endif %}

That looks wrong to me, it should look like this…

sensor:
  - platform: template
    sensors:
      moons:
        friendly_name: "Moon Type"
        entity_picture_template: >-
          {% if is_state('sensor.moon', 'New moon') %}
             /local/images/new-moon.png
          {% elif is_state('sensor.moon', 'Waning crescent') %}
             /local/images/waning-crescent-moon.png     
          {% elif is_state('sensor.moon', 'Waxing crescent') %}
             /local/images/waxing-crescent-moon.png
          {% endif %}

Remember you can check these in the template editor :slight_smile:

- platform: template
  sensors:
    moon_phase:
      friendly_name: "Moon Phase"
      value_template: >
        {% if is_state('sensor.moon', 'New moon') %}
           'New Moon'
        {% elif is_state('sensor.moon', 'Waning crescent') %}
           'Waning Moon'     
        {%elif is_state('sensor.moon', 'Waxing crescent') %}
           'Waxing Moon'
        {% endif %}
      entity_picture_template: >
        {% if is_state('sensor.moon', 'New moon') %}
           /local/moon_new.png
        {% elif is_state('sensor.moon', 'Waning crescent') %}
           /local/moonwane.png     
        {%elif is_state('sensor.moon', 'Waxing crescent') %}
           /local/moonwax.png
        {% endif %}

image

1 Like