Icon with an attribute value

Hi everybody,

I bought an iRobot Roomba and it’s really efficient !

But I wanna have a dynamic battery icon. It could be easy because in attributes there is a “battery_icon” :

{
  "battery_icon": "mdi:battery-charging-100",
  "bin_full": false,
  "battery_level": 100,
  "software_version": "v2.2.11-4",
  "position": "(-23, -1050, 95)",
  "bin_present": true,
  "status": "Charging",
  "supported_features": 479,
  "icon": "mdi:roomba",
  "friendly_name": "Toto"
} 

So in the sensor.yaml I have this:

  - platform: template
    sensors:
       batterie_aspirateur:
         friendly_name: 'Batterie'
         value_template: '{{ states.vacuum.toto.attributes.battery_level}}'
         unit_of_measurement: '%'
         entity_id: vacuum.toto

And in the customize.yaml I try to use this :

sensor.batterie_aspirateur:
  friendly_name: Batterie
  icon: '{{ states.vacuum.toto.attributes.battery_icon }}'

But it doesn’t work and it displays no icon… but I haven’t error !
I tried with and without quotes, but no result…

Do you have an idea ?

Thank you !

add icon_template to your sensor definition:

1 Like

Thank you, it’s working !!

1 Like

Hi @Will711990, would you mind posting your entire config for this, I would love to see the code!

Of course !!

  - platform: template
    sensors:
       batterie_aspirateur:
         friendly_name: 'Batterie'
         value_template: '{{ states.vacuum.toto.attributes.battery_level}}'
         unit_of_measurement: '%'
         entity_id: vacuum.toto
         icon_template: '{{ states.vacuum.toto.attributes.battery_icon }}'
1 Like