Zigbee2MQTT - Xiaomi Mijia Round Wireless Remote Switch (WXKG01LM) actions

Github Gist: https://gist.github.com/freakshock88/cbc0909e874cf82118a843721d72f656

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.
    For your button entity, choose the right sensor with your button name and the entity id which ends with '_action', e.g. 'sensor.kitchen.button_action'
  domain: automation
  input:
    button_sensor:
      name: Mijia Wireless Round Switch sensor entity
      description: Sensor for Mijia Wireless Round Switch to use (Use sensor with entity_id ends with _action)
      selector:
        entity:
          domain: sensor
    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

# Each option is explicitly defined as a trigger because sensor reports empty values as well. 
# Not defining explicit triggers causes the automation to show up in the log multiple times per button press.
trigger:
  - platform: state
    entity_id: !input button_sensor
    to: 'single'
  - platform: state
    entity_id: !input button_sensor
    to: 'double'
  - platform: state
    entity_id: !input button_sensor
    to: 'triple'
  - platform: state
    entity_id: !input button_sensor
    to: 'quadruple'
  - platform: state
    entity_id: !input button_sensor
    to: 'many'
  - platform: state
    entity_id: !input button_sensor
    to: 'hold'
  - platform: state
    entity_id: !input button_sensor
    to: 'release'

action:
  - variables:
      action: "{{ trigger.to_state.state }}"

  - choose:
      - conditions: "{{ action == 'single' }}"
        sequence: !input remote_button_single_press
      - conditions: "{{ action == 'double' }}"
        sequence: !input remote_button_double_press
      - conditions: "{{ action == 'triple' }}"
        sequence: !input remote_button_triple_press
      - conditions: "{{ action == 'quadruple' }}"
        sequence: !input remote_button_quadruple_press
      - conditions: "{{ action == 'many' }}"
        sequence: !input remote_button_multiple_press
      - conditions: "{{ action == 'hold' }}"
        sequence: !input remote_button_long_press
      - conditions: "{{ action == 'release' }}"
        sequence: !input remote_button_release

Changelog

  • 2020-12-22: Initial version

If you have any issues or questions, please let me know :slight_smile:

8 Likes

Thx for sharing, used it while setting up a new zigbee2mqtt integration.

can you add the sun condition to this great plan?

You can add a condition action yourself: https://www.home-assistant.io/docs/automation/action/

Hello.
I use this and im happy with this blueprint.
My problem is that in one condition I use a “wait for 2 hours” and the and action.
This action never run.
Do you know if exist any problem in use a wait so long?

Can you post your automation in YAML format?

Off course.
the automation is simple:

  • wait 2 hours
  • send ir comand to shutdown a fan
  • turn off boolean
  • wait 1 hour
  • send ir command to shutdown the same fan (security if the fan still on)
    remote_button_long_press:
      - delay:
          hours: 2
          minutes: 0
          seconds: 0
          milliseconds: 0
      - service: remote.send_command
        data:
          device: Lampara_Dormitorio
          command: Apagar
          num_repeats: 1
          delay_secs: 0.4
          hold_secs: 0
        target:
          device_id: xxxxxxxxxxx
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.p1_dormi_ventilador
      - delay:
          hours: 1
          minutes: 0
          seconds: 0
          milliseconds: 0
      - service: remote.send_command
        data:
          device: Lampara_Dormitorio
          command: Apagar
          num_repeats: 1
          delay_secs: 0.4
          hold_secs: 0
        target:
          device_id: xxxxxxxxxxxx