How can I check, in a template, if an input_number has a specific value

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.

{{ 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

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!