For many sensors in Home Assistant you may want to change icon color dynamically on your dashboard. Having the icon color turn on or off was not enough for me especially for thermostats. I wanted to use a range of colors to show how extremely cold or hot the temperature was. The way I accomplished this was by using the Config Template Card.
Installing the Config Template Card
Firstly you are going to need to install the Config Template Card. The easiest way is to use HACS
Or you can install manually using this guide.
YAML for dynamically changing icon color
type: custom:config-template-card
variables:
TEMP: states['sensor.blink_front_door_temperature'].state | i
entities:
- sensor.blink_front_door_temperature
card:
type: custom:mushroom-entity-card
entity: sensor.blink_front_door_temperature
name: Front Door Temperature
icon_color: >-
${TEMP < '0'? 'deep-purple' :TEMP < '20'? 'purple' : TEMP < '32' ? 'indigo'
: TEMP < '50' ? 'blue': TEMP < '72' ? 'green': TEMP < '85' ? 'orange':
'red'}