Wrong entity_picture showing while template is correct...?

HI,

have this template switch:

switch:
  - platform: template
    switches:
      audio_system:
        friendly_name: Audio system
        value_template: >
          {{ is_state('switch.sw_tv_auditorium_cl', 'on') }}
        turn_on:
          service: script.turn_on
          entity_id: script.audio_on
        turn_off:
          service: script.turn_on
          entity_id: script.audio_off
        entity_picture_template: >
          {% if is_state('switch.audio_system','on') %} /local/activities/hometheater.png
          {% else %} /local/activities/book.png
          {% endif %}

switch is on and both templates evaluate correctly:

the switch shows with the wrong picture though:

46

and dev-state says:

turning it off shows the picture for on:

24
can you spot the error here?

I dont think you can use the template sensor itself as a template for the icon. I think you should use the actual switch.

        entity_picture_template: >
          {% if is_state('switch.sw_tv_auditorium_cl', 'on') %} /local/activities/hometheater.png
          {% else %} /local/activities/book.png
          {% endif %}
1 Like

will test of course, but I do that with many other templates without issue. Also imagine creating another sensor with this template, it would still have to reflect the correct state…

seems I mixed up the on/off somewhere in either of the templates?

In that case, you are right. It just didnt make sense when I thought of it.
Check your scripts and their names. Are they accidentally flipped? Maybe the one turning the switch to on, is actually off?

Don’t think so:

  audio_on:
    sequence:
      - service: switch.turn_on
        entity_id:
          - switch.sw_tv_auditorium_cl
          - switch.subwoofer_outlet
      - delay:
          seconds: 5
      - service: switch.turn_on
        entity_id: switch.sw_audio_auditorium_cl

  audio_off:
    sequence:
      - service: switch.turn_off
        entity_id:
          - switch.sw_tv_auditorium_cl
          - switch.subwoofer_outlet
      - delay:
          seconds: 5
      - service: switch.turn_off
        entity_id: switch.sw_audio_auditorium_cl

@argykaraz

it did help, though I find it a bit unpredictable why in this case calling the switch itself turns the value around…

when I use custom-ui, things work out as expected:

switch.audio_system:
  show_last_changed: true
  # state_card_mode: badges
  templates:
    theme: >
      if (state === 'on') return 'green';
      return 'brown';
    friendly_name: >
      if (state === 'on') return 'Enjoying Home theater';
      return 'Enjoying Silence';
    entity_picture: >
      if (state === 'on') return '/local/activities/hometheater.png';
      return '/local/activities/book.png';

23
32

will make an extra tile out of this. thanks for your help

1 Like