kanidef
(Kanidef)
June 16, 2019, 3:25pm
1
Hello. I can’t change icon and color of icon by state.
I wrote in configuration.yaml
sensor:
platform: miflora
mac: ‘C4:7C:8D:66:45:17’
name: eucalipt
force_update: false
median: 3
monitored_conditions:
moisture
light
temperature
conductivity
battery
in customize.yaml
sensor.eucalipt_moisture:
templates:
rgb_color: >
if (state > 70)
return [0, 0, 255];
elif (state > 30)
return [32, 255, 32];
else
return [255, 0, 0];
sensor.eucalipt_battery:
templates:
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;
else
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:
sensor.count_actueel_sensors:
icon: mdi:counter
templates:
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
kanidef
(Kanidef)
June 16, 2019, 4:47pm
3
Mariusthvdb:
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:
thanks. Color is chahged.
add to customize.yaml:
sensor.eucalipt_battery:
device_class: battery
it is not work
but it is not work. All the examples that I found to do template
sensor:
- platform: template
sensors:
eucalipt_battery_temp:
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.
you’re welcome, let us know if you need more help, or things work out for you .