Template configuration not working for me

Why doesn’t my template work? I do not understand why not. I have it in my sensors.yaml
I just want a different icon based on the status.

- platform: template
  name: "Room 1 mode"
  value_template: "{{ states('input_boolean.room1_mode') }}"
  icon_template: >- 
    {% if is_state("input_boolean.room1_mode", "on") %}
      mdi:radiator
    {% else %}
      mdi:radiator-disabled
    {% endif %}

Why are you using a template sensor instead of a binary template sensor?

It’s a binary value looking at your template.

It still should work as a sensor though, and I don’t see anything wrong with the configuration you have posted. Try it in the template editor, make sure you have the entity ids right.

I already tried the templates in the editor and everything is ok.

As for the binary sensor file, I just tried it and as opposed to sensors file at least my homeassistant starts normally. I pasted the same thing in the binary_sensor.yaml. But it still does not work. Here is what is says in the log:

Invalid config for [binary_sensor.template]: [value_template] is an invalid option for [binary_sensor.template]. 

Actually I just had a closer look at your config. It is not correct. You are missing sensors: and the map under it. As well as using name instead of friendly_name.

- platform: template
  sensors: 
    room_1_mode:
      friendly_name: "Room 1 mode"
      value_template: "{{ states('input_boolean.room1_mode') }}"
      icon_template: >- 
        {% if is_state("input_boolean.room1_mode", "on") %}
          mdi:radiator
        {% else %}
          mdi:radiator-disabled
        {% endif %}

This is the same for the template sensor or template binary sensor.

1 Like

Thank you this works now. I tried this format on sensors.yaml but there an error caused nothing to work, don’t know why.
Thank you.