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

This makes me think about what I’ve read in the zigbee2mqtt docs some time ago about this button
and the configurable hold timeout:

  • hold_timeout: The WXKG01LM only reports a button press and release.By default, a hold action is published when there is at least 1000 ms between both events. It could be that due to delays in the network the release message is received late. This causes a single click to be identified as a hold action. If you are experiencing this you can try experimenting with this option (e.g. set it to 2000) (value is in ms). The value must be a number with a minimum value of 0

changelog of this blueprint:

  • 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

It could be that you have enough delay in the zigbee network that the release from a single press comes in too late and thats why It gets detected as a hold action. Try editing the blueprint to increase the hold time to a higher value again. Maybe this solves the issue

1 Like

Incredible work mate - I was troubleshooting some general lag in my entire system, which turned out to be caused by a very niche custom component that the author very kindly rebuilt to prevent any more issues.

You were spot on though, the integration was causing my HA to lag so much that single presses were being interpreted as hold actions. As soon as the integration was fixed, this problem went away.

Thanks for your help mate :pray:

Am I missing something here? I can’t see the actual blueprint import button in the topic anymore.

In the first post:
image

For those like me who are visual :slight_smile:

Thank you very much, I’d given up on this button thinking that I needed the Xiaomi gateway and the unusual handling of how clicking the button doesn’t show anything on the Device Info page where for other devices you can see all its sensors or diagnostics

I know this is an old Post but I could really use some help / fear that this is not working anymore.
I have recently bought a couple of the Switches and they are not able to pair with the HA SkyConnect Zigbee USB. The switches do not have any reset / pairing button and when pressing the switch for 5s they blink quickly twice, but nothing else happens.
On the Zigbee Connection page, no devices are visible.

Anybody any idea?

Pairing the device is not related to this blueprint.

With battery zigbee devices you often need to keep activating them to keep them from going to sleep whilst you try to pair them.

Since one of the last updates from HA (2014.6 I think) my automations with “remote_button_short_press” won’t work anymore on any of my buttons.

Other events are still working. Anyone has an idea?

1 Like

As of HA 2024.8.0b01 (August Beta) this Blueprint is not working for me for short and long press functions. Double tap seems to still be working.

The automation gets to the choose section for figuring out what to do based on click type and then does nothing. I’m trying to get more info from the traces.

3 Likes

Same on 2024.8.0…

Listening to zha_event in developer tools I see:

Single click has

  args:
    attribute_id: 0
    attribute_name: on_off
    attribute_value: false

and double click has

  args:
    attribute_id: 32768
    attribute_name: Unknown
    attribute_value: 2

Triple and quadruple click has an attribute_value of 3 and 4 respectively, and 5 is more clicks has an attribute_value of 128 with the other values the same as double click.

1 Like

Since I use a number of these buttons including for my doorbell I decided to move the automations over to Switch Manager just now. They are working perfectly there.

1 Like

I had the same issues on 2024.8.0.

Managed to make it working by commenting the condition:

“{{ value == true }}”

This is my working blueprint:

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: null
    remote_button_hold_press:
      name: Hold
      description: Action to run on hold
      default: []
      selector:
        action: null
    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: null
    remote_button_triple_press:
      name: Triple Press
      description: Action to run on triple press
      default: []
      selector:
        action: null
    remote_button_quadruple_press:
      name: Quadruple Press
      description: Action to run on quadruple press
      default: []
      selector:
        action: null
    remote_button_multiple_press:
      name: Multiple Press
      description: Action to run on multiple press
      default: []
      selector:
        action: null
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
1 Like

Nice try :+1:t2:
But it doesn’t work if you have a choose action in your automation (like 100% of the cases in my house :grimacing:), HA considers two separate simple clicks… :face_with_diagonal_mouth:

On the other hand, I saw something a few lines above and changing :

value: "{{ trigger.event.data.args.value }}"

by

value: "{{ trigger.event.data.args.attribute_value }}"

Everything is working again :ok_hand:t2:

.
Note: without your modification…

7 Likes

after the last update and the one-click button didn’t work, this was the solution, thank you very much

Thanks, it worked perfect.

Hi guys,

I’m trying to use my Mi Wireless Switches with my HA.

I used them previously with my Mi Home App through an Aqara Gateway. Now I got a Zigbee Dongle-E and I managed to pair them via ZHA and do some automations.

The problem I’m having is that they’re stopping being connected to ZHA.

After config I leave them without tap and they just disconnect and I have to pair them again.

This way they’re not useful, I have no idea what to do.

Thank you for your attention.

thanks, this also works for me too!

I’ve changed the line as stated in the blueprint (value → attribute_value). After restarting single press is not working for me.
I have 3 scene:
single: scene_warm
hold : scene_off
double: scene_cold
double and hold works with the patch but not single :frowning:

Any ideas ?