If conditions / logic in markdown card


New to all this stuff and trying to figure out how to write a condition for a markedown card. So far this is what I have working:

Tempature is {% if is_state('sensor.temperature_sensor_temperature_4', '22.1') %} perfect{% else %} to cold{% endif %}.

What i want it to do is say: Tempature is perfect (if the range is between 22-23C) or if it’s over 23 write Tempature is too hot, or below 22 , Tempature is too cold.

I think i’m on the right track but can’t seem to figure out the next step. Any help is greatly appreciated.

{% set t = states('sensor.temperature_sensor_temperature_4') | float(0) %}
Temperature is {{ 'perfect' if 22 <= t <= 23 else 'too hot' if t > 23 else 'too cold' }}.

Much appreciated! I see now what to do.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.