diegopau
(Diego)
December 20, 2022, 10:27am
1
I am trying to use the code below, in a mushroom custom template card, to decide on the color of the icon.
{% if states('input_number.shower_timer_initial_value') == '5' %}
orange
{% elif %}
grey
{% endif %}
I would expect this to work since in the template editor (inside Developers page) I can try to do only
{{ states('input_number.shower_timer_initial_value') }}
and the output is
5
as expected.
I am quite new to all this and I can’t figure out what is wrong with it. I would be thankful for your help.
Olivier1974
(Olivier Toussaint)
December 20, 2022, 10:34am
2
{{ iif (states.input_number.shower_timer_initial_value.state | int == 5, orange, grey) }}
should work
1 Like
The issue is your use of elif
without providing an argument… if you want an if statement to return a default value you should use else
.
{% if states('input_number.shower_timer_initial_value') == '5' %}
orange
{% else %}
grey
{% endif %}
As Olivier pointed out you can use the “immediate if” function for an If/Then/Else construction, however I would reccommend using is_state()
instead of the state object method.
{{ iif( is_state('input_number.shower_timer_initial_value', '5'), 'orange', 'grey' ) }}
1 Like
diegopau
(Diego)
December 21, 2022, 6:18pm
4
Thank you both!! I feel a bit foolish now for not realizing that I left an elif there due to a copy paste. But it was nice to learn about the iif statement!