Template /helper - here we go again

Ok, since I wanted to move my existing templates to helpers and need to start all over I have to (re)create my entities…

Now I have a helper which is a binary_sensor and I need the icon to change from a mdi:radiobox-blank (default?) to a mdi:radiobox-marked…

But I cant get it working and I don’t know where to start or look. Please give me a push in the right direction…

i have tried a lot but this sees the most feasible:

icon_template: >-
  {% if is_state('switch.tuin_klep_uitgang_tuinslang', 'on') %}
    mdi:radiobox-marked
  {% else %}
    mdi:radiobox-blank
  {% endif %}

What is the way to chae an icon based on state (on / off)?

You’re trying something, that’s not possible in this way, unfortunately. :slight_smile:

icon_template is not available under the “new” template format. It would have been possible with the old, legacy format, but that’s not what you get, when you set it up via GUI.

You’d need to define that sensors in the old format in YAML, or you take the new format.

See here for the new format:

And here for the “old”, legacy helpers:

Yes think I am slowly finding out:

It’s not that you’d do something particular wrong, it’s just mixing two formats - old and new. :slight_smile:

The field where the UI shows this title:

State template*

is exclusively for a template. Specifically, the template that will determine the binary_sensor’s state value.

It is not designed to contain anything else, such as YAML and/or templates for other options.

Currently, a Template Binary Sensor helper only supports three options:

  1. Name
  2. State template
  3. Device class

A Template Binary Sensor supports many other options:

  • attributes
  • auto_off
  • availability
  • delay_on
  • delay_off
  • icon
  • picture

If you need to configure any of those options, you cannot do it with a helper and must use YAML.

Why are you trying to template this? The default icons for binary sensors are very similar to this

If you want to template this, you can’t use the UI. You have to use yaml.

You can use the old or new yaml template format.

@sender
As example (used your icons):

switch:
  - platform: template
    switches:

      tesing_switch:
        icon_template: >-
          {% if is_state(this.entity_id,'on') -%}
            mdi:radiobox-marked
          {%- else -%}
            mdi:radiobox-blank
          {%- endif %}

        value_template: >-
          {{ is_state('input_boolean.test_boolean', 'on') }}

        turn_on:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.test_boolean
          - service: notify.persistent_notification
            data:
              message: ON

        turn_off:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.test_boolean
          - service: notify.persistent_notification
            data:
              message: OFF

And yes, defining code in yaml is still more powerful than using UI…

1 Like

Sorry, what do you mean by a “new format”?
Switches are not covered here:

i.e. these “new” & “legacy” terms are not applicable for switches.

1 Like

For me they were not… now I have templated them all is fine again… In YAML though…

All you had to do what change the display as…

To what then? I tried that but none gave me “marked” circles… only squares, houses, people, I tried the whole list bit no circle… (with marked and unmarked)

I think the real question here is “why?”.

If the existing ones were working then why change them?

I needed to change other thing as well.

And recently even automatically things were moved to helpers (dont remember well). Thus I thought having all at 1 place.

Therlse were in the “template” section of the config file. And nowaday templates are below the sensor or binary sensor sections.

Sumup… a lot of variation so wanted to harmonize.