Icon_template does not change icon?

Hi, I’m trying to change the icon in my binary sensors but this doesn’t seem to work? Can I have your input please?

- platform: template
      value_template: '{{ is_state("input_boolean.issleep","on") }}'
      icon_template:'{% if is_state("binary_sensor.issleep","off") %} mdi:sleep-off {% else %} mdi:sleep{% endif %}'
      friendly_name: 'Sleeping'
  payload_on: 'True'
  payload_off: 'False'

I’m not good at those so this might not be the issue, but aren’t you missing a single quote to end the icon_template line?

Yes, that got lost when I pasted the coded. It’s there in the code :slight_smile:

Hmm, try testing the icon_template line against “False” instead of “off” and see if it helps.

This is my reasoning:

This generates a value that is True or False

value_template: ‘{{ is_state(“input_boolean.issleep”,“on”) }}’

But here you check if it’s value is ‘off’ or if it’s something else:

icon_template:‘{% if is_state(“binary_sensor.issleep”,“off”) %} mdi:sleep-off {% else %} mdi:sleep{% endif %}’

And since off is never the same as either True or False, the icon should only be mdi:sleep.