How to change color custom button card

Hi,

I want the color of the button depending of the state of a dropbox, but this doesn’t work :

type: custom:button-card
name: living
icon: mdi:stop
state:
  - value: 'on'
    color: >
      [[[
        if (states['input_select.airco_modus'].state == 'heat')
          return "red";
        return "blue";
      ]]]
  - value: 'off'
    spin: false
tap_action:
  action: call-service
  service: climate.turn_off
  service_data:
    entity_id:
      - climate.airco_living_links
      - climate.airco_living_rechts
  target: {}
entity: binary_sensor.airco_living_is_on

Try this:

state:
  - value: 'on'
    color: >
      [[[ 
        if (states['input_select.airco_modus'].state == 'heat') 
          return 'red'; 
        else 
          return 'blue'; 
      ]]]
1 Like

Have black :roll_eyes:

Schermafbeelding 2022-02-02 123133

- type: custom:button-card
  [...]
  state:
    - value: 'on'
      styles:
        state:
          color: >
            [[[ 
              if (states['input_select.airco_modus'].state == 'heat') 
                return 'red'; 
              else 
                return 'blue'; 
             ]]]
        icon:
          color: >
            [[[ 
              if (states['input_select.airco_modus'].state == 'heat') 
                return 'red'; 
              else 
                return 'blue'; 
             ]]]

Button is gone…

https://github.com/custom-cards/button-card#styles

Yes, found it ! :grinning:

  - operator: template
    value: |
      [[[ 
        return (states['input_select.airco_modus'].state == 'heat') && (states['binary_sensor.airco_living_is_on'].state == 'on') 
       ]]]
    color: red
    spin: false
  - operator: template
    value: |
      [[[ 
        return (states['input_select.airco_modus'].state == 'cool') && (states['binary_sensor.airco_living_is_on'].state == 'on') 
       ]]]
    color: powderblue
    spin: false
  - operator: default
    spin: false

Instead of looking to the dropdown box, I would like to see the state of my aircon.
So, I did this :

  - operator: template
    value: |
      [[[ 
        return (states['climate.airco_living_links'].attributes.hvac_modes == 'heat') && (states['binary_sensor.airco_living_is_on'].state == 'on') 
       ]]]
    color: red
    spin: false

But this doesn’t work…any idea ?

Found it : states[‘climate.airco_living_links’].state

hello there:

I am trying to get the color changed in a button card wenn a particular script is running . can someone help ?

type: vertical-stack
cards:
  - type: custom:mushroom-vacuum-card
    entity: vacuum.rocky
    commands:
      - start_pause
      - stop
      - return_home
      - locate
  - square: true
    columns: 4
    type: grid
    cards:
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.1643022832589
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:stairs
        name: Hallway
        theme: Mushroom
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.1642517723169
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:toilet
        name: Bathroom
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.1647465285998
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:washing-machine-alert
        name: HTR
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.kitchen
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:countertop-outline
        name: Kitchen
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.dinner
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:silverware-fork-knife
        name: Dinning
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.living
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:sofa
        name: Living Room
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.1643021333614
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:chair-rolling
        name: Office
      - show_name: true
        show_icon: true
        type: button
        tap_action:
          action: call-service
          service: script.empty
          data: {}
          target: {}
        entity: vacuum.rocky
        icon: mdi:delete-empty
        name: Empty

I’m not so sure if you can intercept the state of the script?!
executing it triggers only a short impulse… maybe install a helper here that is switched on as long as the script is running?
the condition could then be determined.

I am trying to make the mdi:lock icon turn red when the alarm (Ring) is armed, the rest of the time it remains black. The button itself does not control the alarm it merely navigates to the alarm page but it would be useful to see at a glance when the alarm is armed.

I have been trying to get this working without success - anyone help?

type: custom:button-card
tap_action:
  action: navigate
  navigation_path: fire01_alarm
  operator: template
  value: |
    [[[ 
      return (states['alarm_control_panel.lancaster_alarm'].state == 'armed_away')
      return 'red';
     ]]]
  color: red
  spin: false
icon: mdi:lock
styles:
  card:
    - border-radius: 5px
    - width: 100px
  icon:
    - width: 55%
style: |
  ha-card {
    background: transparent
  }