Icon color based on entity numeric state with Mushroom template card

Hi all,
I’m trying to make the icon of a mushroom template card change color based on the numeric state of the entity.
I installed HACS Mushroom cards integration, restarted and, after trying lots of ways described variously on the internet, I wrote this:

type: custom:mushroom-template-card
primary: ""
secondary: ""
entity: sensor.qualita_totale_aria
icon: mdi:weather-dust
icon_color: |-
  {% set q = states('sensor.qualita_totale_aria') | float %} 
  {% if q < 20 %} 
    'blue'  
  {% elif q >= 20 and q < 50 %} 
    'green' 
  {% elif q >= 50 and q < 100 %} 
    'lime' 
  {% elif q >= 100 and q < 150 %} 
    'yellow'
  {% elif q >= 150 and q < 200 %} 
    'orange' 
  {% elif q >= 200 and q < 300 %} 
    'red' 
  {% elif q >= 300 %} 
    'purple' 
  {% else %} 
    'gray' 
  {% endif %}

and got no results.
So I searched for other ways or syntaxes and tryed to apply all the different ones I found, but the icon always remains white in the end.
Anybody with a piece of advice?
Thanks

Remove ‘…’ for each color

1 Like

Wow
thanks