Is it possible to change icon based on percentage

Say you have a sensor that records the voltage of a battery on a device, is it possible to change the icon based on the percentage, I notice there are mdi icons available for different battery states, so it would be nice to be able to change the icons roughly based on the percentage value.

This would be a good feature.

Can you include icons in a sensor template? I don’t know as I’ve never tried this.

HI there.

This is exactly what I would like to do: did you find the solution to do so? These must be a way to do so…some icons of the switches change based on the status

It is not possible from the configuration file.
It is possible with a custom component:

1 Like

Hey there, I’m interested in this too. Since I’ve no experience in writing components I was wondering if maybe somebody got around creating such a component in the meantime and would be willing to share the code :-). Thanks

So did anybody succeed and can post some example coding in here? :slight_smile:


As it’s not possible to set an icon by programming I’d suggest this be moved to Feature Requests.

The yr sensor change icon based on current weather:

True and so does Weather Underground.

But both are components and both platforms send that information to HA as part of their API. Doing this with a random sensor would be a very different thing.

Currently it is possible with a custom component.

But you want to do it from the config file?

I think that was what the OP was trying to do.

That’s something I am looking for too. Template an icon :slight_smile:
According to value or state of a sensor change the icon. Examples:

  • Door closed: icon with closed door
  • Door open: icon with open door
  • Battery levels: battery, battery-60, battery-40, battery-10, battery-alert
  • Temperature above treshold: red icon
  • Temperature within range: green icon
  • Temperature below treshold: blue icon
  • Rest sensor monitors a service, service ok: green, service warning: yellow, service critical: red

Something like that would be awesome.

I think what you guys are looking for is an extension of this feature request:

I’d suggest moving your posts to there and voting on it.

1 Like

For battery you can do something like I did here:

1 Like