Button held
Use this trigger when you want an automation to run when a button is held down. It works with event entities that have the button device class, such as the buttons of a remote control or a wall switch. This is useful to give a button a second function, like turning off all the lights in a room when you hold it.
You can also make the trigger fire again at a set interval for as long as the button stays held. This is useful to keep changing something while you hold the button, like dimming a light or turning up the volume.
Using this trigger from the user interface
If you prefer building automations visually, Home Assistant walks you through this trigger step by step. You pick what to watch, tweak a few options, and save. No YAML knowledge required.
To use this trigger in an automation:
- Go to Settings > Automations & scenes.
- Open an existing automation, or select Create automation > Create new automation.
- In the When section, select Add trigger.
- Select what you want to monitor. Under By target (see Targets), select the button event entity you want to monitor. You can also select an area, a floor, a device, or a label.
- From the triggers shown for that target, select Button held.
- Optional: To make the trigger fire again while the button stays held, select Interval, and enter how often. If you don’t select Interval, the trigger fires once per hold.
- Select Save.
Options in the UI
How often to fire again while the button stays held. Must be more than 0 and less than 30 seconds. Only buttons that report both Long press start and Long press end repeat. Other buttons fire once per hold. Repeats stop after 30 seconds, even if the button is still held. If you don’t select it, the trigger fires once per hold.
Using this trigger 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 trigger under options. Keep target, if the trigger uses one, and general settings such as id, alias, enabled, and variables at the top level, next to trigger.
When this trigger starts an automation, it passes data about what happened to the automation. You can use this trigger data in the templates of your conditions and actions. To see which data is available, refer to Trigger data in templates.
In YAML, refer to this trigger as button.held. A basic example looks like this:
trigger: button.held
target:
entity_id: event.bedroom_switch_button
This fires once every time the button of event.bedroom_switch_button is held.
To fire again every half second for as long as the button stays held:
trigger: button.held
target:
entity_id: event.living_room_remote_brightness_up
options:
interval:
milliseconds: 500
Options in YAML
How often to fire again while the button stays held. Leave it out to fire once per hold. Must be more than 0 and less than 30 seconds. Only buttons that report both Long press start and Long press end repeat. Other buttons fire once per hold. Repeats stop after 30 seconds, even if the button is still held. Accepts a duration string in HH:MM:SS format, such as "00:00:01.5", or a time period mapping, such as milliseconds: 500. For a list of all accepted formats, refer to Durations in automations and scripts.
Targets of the trigger
This trigger requires a target. The target is the object that Home Assistant will watch. You can select 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 as a target, and Home Assistant will watch every matching button event entity behind that target.
-
Entity: one specific button event entity, such as
event.living_room_remote_brightness_up. - 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 trigger. For example, you can add a specific entity and an area as targets in the same trigger to monitor 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.
Trigger variables
When the trigger reacts, the trigger variable contains the following data:
-
trigger.entity_id: Entity ID of the button event entity that is held. -
trigger.from_state: State object of the entity before the hold was reported. -
trigger.to_state: State object of the entity when the hold was reported. The repeats while the button stays held use the samefrom_stateandto_state. -
trigger.repeat_count:0for the run when the hold is reported, then1,2, and so on for each repeat while the button stays held. -
trigger.description:state offollowed by the entity ID for the first run, such asstate of event.living_room_remote_brightness_up. For each repeat, it’shold offollowed by the entity ID.
This trigger doesn’t include trigger.for.
For example, use {{ trigger.repeat_count }} in a condition to only run an action after the button has been held for a while.
For the data that all triggers include, refer to Trigger data in templates.
Good to know
- This trigger works with event entities with the button device class (domain
event). Event entities with another device class are skipped, even if you select them directly. Button entities and button helpers can’t report a hold, so they don’t work with this trigger. - This trigger reacts to a single event type, so a hold reported as several event types doesn’t fire it twice. It uses the first of these event types that the entity supports:
-
Long press start (
long_press_start), when the button has been pushed down for a while -
Long press end (
long_press_end), when the button is released after a hold, for buttons that only report a hold on release
-
Long press start (
- You can still select a button event entity that supports neither of the event types above, but it never starts the automation. Each event it receives records a Did not trigger trace instead. For details, refer to Testing automations.
- The trigger only fires again at the interval for button event entities that support both Long press start and Long press end, since Home Assistant needs both to know when the hold ends. For other button event entities, the trigger fires once per hold, even if you set an interval. To see which event types a button supports, add an Event received trigger for it, and open the Event type list.
- The first repeat comes one interval after the trigger first fires. Repeating stops when:
- The button is released, or the entity receives any other event.
- The entity becomes unavailable or is removed.
- The entity is no longer part of the target, for example, because you moved its device to another area.
- 30 seconds have passed since the trigger first fired. This limit stops the repeats if Home Assistant misses the release of the button.
- If you select several buttons, each held button repeats on its own interval.
- Each repeat starts a new run of the automation. If the previous run is still going, the automation mode decides what happens. With the default Single mode, the repeat is skipped and a warning is logged. Each repeat also records its own trace, so a long hold can replace the traces of earlier runs. For details, refer to Why the trace you want is missing.
- Changes to Unavailable or Unknown don’t count as holds. The first hold after Home Assistant starts also counts, even if the entity showed Unknown before. If the entity comes back from Unavailable, that recovery doesn’t count as a hold.
- To react to the release of the button after a hold, use the Button hold ended trigger.
- To react to a press of the same button, use the Button pressed trigger. If the button reports Press start but neither Single press nor Press end, Button pressed also fires when you hold the button. To react to a double or triple press, use the Number of presses option of Button pressed. To react to other event types, use the Event received trigger instead.
Try it yourself
Ready to test this? Go to Settings > Automations & scenes, create a new automation, and add this trigger. Save the automation, and then make the trigger react. For example, change the state of the targeted 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], turn on a light that the trigger monitors, or change its brightness. To check whether the automation ran, open its traces.
More examples
Real scenarios where this trigger fires in automations and scripts. Copy any example and adapt it to your setup. In the visual editor, select the UI options listed in the example when they are available, or paste the YAML code.
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: brighten a light while a remote button is held
Use this automation to keep making a light brighter for as long as you hold a button on your remote control. This needs a button that reports both Long press start and Long press end.
-
Trigger: Button held
- Target: Living room remote brightness up button
- Interval: 500 milliseconds
-
Action: Turn on light
- Target: Living room light
- Brightness step: 10%
YAML example for brightening a light while a button is held
alias: "Brighten the living room light while the remote button is held"
triggers:
- trigger: button.held
target:
entity_id: event.living_room_remote_brightness_up
options:
interval:
milliseconds: 500
actions:
- action: light.turn_on
target:
entity_id: light.living_room
data:
brightness_step_pct: 10
Automation: turn off all lights after a long hold of a button
Use this automation to turn off all the lights on a floor when you hold a wall switch button for a few seconds, so a short hold doesn’t turn them off by accident. The trigger fires every second after the hold starts, and the condition only lets the third repeat through. This needs a button that reports both Long press start and Long press end.
-
Trigger: Button held
- Target: Hallway switch button
- Interval: 1 second
-
Condition: Template
-
Value template:
{{ trigger.repeat_count == 3 }}
-
Value template:
-
Action: Turn off light
- Target: Ground floor
YAML example for turning off all lights after a long hold
alias: "Turn off all ground floor lights after holding the hallway button"
triggers:
- trigger: button.held
target:
entity_id: event.hallway_switch_button
options:
interval:
seconds: 1
conditions:
- "{{ trigger.repeat_count == 3 }}"
actions:
- action: light.turn_off
target:
floor_id: ground_floor
Still stuck?
To find out why the trigger didn’t react, make the change that it should react to, and then open the traces of the automation. If the automation didn’t run, there’s usually no trace, but some triggers record a Did not trigger trace. 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 trigger you’re using and what you expected to happen, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain triggers or suggest the right one when you describe what you want in plain language.
Related triggers
Explore related triggers:
-
Button hold ended: Triggers when one or more buttons are released after being held.
-
Button pressed: Triggers when one or more buttons are pressed.
-
Event received: Triggers when one or more event entities receive a matching event type.