Automate your Xiaomi Aqara Wireless Double Rocker WXKG02LM using ZHA events

This blueprint works with the 2016 WXKG02LM model. I have not found another blueprint on the forums or elsewhere that works with this specific model, so I created my own.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: ZHA - Aqara Wireless Double Rocker WXKG02LM
  description: Automate your Xiaomi Aqara Wireless Double Rocker WXKG02LM using ZHA events.
  domain: automation
  input:
    aqara_switch:
      name: Select the switch
      description: Aqara Wireless Double Rocker WXKG02LM
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          entity:
            domain: sensor
            device_class: battery
    button_single_press_left:
      name: Single Press Left
      description: Action to run on single press
      default: []
      selector:
        action:
    button_single_press_right:
      name: Single Press Right
      description: Action to run on single press
      default: []
      selector:
        action:
    button_single_press_both:
      name: Single Press Both Buttons
      description: Action to run on single presses
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input aqara_switch

action:
  - variables:
      command: "{{ trigger.event.data.endpoint_id }}"
      command2: "{{ trigger.event.data.args.value }}"

  - choose:
      - conditions:
          - "{{ command == 1 }}"
          - '{{ command2 == "Bool.true" }}'
        sequence: !input button_single_press_left
      - conditions:
          - "{{ command == 2 }}"
          - '{{ command2 == "Bool.true" }}'
        sequence: !input button_single_press_right
      - conditions:
          - "{{ command == 3 }}"
          - '{{ command2 == "Bool.true" }}'
        sequence: !input button_single_press_both

This blueprint does not work for me :frowning: despite the fact that I have the mentioned switch. When creating automation, when selecting a device at first, it does not offer any and displays the message: No matching devices were found.
What I noticed, I don’t have it as a “sensor”, but as a “remote”. Specifically: “remote.b286acn01”
Apparently there will be a problem. But I don’t know how to solve it.

1 Like

Hi, I have never gotten the device to register as a remote. Have you tried repairing the device? And just to confirm, you are using ZHA, right?

I’ve used deconz previously and this device seems to work better with deconz, not sure why. But with ZHA you get duplicate events etc. So toggling a light (which was my plan), doesn’t work with this blueprint very well.

The switch WXKG02LM is integrated via the Xiaomi gateway DGNWG02LM and he made it as a “remote”. Probably. Because I don’t remember that I would configure it as a “remote”.

I see, because if you are not using it with ZHA, then this blueprint will not work for you unfortunately

Hello,
I suspected that the integration via the Xiaomi gateway was to blame. You, and even my own experience, confirmed it to me. Yesterday I received the ordered Skyconnect, where I integrated the switch and everything works beautifully for the first time. AWESOME. Thanks for your time, responses, sorry for spamming because of my inexperience. Thank you again. :wink:

btw. I was originally thinking of deleting my comments from this thread, but maybe this experience will help someone. Or?

No worries! Great to be of help;)

Definitely don’t delete your comments as it might help someone out in the future:)

Hi,

When pressing a button, the action is performed 2 times at the press and at the realease.
Activate :

endpoint_id: 1
  cluster_id: 6
  command: attribute_updated
  args:
    attribute_id: 0
    attribute_name: on_off
    value: 1
  params: {}
origin: LOCAL
time_fired: "2023-04-23T15:07:29.282563+00:00"
context:
  id: 01GYQAFQ422Z1RGWTZB8SSKJ3Q
  parent_id: null
  user_id: null

Release :

 endpoint_id: 1
  cluster_id: 6
  command: attribute_updated
  args:
    attribute_id: 0
    attribute_name: on_off
    value: 0
  params: {}

Isn’t there a way to work on the bet a one rather than on the event?
(Sorry I’m very new …)

Thanks for your return

Etienne

After this modifications it will be ok for me :

action:
- variables:
    command: '{{ trigger.event.data.endpoint_id }}'
    command2: '{{ trigger.event.data.args.value }}'
- choose:
  - conditions:
    - '{{ command == 1 }}'
    - '{{ command2 == "Bool.true" }}'
    sequence: !input button_single_press_left
  - conditions:
    - '{{ command == 2 }}'
    - '{{ command2 == "Bool.true" }}'
    sequence: !input button_single_press_right
  - conditions:
    - '{{ command == 3 }}'
    - '{{ command2 == "Bool.true" }}'
    sequence: !input button_single_press_both

1 Like

This is perfect! Just updated the gist on GitHub. Thanks for improving upon this, helps me out a ton:)

Perfect for me! Great Job!

This is not working for me. I have the same model (WXKG02LM) and I can’t get anything working. Could anyone give me some help? Thank you!

1 Like

Hello this blueprint was working fine, but now I get a strange error:

“Choose: No action taken”

When I press the button, the automation is triggered but the trace timeline shows that it exits without taking any action.


Triggered by the event 'zha_event' at 8 décembre 2023 à 15:58:07
DĂ©finir les variables command et command2
Choose: No action taken
Finished at 8 décembre 2023 à 15:58:07 (runtime: 0.10 seconds)

Any idea would be more than welcome!