State_color: doesn't work in Button card

In this simple card, the state_color: true does not have any effect at all.
image
The code is:

- type: button
    entity: sensor.av_pa
    show_name: false
    show_state: true
    icon: 'mdi:power'
    icon_height: 70px
    state_color: true
    tap_action:
      action: call-service
      service: climate.turn_on
      service_data:
        entity_id: climate.thermostat_5

How can I make the state_color attribute work (please, no card_mod)?

It’s a sensor. There is no way to know if it’s on or off. Pretty sure state_color only works for binary type devices, like switch/light/binary_sensor, etc since those all are forced to return either true or false.

The sensor state could be anything really.

@jocnnor hi and thanks for your reply. But if it is no way of knowing if it is ‘on’ or ‘off’ why then does show_state: true work exactly as it should ?

Because it will show the state. It doesn’t care if the state is ‘on’, ‘off’, ‘the_climate_is_on’, ‘Please Fasten Your Seatbelts’…it’s always just a text string. It doesn’t try to translate the state string to a boolean.

Aha, I see - thanks for explaining. :smirk:

1 Like