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

Tags: #<Tag:0x00007f326ccfac88> #<Tag:0x00007f326ccfab98> #<Tag:0x00007f326ccfaad0> #<Tag:0x00007f326ccfa990> #<Tag:0x00007f326ccfa8c8>

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.

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: 1
      selector:
        number:
          min: 0.0
          max: 10.0
          unit_of_measurement: seconds
          step: 1.0
          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: restart
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-01-03: Added hold action & refactored to improve readability. Thansk to @jodur and @123.
  • 2020-12-22: Initial version.

Enjoy! :sunglasses:

5 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.