Github Gist: xiaomi_button_zigbee2mqtt.yaml · GitHub
Main features
Define actions for each button press type (single, double, triple, quadruple, many, hold, release).
Supported device
This blueprint support the WXKG01LM device through Zigbee2MQTT only.
Prerequisites
You need to have a sensor entity for the button you want to use from Zigbee2MQTT.
Choose the right sensor with your button name and the entity id which ends with ‘_action’, e.g. ‘sensor.kitchen.button_action’
Blueprint Code
blueprint:
name: Zigbee2MQTT - Mijia Wireless Remote Switch (WXKG01LM) actions
description: >
Define actions your Xiaomi Mijia Wireless Round Remote Switch using Zigbee2MQTT.
This blueprint requires a MQTT topic for your button and the actions you want to take for each button press type.
domain: automation
input:
mqtt_topic:
name: Mijia Wireless Round Switch device name
description: MQTT topic for Mijia Wireless Round Switch. e.g. "zigbee2mqtt/Desk Button"
remote_button_single_press:
name: Single Press
description: Action to run on single press
default: []
selector:
action:
remote_button_double_press:
name: Double Press
description: Action to run on double press
default: []
selector:
action:
remote_button_triple_press:
name: Triple Press
description: Action to run on triple press
default: []
selector:
action:
remote_button_quadruple_press:
name: Quadruple Press
description: Action to run on quadruple press
default: []
selector:
action:
remote_button_multiple_press:
name: Multiple Press (5x or more)
description: Action to run on multiple press
default: []
selector:
action:
remote_button_long_press:
name: Long Press
description: Action to run on long press
default: []
selector:
action:
remote_button_release:
name: Release
description: Action to run on release after long press
default: []
selector:
action:
mode: restart
max_exceeded: silent
trigger:
- trigger: mqtt
topic: !input mqtt_topic
payload: "single"
value_template: "{{ value_json.action }}"
id: "action_single"
- trigger: mqtt
topic: !input mqtt_topic
payload: "double"
value_template: "{{ value_json.action }}"
id: "action_double"
- trigger: mqtt
topic: !input mqtt_topic
payload: "triple"
value_template: "{{ value_json.action }}"
id: "action_triple"
- trigger: mqtt
topic: !input mqtt_topic
payload: "quadruple"
value_template: "{{ value_json.action }}"
id: "action_quadruple"
- trigger: mqtt
topic: !input mqtt_topic
payload: "many"
value_template: "{{ value_json.action }}"
id: "action_many"
- trigger: mqtt
topic: !input mqtt_topic
payload: "hold"
value_template: "{{ value_json.action }}"
id: "action_hold"
- trigger: mqtt
topic: !input mqtt_topic
payload: "release"
value_template: "{{ value_json.action }}"
id: "action_release"
action:
- choose:
- conditions:
- condition: trigger
id: "action_single"
sequence: !input remote_button_single_press
- conditions:
- condition: trigger
id: "action_double"
sequence: !input remote_button_double_press
- conditions:
- condition: trigger
id: "action_triple"
sequence: !input remote_button_triple_press
- conditions:
- condition: trigger
id: "action_quadruple"
sequence: !input remote_button_quadruple_press
- conditions:
- condition: trigger
id: "action_many"
sequence: !input remote_button_multiple_press
- conditions:
- condition: trigger
id: "action_hold"
sequence: !input remote_button_long_press
- conditions:
- condition: trigger
id: "action_release"
sequence: !input remote_button_release
Updating blueprint
Since Z2M 2.0, there are no longer _action
button entities to trigger on, therefore the blueprint has to use MQTT triggers now. For that reason you need to update existing automations slightly. Instead of the old button_sensor
blueprint input, you need to define a mqtt_topic
. An example is zigbee2mqtt/Desk Button
. The second part is the name of your button in Z2M.
Changelog
- 2020-12-22: Initial version
- 2025-01-04: Fixed compatability with Zigbee2MQTT 2.0, not using the
_action
entities anymore, but instead used MQTT triggers.
If you have any issues or questions, please let me know