Customize: change sensors's icon and color (miflora)

Hello. I can’t change icon and color of icon by state.
I wrote in configuration.yaml

  • platform: miflora
    mac: ‘C4:7C:8D:66:45:17’
    name: eucalipt
    force_update: false
    median: 3
    • moisture
    • light
    • temperature
    • conductivity
    • battery

in customize.yaml

    rgb_color: >
       if (state > 70)
         return [0, 0, 255];
       elif (state > 30)
         return [32, 255, 32];
         return [255, 0, 0];
    icon:  >                                                                                 
        if (state >= 98)
          return mdi:battery;
        elif (state >= 85)
          return mdi:battery-90;
        elif (state >= 75)
          return mdi:battery-80;
        elif (state >= 65)
          return mdi:battery-70;
        elif (state >= 50)
          return mdi:battery-50;
        elif (state >= 35)
          return mdi:battery-30;
        elif (state >= 25)
          return mdi:battery-20;
        elif (state <= 15)
          return mdi:battery-10;
          return mdi:battery-outline;

but color and icon didn’t change

please format your code using the </> button in the toolbar.

you could leave out the icon template completely, and simply use device_class: battery

for the icon_color, you should have custom-ui installed, as this isn’t supported natively in HA.

after you’ve done that, its as simple as:

  icon: mdi:counter
    icon_color: >
      if (state > 12) return 'rgb( 192, 39, 30 )';
      if (state > 10) return 'rgb( 244, 101, 35 )';
      if (state > 8) return 'rgb( 255, 194, 15 )';
      if (state > 4) return 'rgb(251, 210, 41)';
      return 'rgb(54, 95, 140)';

of course change your desired states and colors.

1 Like

thanks. Color is chahged.

add to customize.yaml:

  device_class: battery

it is not work

but it is not work. All the examples that I found to do template
- platform: template

        friendly_name: "eucalipt Battery"
        unit_of_measurement: "%"
        value_template: "{{states('sensor.eucalipt_battery')}}"
        device_class: battery

But i don’t want create new sensor

using HA’s native customization options you need t use jinja templating, and you now used Javascript templating used in custom-ui, but an incorrect version of it…

have a look at the icon_color template, and adapt accordingly in the icon template.

Thank you.

you’re welcome, let us know if you need more help, or things work out for you .