Skip to content

Instantly share code, notes, and snippets.

@thomasmaxson
Last active December 21, 2025 19:14
Show Gist options
  • Select an option

  • Save thomasmaxson/67dc65d3cf0725f3d2088d38ba9f0234 to your computer and use it in GitHub Desktop.

Select an option

Save thomasmaxson/67dc65d3cf0725f3d2088d38ba9f0234 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint to control your devices with an Aqara Wireless Mini Switch using ZHA.
# This blueprint uses an Aqara Mini Switch Remote Control connected through ZHA and MQTT
# This blueprint allows you to control lights and run custom actions with the remote's buttons
#
# | Button Type | Interaction | Action Choices |
# | ------------- | ------------ | ----------------------- |
# | Main Button | Single Press | - Toggle light(s) state |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Main Button | Double Press | - Toggle light(s) state |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Main Button | Press & Hold | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Main Button | Release | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Remote | Shake | - Run custom action |
# | ------------- | ------------ | ----------------------- |
blueprint:
name: Aqara, Wireless Mini Switch
description: Control lights or devices with your Aqara Wireless Mini Switch.
author: Thomas Maxson
source_url: https://gist.github.com/thomasmaxson/67dc65d3cf0725f3d2088d38ba9f0234
homeassistant:
min_version: 2024.6.0
domain: automation
input:
remote:
name: Aqara Wireless Mini Switch
description: Aqara Mini Switch remote used to trigger actions.
selector:
device:
multiple: false
filter:
- manufacturer: Aqara
model: Wireless mini switch (with gyroscope) (WXKG12LM)
- manufacturer: Aqara
model: Wireless mini switch (with gyroscope)
- integration: mqtt
manufacturer: Xiaomi
model: WXKG11LM
- integration: zha
manufacturer: LUMI
model: lumi.remote.b1acn01
button_single_press_config:
name: Single Press Configuration
icon: mdi:gesture-tap
collapsed: true
input:
event_button_press_single:
name: Single Press Event Type
description: >-
Select the event you want the **Button** to do.
<br>&bull; _Toggle light_: Toggle the power state of the light(s)
<br>&bull; _Custom Action_: Trigger your own custom action
default: "Toggle light"
selector:
select:
options:
- Toggle light
- Custom action
light_press_single:
name: Single Press Light(s)
description: Select the light entities you wish to control.
default: []
selector:
entity:
multiple: true
filter:
domain: light
action_button_press_single:
name: Single Button Press Event
description: The action to perform on _single press_ of the **Button**.
default: []
selector:
action: null
button_double_press_config:
name: Double Press Configuration
icon: mdi:gesture-double-tap
collapsed: true
input:
event_button_press_double:
name: Double Press Event Type
description: >-
Select the event you want the **Button** to do.
<br>&bull; _Toggle light_: Toggle the power state of the light(s)
<br>&bull; _Custom Action_: Trigger your own custom action
default: "Toggle light"
selector:
select:
options:
- Toggle light
- Custom action
light_press_double:
name: Double Press Light(s)
description: Select the light entities you wish to control.
default: []
selector:
entity:
multiple: true
filter:
domain: light
action_button_press_double:
name: Double Press Button Event
description: The action to perform on _double press_ of the **Button**.
default: []
selector:
action: null
button_other_events:
name: Other Button Events
icon: mdi:gesture-tap
collapsed: true
input:
action_button_press_hold:
name: Button Press & Hold Event
description: The action to perform on _press and hold_ of the **Button**.
default: []
selector:
action:
action_button_press_release:
name: Button Release Event
description: The action to perform on _release_ of the **Button**.
default: []
selector:
action:
action_device_shake:
name: Device Shake Event
description: >-
The action to perform on _shake_ of the **Device**.
<br>This interaction type is only available on devices with a gyroscope.
default: []
selector:
action:
automation_config:
name: Configuration
icon: mdi:cog
collapsed: true
input:
config_mode:
name: Automation Mode
description: Mode that automation runs in.
default: restart
selector:
select:
options:
- single
- restart
- queued
- parallel
custom_value: false
multiple: false
config_max_num:
name: Mode Max
description: >
Maximum number of runs that can be executed or queued at a time.
<br>Ignored by _Single_ and _Restart_ Modes.
default: 10
selector:
number:
mode: slider
unit_of_measurement: runs
min: 1.0
max: 15.0
step: 1.0
mode: !input config_mode
max: !input config_max_num
max_exceeded: silent
variables:
var_remote: !input remote
var_light_press_single: !input light_press_single
var_light_press_double: !input light_press_double
var_event_button_press_single: !input event_button_press_single
var_event_button_press_double: !input event_button_press_double
var_action_button_press_hold: !input action_button_press_hold
var_action_button_press_release: !input action_button_press_release
var_action_device_shake: !input action_device_shake
triggers:
- alias: Button Press Once (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: single
id: trigger_press_single_zha
- alias: Button Press Once (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: single
id: trigger_press_single_mqtt
- alias: Button Press Twice (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: double
id: trigger_press_double_zha
- alias: Button Press Twice (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: double
id: trigger_press_double_mqtt
- alias: Button Press and Hold (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: hold
id: trigger_hold_zha
- alias: Button Press and Hold (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: hold
id: trigger_hold_mqtt
- alias: Button Release (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: release
id: trigger_release_zha
- alias: Button Release (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: release
id: trigger_release_mqtt
- alias: Button Shake (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: shake
id: trigger_shake_mqtt
conditions:
- condition: template
value_template: "{{ var_remote | count > 0 }}"
actions:
- variables:
var_all_lights_on_single: >-
{{ expand( var_light_press_single ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | unique | list }}
var_all_lights_off_single: >-
{{ expand( var_light_press_single ) | selectattr( "state", "eq", "off" ) | map( attribute = "entity_id" ) | unique | list }}
var_first_light_on_single: >-
{{ [] if ( var_light_press_single | length <= 0 ) else expand( var_light_press_single ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | unique | list | first }}
var_all_lights_on_double: >-
{{ expand( var_light_press_double ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | unique | list }}
var_all_lights_off_double: >-
{{ expand( var_light_press_double ) | selectattr( "state", "eq", "off" ) | map( attribute = "entity_id" ) | unique | list }}
var_first_light_on_double: >-
{{ [] if ( var_light_press_double | length <= 0 ) else expand( var_light_press_double ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | unique | list | first }}
- choose:
- conditions:
- condition: trigger
id:
- trigger_press_single_zha
- trigger_press_single_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For Single button press, toggle light state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_press_single == 'Toggle light' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_light_press_single | length > 0 }}"
sequence:
- alias: "Determine weather to turn the light(s) on or off"
if:
- alias: "Check if the light(s) are currently off"
condition: template
value_template: "{{ var_all_lights_on_single | length == 0 }}"
then:
- alias: "Turn on light(s)"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_off_single }}"
else:
- alias: "Turn off light(s)"
action: light.turn_off
target:
entity_id: "{{ var_all_lights_on_single }}"
- alias: "For Single press, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_press_single == 'Custom action' }}"
sequence: !input action_button_press_single
- conditions:
- condition: trigger
id:
- trigger_press_double_zha
- trigger_press_double_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For Double button press, manage light on/off state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_press_double == 'Toggle light' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_light_press_double | length > 0 }}"
sequence:
- alias: "Determine weather to turn the light(s) on or off"
if:
- alias: "Check if the light(s) are currently off"
condition: template
value_template: "{{ var_all_lights_on_double | length == 0 }}"
then:
- alias: "Turn on light(s)"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_off_double }}"
else:
- alias: "Turn off light(s)"
action: light.turn_off
target:
entity_id: "{{ var_all_lights_on_double }}"
- alias: "For Double press, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_press_double == 'Custom action' }}"
sequence: !input action_button_press_double
- conditions:
- condition: trigger
id:
- trigger_hold_zha
- trigger_hold_mqtt
sequence: !input action_button_press_hold
- conditions:
- condition: trigger
id:
- trigger_release_zha
- trigger_release_mqtt
sequence: !input action_button_press_release
- conditions:
- condition: trigger
id:
- trigger_shake_zha
- trigger_shake_mqtt
sequence: !input action_device_shake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment