ZHA - Xiaomi Mijia Round Wireless Switch (WXKG01LM) - lumi.sensor_switch

Introduction:

This Blueprint allows you to configure an Xiaomi Mijia Round Wireless Switch (WXKG01LM) paired to the ZHA integration. The Zigbee ID for this button is “lumi.sensor_switch”.

It supports six commands - single press, button hold, double press, triple press, quadruple press and “multiple” press, which is basically anything higher than 5 presses (aka “furious”).

Thanks to @jodur for the button hold behavior.

This blueprint is based on ZHA - Aqara Wireless Mini Switch from @SeanM!

As @SeanM mentions on his blueprint:

Also, an additional tip: if you select the “Choose” action type, you can increase the amount of actions each button is capable of executing. For example you can make “double press” activate a scene by default, but make it skip tracks if Spotify is playing, and make it fast forward if you’re watching a movie.

Other Recommended Xiaomi ZHA Blueprints:

Here are some Blueprints I am using for Xiaomi devices using ZHA, which are working great.

ZHA - Xiaomi Aqara Wireless Mini Switch (WXKG11LM) - lumi.sensor_switch.aq2 - by me, @carlosmesquita
ZHA - Aqara Wireless Remote Switch (Double Rocker) - by @NachtaktiverHalbaffe

Requirements:

Blueprint:

You can check the blueprint YAML here if you want, or just try it out by importing it using this topics’ URL:

blueprint:
  name: ZHA - Mijia Wireless Remote Switch (WXKG01LM)
  description: Automate your Xiaomi Mijia Wireless Round Remote Switch using ZHA events.
  domain: automation
  input:
    mijia_round_switch:
      name: Mijia Wireless Round Switch
      description: Mijia Wireless Round Switch to use
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          model: lumi.sensor_switch
    remote_button_short_press:
      name: Single Press
      description: Action to run on single press
      default: []
      selector:
        action: {}
    remote_button_hold_press:
      name: Hold 
      description: Action to run on hold
      default: []
      selector:
         action: {}   
    holdtime:
      name: Time interval for hold detection, in seconds
      description: Time to wait until hold_press is activated
      default: 0.60
      selector:
        number:
          min: 0.15
          max: 2.5
          unit_of_measurement: seconds
          step: 0.05
          mode: slider
    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
      description: Action to run on multiple press
      default: []
      selector:
        action: {}
mode: parallel
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'mijia_round_switch'
action:
- variables:
    click_type: '{{ trigger.event.data.args.click_type }}'
    attrname: '{{ trigger.event.data.args.attribute_name }}'
    value: '{{ trigger.event.data.args.value }}'  
    command: '{{ trigger.event.data.command }}'   
- choose:
  - conditions:
      - '{{ attrname == ''on_off'' }}'
      - '{{ value == true }}'
    sequence:
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'mijia_round_switch'
          command: 'attribute_updated'
          args:
            attribute_id: 0
            attribute_name: on_off
            value: false
      continue_on_timeout: true
      timeout: !input 'holdtime'  
    - choose:
      - conditions:
          - condition: template
            value_template: '{{ not wait.trigger }}'
        sequence: !input 'remote_button_hold_press'
      default: !input 'remote_button_short_press'
  - conditions:
    - condition: template
      value_template: "{{ command == 'click' }}"
    sequence:
    - choose:
      - conditions: "{{ click_type == 'double' }}"
        sequence: !input remote_button_double_press
      - conditions: "{{ click_type == 'triple' }}"
        sequence: !input remote_button_triple_press
      - conditions: "{{ click_type == 'quadruple' }}"
        sequence: !input remote_button_quadruple_press
      - conditions: "{{ click_type == 'furious' }}"
        sequence: !input remote_button_multiple_press

Below you can check the Automation creation screen from this blueprint:

Changelog

  • 2021-04-09: Changed Hold time default value (from 1s to 0.6s), along with the minimum hold time ( from 0 to 0.15s), max time (from 10s to 2.5s) and the step (from 1 to 0.05), to allow more granularity and flexibility. Kudos to @jant90

  • 2021-02-24: Changed Automation Mode from restart to parallel, to fix multiple actions per event not working properly.

  • 2021-01-03: Added hold action & refactored to improve readability. Thanks to @jodur and @123.

  • 2020-12-22: Initial version.

Enjoy! :sunglasses:

19 Likes

Maybe you could also intergrate the longpress in the blueprint? This seems to be missing in ZHA for this button, while in the original Xiaomi gateway this is supported (Also with deconz). You could integrate my automation for this https://community.home-assistant.io/t/longpress-and-shortpress-script-automation-for-xiaomi-round-button-with-zha/229367

3 Likes

Hello @jodur!
I will take a look at that! As you mention, the longpress is not supported by ZHA, but it can be implemented using the ZHA events, as you did with your automation.
Will update here when I got some news.

Both of my switches don’t pop up on the list. Did I miss something?

You are using the Zigbee Home Automation integration, correct?
Go to your devices, and paste here a printscreen of your device here please, something like this:

Hi, this is showing in mine:
there is a device but no entity

Which HA version are you running?
Also, which ZB coordinator are you using?

You can try deleting the device, and re-pairing it, to check if it is recognized properly!

For those that need a hold action, use https://community.home-assistant.io/t/zha-xiaomi-mijia-round-wireless-switch-wxkg01lm-with-hold-lumi-sensor-switch/263075/1

If you’re interested, you can streamline the action like this:

action:
  - variables:
      command: "{{ trigger.event.data.command }}"
      click_type: "{{ trigger.event.data.args.click_type }}"
  - condition: template
    value_template: "{{ command == 'click' }}"
  - choose:
    - conditions: "{{ click_type == 'single' }}"
      sequence: !input remote_button_short_press
    - conditions: "{{ click_type == 'double' }}"
      sequence: !input remote_button_double_press
    - conditions: "{{ click_type == 'triple' }}"
      sequence: !input remote_button_triple_press
    - conditions: "{{ click_type == 'quadruple' }}"
      sequence: !input remote_button_quadruple_press
    - conditions: "{{ click_type == 'furious' }}"
      sequence: !input remote_button_multiple_press
1 Like

@123, thanks a lot for your contribution! That’s a nice improvement, makes it more readable :slight_smile:
Also, @jodur, thanks for taking your time into implementing the hold action!

I have changed my Blueprint to include these 2 improvements, thanks again.

1 Like

I am also having the same issue. the blueprint cannot see the device i have.

removing the device and adding it again solved the problem.

Good to hear that.
Probably the integration has changed since you added the device for the first time, and now recognizes it correctly.

i recently passed from deconz to zha, and i can0t add my xiaomi switch. i paired it, the hub recognised it, but the it goeas in to a loop and i can’t add it as a device. any suggestion? i also try to single press “like a mad the button”, i also try to add it trought an another router (aka an ikea repeater). But nothing seems to work. the system sees it but doesn’t add it.

Hello!
When you say you paired it, you mean adding it via the ZHA integration?
Also, what do you mean by “the system sees it but doesn’t add it”?

Some printscreens might help here :slight_smile:

That is the state. it’s never changed.
Thanks

@nebbiadigiorno, take a look at this post please:

Thanks a lot! it did the trick!!

1 Like

This blueprint is great!. However i’m having an issue that wont allow 2 actions happen when a single click or double click event is pressed.

Example: i’ve added 2 actions to turn on 2 separate lights when a single press is activated.
Only the first action executes however and the second does not.

I’ve tried this also on the double click event but doesn’t work either. It does however work on the hold event?.When the button is held both lights turn on as expected.

Is the issue on my side or can someone else confirm multiple actions work on a single or double click event.

Thanks in advance.