Binary sensor not used in button card config

Hi all!

I have a switch for controlling the garagedoor and a separate sensor (with separate enity) for seeing if its open or closed. Both work without issues but I’m trying to combine them in 1 card on my dashboard.

The goal is to have the garagedoor icon shown in green if door is closed, open is red and others orange (if that ever happens).

I’ve used the code below, but the icon is orange. The data from the binary sensor is not used. Neither open or closed is recognized even though these are the states that this sensor is using as far as I know.

type: custom:button-card
entity: switch.garagedeur_nodon
icon: mdi:garage
name: Garagedeur
    - color: |
          if (states['binary_sensor.deursensor_garagedeur'].state == 'Open')
            return 'red';
          if (states['binary_sensor.deursensor_garagedeur'].state == 'Closed')
            return 'green';
          return 'orange';

What am I missing here? I believe i followed the configuration the way they suggested in the instructions.

Big thanks!


binary sensor may be on / off.

You are a genius, thanks!!