Button is being held

The Button is being held condition passes while a button is held down. It checks event entities with the button device class, such as the buttons of a remote control or a wall switch. Use it to check whether a button is held when something else happens. For example, you can give a button a second function that only runs while you hold another button.

A button counts as held from the moment it reports a Long press start (long_press_start) event until it reports any other event, such as Long press end (long_press_end) or an event type that is specific to the integration. A hold also ends 30 seconds after it starts, even if the button is still held.

Using this condition from the user interface

If you prefer building automations visually, Home Assistant walks you through this condition step by step. You pick what to check, tweak a few options, and save. No YAML knowledge required.

To use Button is being held in an automation:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation, or select Create automation > Create new automation.
  3. In the And if section, select Add condition.
  4. Select what you want to check. Under By target (see Targets), select the button event entity you want to check. You can also select a device, an area, a floor, or a label.
  5. From the conditions shown for that target, select Button is being held.
  6. Under Condition passes if (see Behavior), pick Any or All to control how the check behaves when multiple buttons are targeted.
  7. Under For at least, set how long the button must have been held before the condition passes. It must be less than 30 seconds. Leave it at zero to pass as soon as the button is held.
  8. Select Save.

Options in the UI

Condition passes if

When multiple buttons are targeted, controls how results combine. Pick Any to pass if at least one targeted button is being held, or All to pass only when every targeted button is being held. Default is Any.

For at least

How long the button must have been held before the condition passes. The time counts from the latest Long press start of the button, not from when you pushed the button down. Must be less than 30 seconds. Default is zero (passes immediately).

Using this condition in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required. For how an automation is built in YAML, refer to Automations in YAML.

In YAML, put the settings that are specific to this condition under options. Keep target, if the condition uses one, and general settings such as alias and enabled at the top level, next to condition.

In YAML, refer to this condition as button.is_being_held. A basic example looks like this:

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: button.is_being_held
target:
  entity_id: event.hallway_switch_button_1

This passes while button 1 of the hallway switch is held.

To pass only once the button has been held for a while, add for under options:

ConditionConditions check whether something is true at that moment, for example, whether a door is closed. You can use them in automations and scripts. If a condition is not met, the actions that come after it in the same sequence do not run. At the top level of an automation or script, this stops the automation or script. [Learn more]
condition: button.is_being_held
target:
  entity_id: event.hallway_switch_button_1
options:
  for: "00:00:02"

This passes once button 1 has been held for at least 2 seconds.

Options in YAML

behavior string (Optional, default: any)

When multiple buttons are targeted, controls how results combine. Accepts all or any.

for string | integer | map (Optional, default: 00:00:00)

How long the button must have been held before the condition passes. The time counts from the latest long_press_start of the button, not from when you pushed the button down. Must be less than 30 seconds. Accepts a duration string in HH:MM:SS format. For a list of all accepted formats, refer to Durations in automations and scripts.

Targets of the condition

This condition requires a target. The target is the object that Home Assistant will check. You can point the condition at a single entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more], a device, an area, a floor, or a label, and Home Assistant will evaluate every matching button event entity behind that target.

  • Entity: one specific button event entity, such as event.hallway_switch_button_1.
  • Device: every button event entity that belongs to a device.
  • Area: every button event entity in a room or area.
  • Floor: every button event entity on a floor.
  • Label: every button event entity that shares a label.

You can also select different target types in one condition. For example, you can add a specific entity and an area as targets in the same condition to check both of them at once.

To learn which entities Home Assistant includes for a device, area, floor, or label, and how it handles several entities, refer to Automation targets.

To leave out some of these entities, refer to Excluding targets. For example, you can leave out one button event entity in an area.

Behavior with multiple targets

When you target more than one entity (or select an area, floor, or label that contains several), the Condition passes if option controls how the results combine:

  • Any (default): the condition passes if at least one of the targeted entities matches. For example, if you check three smoke sensors and only one of them detects smoke, the condition still passes. This is useful for questions like “is there smoke anywhere in the house?”
  • All: the condition passes only when every targeted entity matches. For example, if you check the same three smoke sensors, the condition passes only once all three report cleared. This is useful for “is the entire house safe now?” checks, so your automation does not send an all-clear while one room still has a reading.

Good to know

  • This condition only checks event entities with the button device class. Button entities (domain button) and button helpers can’t be held, so they are skipped. Event entities with another device class are skipped too, even if you select them directly.
  • A button must support both the Long press start and Long press end event types. Buttons that only report a hold when you release them, or that use their own event types for holds, are always skipped, even though you can still select them as a target. To see which event types a button supports, add an Event received trigger for it, and open the Event type list.
  • Buttons that are unavailable or unknown are skipped. With Any, the condition passes if at least one of the other targeted buttons matches. With All, it passes if all the other targeted buttons match. If all targeted buttons are unavailable or unknown, All passes and Any fails.
  • Entities skipped for the other reasons above count the same way: if all targeted entities are skipped, All passes and Any fails.
  • The condition relies on the button reporting when you release it. If Home Assistant misses the release, for example because it restarted while you held the button, the condition keeps passing until the button reports its next event, for at most 30 seconds.
  • After Home Assistant restarts, or after a held button was unavailable, For at least and the 30-second limit count from when Home Assistant restarted or the button came back, instead of from the start of the hold.
  • To start an automation when a button is held, use the Button held trigger. To react to a short press, use the Button pressed trigger.

Try it yourself

Ready to test this? Go to Settings > Automations & scenes, open an automation, and add this condition. Trigger the automation with and without the condition met, and watch whether it continues or stops.

More examples

Real scenarios where this condition gates an automation. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example or paste the YAML code.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the visual automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.

Automation: give a button a second function while another one is held

Use this automation to give a button of a wall switch a second function. A press of button 2 of the hallway switch turns on the hallway light. If you press it while you hold button 1, it turns on all the lights on the ground floor instead. Hold button 1 until the switch reports a long press, then press button 2. This needs button 1 to report both Long press start and Long press end, and a switch that reports a press of one button while another is held.

  • Trigger: Button pressed
    • Target: Hallway switch button 2 (event.hallway_switch_button_2)
  • Action: If-then
    • If: Button is being held
      • Target: Hallway switch button 1 (event.hallway_switch_button_1)
    • Then: Turn on light
      • Target: Ground floor
    • Else: Turn on light
      • Target: Hallway light (light.hallway)
YAML example for a second button function
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Hallway switch button 2, with a second function while button 1 is held"
triggers:
  - trigger: button.pressed
    target:
      entity_id: event.hallway_switch_button_2
actions:
  - if:
      - condition: button.is_being_held
        target:
          entity_id: event.hallway_switch_button_1
    then:
      - action: light.turn_on
        target:
          floor_id: ground_floor
    else:
      - action: light.turn_on
        target:
          entity_id: light.hallway

Automation: turn off the lights when two buttons are held together

Use this automation to turn off all the lights on the ground floor when you hold both buttons of the hallway switch at the same time. Holding a single button does nothing. The trigger fires when either button is held, and the conditions only pass once both are held. This needs buttons that report both Long press start and Long press end, and a switch that reports each button on its own.

Each button has its own condition. If you use a single condition for both buttons with Condition passes if set to All instead, a skipped button is left out of the check. For example, if button 2 is unavailable, or has not reported any event yet, holding button 1 alone would turn off the lights.

  • Trigger: Button held
    • Target: Hallway switch button 1 (event.hallway_switch_button_1) and Hallway switch button 2 (event.hallway_switch_button_2)
  • Condition: Button is being held
    • Target: Hallway switch button 1
  • Condition: Button is being held
    • Target: Hallway switch button 2
  • Action: Turn off light
    • Target: Ground floor
YAML example for turning off the lights with a two-button hold
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Turn off the ground floor lights when both hallway switch buttons are held"
triggers:
  - trigger: button.held
    target:
      entity_id:
        - event.hallway_switch_button_1
        - event.hallway_switch_button_2
conditions:
  - condition: button.is_being_held
    target:
      entity_id: event.hallway_switch_button_1
  - condition: button.is_being_held
    target:
      entity_id: event.hallway_switch_button_2
actions:
  - action: light.turn_off
    target:
      floor_id: ground_floor

Still stuck?

To find out why the condition didn’t pass, check it live in the automation editor, and look at the trace of the run. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.

If that doesn’t help, the Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the condition you’re using and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain conditions or suggest the right one when you describe what you want in plain language.