Help with Template where state is x y or z

I am making a card for my ember mug and part of it I need to list out if the state of the mug is heating, warming or perfect. I’m trying to use this code here, and it works if the mug is heating, but not if it’s cooling or perfect. I also tried playing around with arrays but that didn’t seem to work either. Can someone please point me in the right direction?

{% if states('sensor.ember_mug_state') == ('heating' or 'cooling' or 'perfect') %}
True
{% else %} 
False
{% endif %}

You could try this:

{% if states('sensor.ember_mug_state') in ['heating','cooling','perfect'] %}
True
{% else %} 
False
{% endif %}
1 Like

think that did it thank you!

Awesome! Please mark the solution for others :slight_smile:

Might be able to simply use:

{{ states('sensor.ember_mug_state') in ['heating','cooling','perfect'] }}

That will return true or false.

OK so that’s working, but now I would like to clean up the config a little bit. I’m looking to perform some actions if the state is in one of those 3 options, so instead of defining it each time I need to reference it, I was thinking I could set a variable. But I can’t figure out how to do that with an if/then statement.

{% set mugstate = {
  if states('sensor.ember_mug_state') in ['heating','cooling','perfect']
  doingsomething
else 
idle
}

edit, I hadn’t bothered with formatting the code because I figured I was far off, good to know I was close :slight_smile:

Close, and please format code correctly.

{% set mugstate = 'doingsomething'
       if states('sensor.ember_mug_state') in ['heating','cooling','perfect']
       else 'idle' %}

Line breaks optional, just for forum readability.

1 Like