[SOLVED] - How to add an icon to a new sensor needed for Lovelace?

Lovelace can not format values so I need to create new sensors with rounded values instead of 24,22 nicer looking 24. I do not wanna change it manually through the interface cause that is unreliable if you change the sensor title later.

I tried this but got an error “invalid option” or so.

  - platform: template
    sensors:
      temperature_printer_via_xiaomi_plug:
        icon: 'mdi:thermometer-lines'
        value_template: "{{ state_attr('switch.chuangmi_plug_m1', 'temperature') | round(0) }}"

Hope someone finds the point I can not see right now. thx

icon_template

Template - Home Assistant (home-assistant.io)

2 Likes

I tried but it does not really work or at least in case it has one, but a different.
not sure how to deal with it in the configuration.yaml cause it does not change.


  - platform: template
    sensors:
      temperature_printer_via_xiaomi_plug:
        icon_template: 'mdi:thermometer-lines'
        value_template: "{{ state_attr('switch.chuangmi_plug_m1', 'temperature') | round(0) }}"

I do not get it why it does not change the icon.

It worked for new sensors, but you can not change it once it has gotten an icon.
At least not this way.

Therefore the next points are

A)
how can I update an existing icon or

B)
how can I detect if a sensor has an icon attribute already and in case it has
how can I remove that icon.

Cause once the icon has been removed I could run the existing code again.

thx

Right now it works after I have renamed the sensor.
Now I can add and replace it with the same command and it works consistent and reliable. I do not know what had made the difference to the old one cause on old one I could not change the icon via configuration.yaml

now it works … so thanks a lot