Xiaomi button switch with ZHA integration

Hey everyone,
I’m trying to switch from xiaomi gateways to ZHA integration with a sonoff zigbee bridge.
There are several similar posts in the community but I’m trying to consolidate information and maybe find a solution i missed.

So, the button does not pair up well. Im testing with WXKG01LM - which i think is the first round button version.

You need to longpress the pair button and then keep single pressing it like mad until it is discovered by the ZHA integration.
source:

and Xiaomi WXKG01LM control via MQTT | Zigbee2MQTT

After it gets discovered by ZHA, it only appears as a battery (for me is at 100% - which i do not believe is accurarte)
No switch entity is registered for the button.

To use the button you need to:

That works and returns different events fired according to how many times you press it.
I get single, double, triple, quadruple and furious (5+ presses).
It does not return “hold” or any long press indication which did work with the original xiaomi gateway integration.

Are there any solutions around to the connection issues?
Any way to track the hold action?
Any template binary_switch example to configure the button as a switch?

Any further information I have missed?

Edit: I also figured out that going to Configuration → Integrations → Zigbee, Configure → Devices → Button in question → Automations Panel and click the + sign, It gives you the option to create automations for single, double, triple, quadruple and quintuple presses. So this solves a lot.

Edit2: I had a button that gave me a hard time connecting. Nothing appearing in logs etc.
I paired with the xiaomi gateway, unpaired it and it connected to ZHA on the first try.

2 Likes

By default this device exposes a deprecated click event. It’s recommended to use the action event instead.

So try setting the “legacy: false” in the config for this switch, then try listening for the command “action” instead. You might have more luck with that.

 trigger:
  - event_data:
      args:
      - double
    command: action
    device_ieee: 00:15:8d:00:01:25:63:f6
    event_type: zha_event
    platform: event

You should open the event viewer and listen for the zha_events to see what this new click shows up as, then modify your trigger accordingly.

I am following the UI way, setting up my automations like this:

Is this the “depreciated” method?

If you didn’t set the legacy method in the zigbee2mqtt configuration.yaml, then yes.

Once you change it there, you won’t have to change your automations at all. The MQTT topic will be updated and the exact same trigger would be used. That’s the benefit of a device trigger…it’s auto determined by the device.

Well, you might have to go back into the UI and take a look to see if it’s the same trigger name or not.

# In zigbee2mqtt configuration.yaml
devices:
  '0x12345678':
    friendly_name: Xiaomi Button 5
    legacy: false

You will have to figure out the device ID. It’s probably in home assistant if you can find more info about it.

I am using ZHA integration, I believe this is different than zigbee2mqtt. No?

Oh, my bad. I confused the links in the original with you using zigbee2mqtt. You are right, this is a completely different thing.

This button has been confirmed to work with zha, and ‘hold’ is a reported click event.

I’m not sure…maybe try a firmware update?

Firmware update on what? The button?
How would I do that, no idea.

Nevermind, Im going through the documentation. I was so excited last time I stopped reading as soon as I got it running :slight_smile:

I can recommend the ControllerX add on for use with all Zigbee buttons. Rather than each input being in a different automation, you can set all the inputs in one place.

Personally use it with a Xiaomi button as well as Hue and Osram dimmers and it works a treat.

1 Like

Interesting, I’ll check it out.

Hey Harry,
My WXKG01LM paired via ZHA integration is also missing the hold and release events.
You mention in your previous post you got it running? Did you manage to update firmware or what did you do?

Edit: I found a solution via this blueprint posted by another user at this link:

No, it only reports 1,2,3 and 4 clicks.
I’ll check the blueprint out, thank you!

Regarding battery reporting, i think its not supported, it only shows low-batter-warning funcitonality in the blakadder site, whereas otherones support bat percentage.
How this warning will appear to me, i have no idea, ill just have to wait and see…

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.