custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.97k stars 241 forks source link

Add Tap-Action to States for conditional actions #543

Open UniqueName992 opened 2 years ago

UniqueName992 commented 2 years ago

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Have the ability to define different tap-actions for each state of the button in the YAML

Describe alternatives you've considered Using Scripts with conditional checks, however I'd like to have conditional confirmation/lockout depending on the state and avoid extra scripts Using different actions (tap / double tap etc.) for each service call, however it's not as intuitive for the end user Using a binary toggle, however it doesn't provide monitoring feedback of status

Additional context For a server on/off button. State provided by ping, shutdown by SSH and power on by smart switch / WoL (if it works). Providing both actions and state monitoring (red/green indicator) on a button is very intuitive for the user (and cool)

An example configuration YAML could be:

type: custom:button-card
icon: mdi:power
entity: binary_sensor.ping_server
show_name: false
state:
  - value: 'on'
    tap_action:
      action: call-service
      service: shell_command.server_shutdown
      confirmation:
        text: Power down server?
    styles:
      icon:
        - color: green
  - value: 'off'
    tap_action:
      action: call-service
      service: (Wol / switch)
    styles:
      icon:
        - color: red

Thank you for the amazing mod!

AndyVRD commented 2 years ago

This would be great, was just searching for this and only find the templating solution.

ghost commented 2 years ago

+1 for this idea!