How to prevent a button from switching "off"?

I have created a button which toggles an input_boolean. The input_boolean triggers an automation. The automation runs a pump for 30 minutes and switches it off, also the input_boolean is switched to "off" after 30 minutes.
The problem is: While the automation is running I can switch the button on and off, this does not affect the pump which is intended (the pump must! run 30 minutes)
I am aiming at blocking the button also for 30 minutes so to have an identical visual state for pump and button at any time.
I tried with a tap action in the button card configuration:

tap_action:
  action: call-service
  service: input_boolean.turn_on
  target:
  entity_id: input_boolean.myinput

But this turned out to bring the follwing error:

The action input_boolean/turn_on could not be exercised. must contain at least one of entity_id
, device_id, area_id, floor_id, label_id

Can anyone help?

Hi,
With the button-card, you should be able to do it:

1 Like

One very brute force method would be to have to versions of the button. One that actually toggles the input boolean, and one that does nothing. Then you could set a visibility condition that would show the right button at the right times.

I don't know if there is a condition for an automation running, so you might have to get clever about using the existing input boolean, or create yet another one that is only used to tell if you are in that 30 minute window.

1 Like

Add 2 spaces before the entity_id line, like this:

tap_action:
  action: perform-action
  perform_action: switch.turn_on
  target:
    entity_id: switch.water_heater_switch

Otherwise, just do everything in the UI under the Interactions part of the card - that will definitely generate the correct output:

call-service was renamed to perform-action, but both work. I suggest you use the newer terminology in your code in case call-service ever gets deprecated.

Tried it, but this failed. Maybe I have to be more precise:
I just want the button to be blocked in its "on"-state while the automation is working, the button should not react to any second or third touch with the finger. In other words: Once setted "on" (color of button changes) it should stay in this state as long as the automation sets it "off".

Then follow @pkscout's advice and use a conditional card (the Visibility option in card setup) with 2 cards. You can use the state of the pump as a condition, since you cannot check whether an automation is running in the conditional .

Just an idea: would it not work to use a condition in the automation to only run the action when the boolean is off?

The automation is to run a pump for 30 minutes. It is triggered by three differnt entities, one of them is the button in HA. So I can trigger the automation by pressing the buuton (state changes from off to on). But since then the button is not synchronized with the pump as the pump runs for 30 minutes but the button can be toggled (although toggling of the button has no impact on the automation any more - which is intended!)

Another option could be to add a conditional action to the automation that immediately switches the button on again when it is pushed to the off state, under the condition: while the input_boolean is on.

If you use custom:button-card, you can have tap action exist only when the switch is off:

type: custom:button-card
name: The button
tap_action:
  action: |
    [[[
      const switchState = states['switch.water_heater_switch']?.state;
      if (switchState === 'off')
        return 'perform-action';
    ]]]
  perform_action: switch.turn_on
  target:
    entity_id: switch.water_heater_switch

As a result, the button becomes inactive when the switch is turned on.

That action is not specific to only a custom:button-card. It's just one way to execute that action with that type of Card.

Substitute the input boolean for a template switch.

Set the:

  • State to track the actual pumps state.
  • The "Actions on turn on" to kick off the script (use a script not an automation).

It won't be perfect, since you can flip the switch off again, but thats just a UI thing, it will reset itself back to "on" in a second or two.

1 Like

What does your automation look like? Do you have a delay there of 30 min? This is typically not a good idea in HA. If so, consider using a timer instead. Let your automation trigger on the timer being started to turn on the pump, and another to turn it off. Have your button start the timer. You can still use David's idea above (which I think is the neatest) by having the switch's state template check the timer's state.

Indeed I use a custom:button-card.I tried your suggestion with my card, but it does not work. Note: The "input_boolean.power_zirkpump" turns on my pump.

type: custom:button-card
show_state: true
name: Zirkulationspumpe
icon: mdi:shower-head
tap_action:
  action: |
    [[[
      const switchState = states['input_boolean.power_zirkpump']?.state;
      if (switchState === 'off')
        return 'perform-action';
    ]]]
  perform_action: input_boolean.turn_on
  target:
    entity_id: input_boolean.power_zirkpump

If by "doesn't work" you mean that the button doesn't reflect input_boolean's state (icon color and state field), then set the entity field to that input_boolean as well:

type: custom:button-card
show_state: true
entity: input_boolean.power_zirkpump
name: Zirkulationspumpe
icon: mdi:shower-head
tap_action:
  action: |
    [[[
      const switchState = states['input_boolean.power_zirkpump']?.state;
      if (switchState === 'off')
        return 'perform-action';
    ]]]
  perform_action: input_boolean.turn_on
  target:
    entity_id: input_boolean.power_zirkpump

record_2026-05-30_16-48-23-ezgif.com-video-to-gif-converter

I mean, when pressing the button, nothing happens, nor color changes. Checking the state of the entity says for input_boolean.power_zirkpump "off", although I have pressed the button.

I understand :slight_smile: Maybe your version of the custom button is very old, so things still have the old names. AFAIR "perform-action" used to be called "call-service" and "perform_action" was simply called "service"? Other than that, I don't see why it wouldn't work.
Edit: I see you actually used the old names in your first post. So you can try with tap_action looking as this:

tap_action:
  action: |
    [[[
      const switchState = states['input_boolean.power_zirkpump']?.state;
      if (switchState === 'off')
        return 'call-service';
    ]]]
  service: input_boolean.turn_on
  target:
    entity_id: input_boolean.power_zirkpump

Oops, I thought it worked. I was still in the editing mode of the dashboard when the button turned red (I changes the colors) and the pump was in operation. But then I reloaded all the yaml-configurations and as a result I get the same error as in the beginning (see my first post).

Here is what I have:

type: custom:button-card
entity: input_boolean.power_zirkpump
show_state: true
name: Zirkulationspumpe
icon: mdi:shower-head
state:
  - value: "on"
    color: red
  - value: "off"
    color: blue
tap_action:
  action: |
    [[[
      const switchState = states['input_boolean.power_zirkpump']?.state;
      if (switchState === 'off')
        return 'call-service';
    ]]]
  service: input_boolean.turn_on
  target:
    entity_id: input_boolean.power_zirkpump`

By the way: The button works well, without the lines beginning with "tap_action". Of course with the behaviour that it can be toggled all while the automation is running.

You want the button to only work when the pump is off? That is make it "unavailable" until the pump is off?

template:
  - button:
      - name: Push Me
        unique_id: push_me_button
        availability: "{{ is_state('light.cabinet_lights','off') }}"
        press:
          action: light.turn_on
          target:
            entity_id: light.cabinet_lights


automation:
  - id: test_turn_the_light_off
    alias: Test turn the light off
    triggers:
      - trigger: state
        entity_id: light.cabinet_lights
        to: 'on'
        for:
          seconds: 10
    actions:
      - action: light.turn_off
        target:
          entity_id: light.cabinet_lights

But, I'd probably use a timer so it will survive a restart.

You have an apostrophe at the end. After removing it, the card works for me! After clicking it, it changes color from blue to red (and becomes non-clickable). P.s. you can check you button-card version in HACS. Don't update, just check.