Customzing icons

I am trying to change color on icons depending on state.
I have this in customize.yaml

I got this working for a sensor for text:

sensor.tesla_charger:
  friendly_name: Tesla charger
  templates:
    icon_color: >
      if (state == 'Charging') return 'blue';
      if (state == 'Connected') return 'yellow';
      if (state == 'Available') return 'green';
      return 'normal';

But when I try to do the same thing with values, it does not work:

sensor.charger_current_p1:
  friendly_name: Phase 1
  templates:
    icon_color: >
      if (state < 20 ) return 'normal';
      if (state > 25) return 'red';
      if (state > 20) return 'yellow';
      return 'black';

Any ideas?

Did you notice there is a missing ’ after yellow in your Phase 1 code?

My two cents :grinning_face_with_smiling_eyes:

1 Like

Good catch, but unfortunately but it did not fix the problem.
Fixed it in the example above.

Hmm, for some reason I had to restart 2 times before it worked… thats for the help…

1 Like