Custom card button label

I’m having trouble getting my custom card button to display a percentage that is the payload of an MQTT topic. Here’s what I have right now but it doesn’t seem to work

type: custom:button-card
entity: sensor.east_garage_status
icon: mdi:garage
name: East Garage
size: 34px
card_size: 1
tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    payload: toggle
    topic: garage/EastGarage/commands
show_state: false
show_name: true
show_label: true
state:
  - value: open
    label: Open
    icon: mdi:garage-open
    color: rgb(5, 147, 255)
  - value: closed
    label: >
    [[[
       var percent = states['sensor.east_garage_percentage'];
       return "Closed " + percent;
    ]]]

    
    icon: mdi:garage
    color: rgb(255, 255, 255)
  - value: opening
    label: Opening
    icon: mdi:garage-alert
    color: rgb(255, 0, 0)
  - value: closing
    label: Closing
    icon: mdi:garage-alert
    color: rgb(255, 0, 0)

What am I doing wrong?

var percent = states['sensor.east_garage_percentage'].state;

Suggest you to avoid creating a separate thread for this (or any other custom cards) - use already present huge dedicated button-card thread. You will attract more users and share your solutions / problems with them; all solutions will be placed in one thread instead of being scattered.

1 Like