elica
December 5, 2023, 3:13pm
1
I need help with this template. I can’t figure out how it makes the state of the binary_sensor change. The strange thing, to me, is that the icon changes correctly.
Did I do something wrong?
template:
- binary_sensor:
- name: "Cancello Automobile"
device_class: "moving" #"opening"
state: >-
{% if is_state("binary_sensor.open_cancello_auto", "off")%}
Chiuso
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
in movimento
{% else %}
Aperto
{% endif %}
icon: >-
{% if is_state("binary_sensor.open_cancello_auto", "off") %}
mdi:gate
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
mdi:gate-alert
{% else %}
mdi:gate-open
{% endif %}
Grazie.
jchh
((not John))
December 5, 2023, 3:19pm
2
A binary_sensor
can only be off
or on
. It cannot be Chiuso
, in movimento
, or Aperto
If you want those possibilities, you probably need sensor
.
1 Like
elica
December 5, 2023, 3:35pm
3
In fact I need to have these written because I’m trying to group three entities into one to simplify the frontend.
finity
December 5, 2023, 3:42pm
4
then change “binary_sensor:” to “sensor:”.
jchh
((not John))
December 5, 2023, 4:04pm
5
So you cannot use a binary_sensor then. A binary sensor can only have 2 states (off and on).
A Sensor can have as many states as you like:
template:
- sensor:
- name: "Cancello Automobile"
device_class: "moving" #"opening"
state: >-
{% if is_state("binary_sensor.open_cancello_auto", "off")%}
Chiuso
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
in movimento
{% else %}
Aperto
{% endif %}
icon: >-
{% if is_state("binary_sensor.open_cancello_auto", "off") %}
mdi:gate
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
mdi:gate-alert
{% else %}
mdi:gate-open
{% endif %}
elica
December 5, 2023, 6:03pm
6
Thanks for your help. Now works. Too bad you can’t change the color of the icon.
To make it work I had to delete the “device_class” line.
#template:
- sensor:
- name: "Cancello Automobile"
#device_class: "moving" #"opening"
state: >-
{% if is_state("binary_sensor.open_cancello_auto", "off")%}
Chiuso
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
in movimento
{% else %}
Aperto
{% endif %}
icon: >-
{% if is_state("binary_sensor.open_cancello_auto", "off") %}
mdi:gate
{% elif is_state("binary_sensor.close_cancello_auto", "on") %}
mdi:gate-alert
{% else %}
mdi:gate-open
{% endif %}
jchh
((not John))
December 5, 2023, 6:23pm
7
You can change the colour of the icon in the dashboard.
elica
December 6, 2023, 10:43am
8
On the dashboard I have these entities but the only one that does not change color is the “Car Gate sensor” that I just created with your help.
I really didn’t know how to do it.
jchh
((not John))
December 6, 2023, 3:08pm
9
is that an entities card?
I thin k the sensor needs to be on/off for the entities card to change colour.
You can set the colour yourself for any state if you used (for example) the (HACS) custom:button-card.
elica
December 6, 2023, 4:52pm
10
I had used “button_card” a while ago. I will try this project again.