Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save CrazyCoder/1dc0767b620ccd8535e6a11f9a983d13 to your computer and use it in GitHub Desktop.

Select an option

Save CrazyCoder/1dc0767b620ccd8535e6a11f9a983d13 to your computer and use it in GitHub Desktop.
Aqara Wireless Switch (single, double, hold, release)
blueprint:
name: Aqara Wireless Switch (single, double, hold, release)
description: 'Control anything using Aqara Wireless Switch.
Customizable actions for each press.
This version of the blueprint is for buttons supporting single, double, hold and
release actions. '
domain: automation
input:
controller_device:
name: Aqara Wireless Switch
description: Select the Aqara wireless switch device
selector:
device:
filter:
- integration: mqtt
manufacturer: Aqara
model: Wireless mini switch
automation_mode:
name: Automation mode
description: >-
Leave this alone unless an action in this automation runs for longer
than about a second. The device sends several events for one gesture,
about a second apart, and with 'restart' a later event cancels the
action that an earlier event started. A long action belongs in a script
that you call with 'script.turn_on', which no mode can interrupt.
default: restart
selector:
select:
mode: dropdown
options:
- single
- restart
- queued
- parallel
press_single:
name: Single button press
description: Action to run on single button press
default: []
selector:
action: {}
press_double:
name: Double button press
description: Action to run on double button press
default: []
selector:
action: {}
press_hold:
name: Button hold
description: Action to run on hold
default: []
selector:
action: {}
press_release:
name: Button release
description: Action to run on release
default: []
selector:
action: {}
source_url: https://gist.github.com/CrazyCoder/1dc0767b620ccd8535e6a11f9a983d13
mode: !input automation_mode
trigger:
- trigger: device
id: single
domain: mqtt
device_id: !input controller_device
type: action
subtype: single
- trigger: device
id: double
domain: mqtt
device_id: !input controller_device
type: action
subtype: double
- trigger: device
id: hold
domain: mqtt
device_id: !input controller_device
type: action
subtype: hold
- trigger: device
id: release
domain: mqtt
device_id: !input controller_device
type: action
subtype: release
action:
- choose:
- conditions:
- condition: trigger
id: single
sequence: !input press_single
- conditions:
- condition: trigger
id: double
sequence: !input press_double
- conditions:
- condition: trigger
id: hold
sequence: !input press_hold
- conditions:
- condition: trigger
id: release
sequence: !input press_release
@CrazyCoder

Copy link
Copy Markdown
Author

The blueprint now has an automation_mode input. The default is restart, which is what the blueprint used before, so an existing automation keeps its behaviour.

Change it only if an action in one branch runs for longer than about a second. One gesture produces several events. A hold sends hold, then release about one second later. With restart the release event cancels the action that hold started.

Measured here on 2026-09-01. The button sent hold at 08:14:51 and release at 08:14:52. The automation called a script that turns on a buzzer, announces over TTS, waits 10 seconds, then closes a garage door. The script entity went on at 08:14:51 and off at 08:14:52. It never reached the delay, so the door stayed open. Home Assistant logged no error, and the buzzer still sounded, so it looked like a partial success.

A mode change is not the best fix for that case. Call the script with action: script.turn_on and a target: instead. Home Assistant then runs it in its own task, outside the caller's cancellation scope, so no automation mode can cancel it. script.turn_off still stops it when you want to abort.

Home Assistant substitutes blueprint inputs before it validates the schema, so mode: !input automation_mode is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment