Confirmation in the custom button card

I am trying to figure out a way to add a confirmation to just one state of the entity, but I cant get it to work…

type: 'custom:button-card'
entity: light.inovelli_unknown_type_0003_id_0001_level
state:
  - value: 'on'
    icon: 'mdi:valve-open'
    color: green
  - value: 'off'
    icon: 'mdi:valve-closed'
    color: red
styles:
  card:
    - height: 100px
confirmation:
  text: Are you sure you want to turn off the water?

Obviously it is not the inovelli switch that that I want to control, but my water shut off valve. But I only want it to ask “are you are sure” if I am turning the water from “on” to “off” so that no one accidently shuts the water off.
Can this be done?

You could try this „workaround“:


tap_action:
  action: toggle
  confirmation:
    text: |
      [[[
        return `${states['light.inovelli_unknown_type_0003_id_0001_level'].state == 'off' ? 'Water is already off. Please press „cancel“ ' : 'Are you sure that you want the water turn off?'}`
      ]]]

or shorter:


…
      [[[
        return `${entity.state == 'off' ? 'Water is already off. Please press „cancel“ ' : 'Are you sure that you want the water turn off?'}`
      ]]]

I call it „workaround“ because the code above only returns a warning but don‘t prevent further execution if „ok“ is pressed by mistake.

1 Like