I’m using a Mushroom template card to change the accent color of an mdi icon based on the charge of my EV. However, when I use the code below, when the EV is charged to 100% the icon color is orange
{% if states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') > "80" %}
green
{% elif states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') > "60" %}
orange
{% elif states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') < "60" %}
red
{% endif %}
I would expect that 100 is higher than 80, because from 81 to 99 it’s green, when it becomes 100 it turns orange for some strange reason.
{% if states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') | int > 80 %}
green
{% elif states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') | int > 60 %}
orange
{% elif states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') | int < 60 %}
red
{% endif %}
In addition to what @Hellis81 is saying, your logic is missing the value 60. If your battery level is ever exactly 60, the code will output nothing resulting in an unavailable sensor. Or if this is used in the frontend, the color black for the icon/text.
{% if states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') | int > 80 %}
green
{% elif states('sensor.volvo_yv1xzept1r2369964_battery_charge_level') | int > 60 %}
orange
{% else %}
red
{% endif %}