Change a Sensor Icon color - Very confused

I have in customize_glob following templates and they are working.

    binary_sensor.*_enabled:
      templates:
        icon_color: >
          if (state == "on") {
            return 'rgb(22, 200, 38)';
          } else {
            return 'rgb(255, 22, 38)';
          }

Give it a try :slight_smile:

I did, but it doesnt work. Soo that tells me there is something wrong with the confguration of custom_ui perhaps…

Make sure you’re using CustomUI: 20190518 (rgb didn’t work in the previous version) and I think you need “===” for “equals” here.

Here’s an example using HSV:

script.disarm_alarm:
  templates:
    icon_color: if (entities['sensor.armed_status'].state === 'disarmed') return 'green';
      else return '#696969';

templates: is a key part

as stated above, for customizing icon_color, you need custom-ui installed. check the /developer-tools/info for that:

then, among the many possible javascript syntaxes available, I find this to be the cleanest:

device_tracker.apple_wireless_keyboard:
  templates:
    icon_color: >
      if (state === 'home') return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';

any css color-coding can be used, most of the time rgb is used for fine coloring, or simply use the color names available, always between quotes.

the above code is placed in a hierarchy in your config, under

homeassistant:
  customize:

depending on your settings, it could be in your configuration.yaml, or if you want in in a separate file/folder, use eg this:

homeassistant:
  name: Main
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: !secret elevation
  unit_system: metric
  time_zone: !secret time_zone
  customize: !include_dir_merge_named customize    <---- this is the important line
  customize_glob: !include customize_glob.yaml

and have a folder /config/customize , in which you place the file with the above customization directly.

or use the line

 customize: !include customize.yaml

and add the file customize.yaml in which the same customization is written.