Icon template in customize.yaml

Is icon_template allowed inside customize.yaml?

I want to customize an icon regarding the battery level and put this as icon_template, but it seems not working.

#    icon_template: >-
#      {% set battery_level = states.sensor.samsung_s8_battery.attributes.battery|default(0)|int %}
#      {% set battery_round = (battery_level / 10) |int * 10 %}
#      {% if battery_round >= 100 %}
#        mdi:battery
#      {% elif battery_round > 0 %}
#        mdi:battery-{{ battery_round }}
#      {% else %}
#        mdi:battery-alert
#      {% endif %}

Nope, check the documentation:

It lists all available options. If a component/document doesn’t list a _template as an option, the component cannot do it.

Here’s my working example. It should be easy to get what you need and make it work for you

mta: This is a separate sensor

 platform: template                                                                                                                                   
  sensors:                                                                                                                                             
    yourdevice:                                                                                                                                     
      friendly_name: "Your Battery"                                                                                                                   
      unit_of_measurement: "%"                                                                                                                         
      value_template: "{{states.device_tracker.yourdevice.attributes.battery}}"                                                                          
      icon_template: >                                                                                                                                 
        {% if states.device_tracker.yourdevice.attributes.battery %}                                                                                     
          {% if states.device_tracker.yourdevice.attributes.battery >= 98 %}                                                                             
            mdi:battery                                                                                                                                
          {% elif states.device_tracker.yourdevice.attributes.battery >= 85 %}                                                                           
            mdi:battery-90                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery >= 75 %}                                                                           
            mdi:battery-80                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery >= 65 %}                                                                           
            mdi:battery-70                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery >= 50 %}                                                                           
            mdi:battery-50                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery >= 35 %}                                                                           
            mdi:battery-30                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery >= 25 %}                                                                           
            mdi:battery-20                                                                                                                             
          {% elif states.device_tracker.yourdevice.attributes.battery <= 15 %}                                                                           
            mdi:battery-10                                                                                                                             
          {% else %}                                                                                                                                   
            mdi:battery-outline                                                                                                                        
          {% endif %}                                                                                                                                  
        {% endif %}
1 Like

That icon template only works inside template sensors, lights, fans, etc. @maurizio53 is specifically asking about the customization section of the config, so your solution will not work for him.

yeah, that’s why it says,

“This is a separate sensor”

2 Likes