DriesA
(Dries)
December 13, 2024, 1:28pm
1
Hi,
I have a sensor that can have four distinct values (0,1,2,3).
I want to show this information on my dashboard using a Tile card. However, instead of the numbers, I would like to display what they actually represent.
E.g. 0=off, 1=standby, 2=running, 3=problem
Is this possible?
Hellis81
(Hellis81)
December 13, 2024, 1:45pm
3
As Ildar says create a helper template sensor and add this yaml:
{{ ["Off", "Standby", "Running", "Problem"][states('sensor.your_sensor_with_numbers')] }}
1 Like
DriesA
(Dries)
December 13, 2024, 2:15pm
4
Thanks both for your feedback.
I was hoping for a solution in the card itself, but I created a template sensor as suggested:
{% if is_state('sensor.sauna_status', '0') %}
Uitgeschakeld
{% elif is_state('sensor.sauna_status', '1')%}
Stand-by
{% elif is_state('sensor.sauna_status', '2') %}
Opwarmen
{% elif is_state('sensor.sauna_status', '3') %}
Fout!
{% else %}
Fout!
{% endif %}
@Hellis81 , I tried your code first, but that did not seem to work although it looks more simple than my code.
Hellis81
(Hellis81)
December 13, 2024, 2:18pm
5
Try it in developer tools, what error does it show?
DriesA
(Dries)
December 13, 2024, 2:22pm
6
It says “‘list object’ has no attribute ‘2’”
{{ ["Off", "Standby", "Running", "Problem"]states('sensor.your_sensor_with_numbers')|int(default=0)] }}
1 Like
DriesA
(Dries)
December 13, 2024, 2:47pm
8
That works, thanks!
I noticed a small typo, a missing “[” before states.
{{ ["Off", "Standby", "Running", "Problem"][states('sensor.sauna_status')|int(default=0)] }}
I would suggest you not to mark my post as a solution since my post was merely a small correction.
1 Like