Change badge color/icon with state

Hello,
I have installed a door sensor for my garage door, which shows me the current status of the door. Now I have a badge set up for it, but it does not change with the state of the sensor. But the sensor responds flawlessly. What do I have to reprogram to change the color or maybe even color and icon of the badge?

My code:

    badges:
      - type: state-label
        entity: binary_sensor.lumi_lumi_sensor_magnet_aq2_3d21e007_on_off
        name: Garagentor

As I’m aware of it, badges have no option to change the color on state change. But could create a badge with state filters, one for state „off“ and one for state „on“:


    badges:
      - type: entity-filter
        entities:
          - entity: binary_sensor.lumi_lumi_sensor_magnet_aq2_3d21e007_on_off
            icon: mdi:garage-variant
            state_filter:
              - 'off'
          - entity: binary_sensor.lumi_lumi_sensor_magnet_aq2_3d21e007_on_off
            icon: mdi:garage-open-variant
            state_filter:
              - 'on'

Super thanks for the answer.
This is exactly what I was looking for.
What would be cool here is not only the icon but also the color change.
How can i change this, commands with ‘badge_color’ somehow do not work for me.

This will only work with Card-mod or another custom cards.

Thanks, this works for me :+1: