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

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

Awesome thank you! Where are you getting your moon png’s from I like them better than mine lol

I just did a google search for phases of the moon pictures :slight_smile:

can this be used in the customize section to modify an existing binary sensor or do I have to create a template sensor for it to work?

No idea I just used a template sensor :slight_smile:

Alrighty then. Thanks!

I just gave it a try by creating a template binary sensor.

It didn’t work but I’m not sure why.

Here is the code in my binary_sensors.yaml:

- platform: template
  sensors:
    n_gd_pos_template:
      friendly_name: "North Garage Door Position"
      device_class: opening
      value_template: "{{ is_state('binary_sensor.garage_door_north_position_sensor', 'on') }}"
      entity_picture_template: >
        {% if is_state('binary_sensor.garage_door_north_position_sensor', 'off') %}
          /local/my-garage-closed.png
        {% elif is_state('binary_sensor.garage_door_north_position_sensor', 'on') %}
          /local/my-garage-open.png
        {% endif %}
      extra_data_template: Battery Level ${(entities['sensor.batt_garagedoor1'].state)}%

I ran the template through the checker and it came up with the correct response so I know that part is good.

I get this error in the log:

2018-02-11 17:26:20 ERROR (MainThread) [homeassistant.config] Invalid config for [binary_sensor.template]: [entity_picture_template] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->sensors->n_gd_pos_template->entity_picture_template. (See ?, line ?). Please check the docs at https://home-assistant.io/components/binary_sensor.template/

I’ve checked the docs and according to that “entity_picture_template” is indeed a valid option:

Am I missing something here?

Try getting rid of the above line? Other than that I don’t see where yours is different from mine.

Yeah I already tried that. Neither way works.

Looks like I need to keep digging…

The only other thing that’s different is the device_class line.

The docs say that is OK too but I removed that line just to be sure.

Same result.

It needs to be in sensors not binary_sensors maybe?

Both should support entity_picture_template. At least according to the docs…:confused:

I tried it anyway…

same result only now the error is in sensor not binary_sensor

2018-02-11 18:46:54 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.template]: [device_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->n_gd_pos_template->device_class. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

EDIT: never mind different error…

Last thing I can think of is the - in the png name, try it with an underscore, after that I’m out of ideas :stuck_out_tongue: