This answers your question but I doubt that is what you really want. icon: mdi:door-closed
You probably want to look into icon templates or ‘device class: door might work’ for you The MDI Icons Icon Template
If you do the templating or the device class on the binary sensor, make sure you remove the icon line in your badge.
that’s not what i need, i mean i know which icon to use, i need to use an icon based on a state like i did for the color in the Style. In other words i need to have like:(this below doesn-t work)
badges:
entity: binary_sensor.xiaomidoorhomestate
icon: {% if is_state(‘binary_sensor.xiaomidoorhomestate’, ‘off’) %} mdi:door-closed {% else %} mdi:door-open {% endif %};
style: |
:host {
–label-badge-blue: {% if is_state(‘binary_sensor.xiaomidoorhomestate’, ‘off’) %} green {% else %} red {% endif %};
}
You need to customize the device class which can be done on the binary sensor set up or after in cusomize.yaml https://www.home-assistant.io/docs/configuration/customizing-devices/
The device class handles changing icon based on state for you. I use it extensively, I mainly set device class in my sensor and binary_sensor yaml configs.