sender
June 29, 2024, 2:01pm
1
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.
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:
sender
June 29, 2024, 2:17pm
3
Yes think I am slowly finding out:
You can’t combine the state and icon logic in the UI. The state template in the UI would be like this.
[image]
You are better off adding the template to the configuration file as suggested
[image]
Adding it to your config file can be done via the File Editor addon (other methods too)
Example configuration.yaml file
default_config:
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
senso…
It’s not that you’d do something particular wrong, it’s just mixing two formats - old and new.
123
(Taras)
June 29, 2024, 2:38pm
5
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:
Name
State template
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.
petro
(Petro)
June 29, 2024, 2:57pm
6
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
sender
June 29, 2024, 8:21pm
9
For me they were not… now I have templated them all is fine again… In YAML though…
petro
(Petro)
June 29, 2024, 11:17pm
10
All you had to do what change the display as…
sender
June 30, 2024, 1:07am
11
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)
finity
June 30, 2024, 1:24am
12
I think the real question here is “why?”.
If the existing ones were working then why change them?
sender
June 30, 2024, 4:18am
13
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.