Hi, I’m trying to figure out the best way to conditionally render a button in a lovelace button card.
To be concrete, I am building a button card which holds a number of buttons which represent common actions to control the home cinema setup.
The button actions are service calls to send a command to a Logitech Harmony remote.
Now I am wondering how I could conditionally render the Play and Pause button based on state.
I’ve been looking at the conditions support in lovelace, but it seems to evaluate on an entity state, and in this situation I do not seem to have a useable entity state for the condition to evaluate on.
Then I started thinking about creating some sort of template binary sensor entity to hold state for this, but am unsure if this is the best way to approach it since it can have 2 states, on or off.
Ofcourse, I could just keep things simple and have both the Play and Pause buttons available simultaneously, but it seemed like a fun exercise to learn more about the platform to try and figure out how one would go about this.
- type: horizontal-stack
cards:
- type: button
tap_action:
action: call-service
service: remote.send_command
service_data:
entity_id: remote.living_room
device: Yamaha AV Receiver
command: VolumeDown
icon: 'mdi:volume-minus'
icon_height: 20px
- type: button
tap_action:
action: call-service
service: remote.send_command
service_data:
entity_id: remote.living_room
device: Yamaha AV Receiver
command: VolumeUp
icon: 'mdi:volume-plus'
icon_height: 20px
- type: button
tap_action:
action: call-service
service: remote.send_command
service_data:
entity_id: remote.living_room
device: Yamaha AV Receiver
command: Mute
icon: 'mdi:volume-mute'
icon_height: 20px
- type: button
tap_action:
action: call-service
service: remote.send_command
service_data:
entity_id: remote.living_room
device: Apple TV
command: Pause
icon: 'mdi:pause'
icon_height: 20px
- type: button
tap_action:
action: call-service
service: remote.send_command
service_data:
entity_id: remote.living_room
device: Apple TV
command: Play
icon: 'mdi:play'
icon_height: 20px