Icon color change

Hi All,

Im using custom_ui and lot of icons get right color. Now I want add 1 based on temperature.

sensor.dark_sky_temperature:
  friendly_name: Current Temperature
  templates:
    icon_color: >-
      if (state < '-23') return 'rgba(255,0,255,1)';
      if (state < '-18') return 'rgba(139,0,139,1)';
      if (state < '-12') return 'rgba(128,0,128,1)';
      if (state < '-7') return 'rgba(0,0,255,1)';
      if (state < '-1') return 'rgba(135,206,236,1)';
      if (state < '4') return 'rgba(0,128,0,1)';
      if (state < '10') return 'rgba(144,238,144,1)';
      if (state < '16') return 'rgba(255,2255,0,1)';
      if (state < '21') return 'rgba(255,165,0,1)';
      if (state < '27') return 'rgba(255,69,0,1)';
      if (state < '32') return 'rgba(255,0,0,1)';
      if (state < '38') return 'rgba(139,0,0,1)';

Only color is see is green "if (state < ‘4’) return ‘rgba(0,128,0,1)’; "
When I change the temp using development tool there is nothing happen on the color.
16 degrees must give " if (state < ‘-18’) return ‘rgba(139,0,139,1)’; " Pink Purple but still green.

Can someone see the fault in this part?

Try this scheme to add colours to temp:

1 Like

In my config I don’t use icon_color: >- but icon_color: > without -
and the color are in rbg not rgba.

sensor.netatmo_interieur_temperature:
  friendly_name: Salon
  templates:
    icon_color: >
      if (state > 24) return 'rgb(255, 90, 0)';
      if (state > 18) return 'rgb(255,193,0)';
      if (state > 10) return 'rgb(216,255,81)';
      if (state > 5) return 'rgb(0,191,255)';  
      if (state > 0) return 'rgb(202,241,255)';     
      if (state < 0) return 'rgb(178,0,237)';
      return 'rgb(204, 255, 229)';
1 Like

Thanks for the reply. I also tried the > without - didn’t work.
I have more templates using the rgba thats why i tried it with rgba.

Let me try this later the day when im back home… :slight_smile:

How would you change this code for in-between state ranges?

e.g. If state (>16,<20) return “colour”

if (state > 16 and state < 20) return 'rgb(255, 90, 0)';