Z2M - Aqara D1 Wireless Remote Switch (Double)

This blueprint is designed to work with the Aqara D1 Wireless Remote Switch (Double Rocker) using a Zigbee2mqtt action sensor. It allows configurable actions for left, right, both, single, double, and hold.

Blueprint:

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

blueprint:
  name: Z2M - Aqara D1 Wireless Remote Switch (Double)
  domain: automation
  input:
    remote:
      name: Remote
      description: Zigbee2mqtt Action Sensor
      selector:
        entity:
          integration: mqtt
          domain: sensor
    condition:
      name: Condition
      description: Condition to test before handling a button press
      default: []
      selector:
        action:
    left_click:
      name: Left Single
      default: []
      selector:
        action:
    left_double:
      name: Left Double
      default: []
      selector:
        action:
    left_long:
      name: Left Long
      default: []
      selector:
        action:
    right_click:
      name: Right Single
      default: []
      selector:
        action:
    right_double:
      name: Right Double
      default: []
      selector:
        action:
    right_long:
      name: Right Long
      default: []
      selector:
        action:
    both_click:
      name: Both Single
      default: []
      selector:
        action:
    both_double:
      name: Both Double
      default: []
      selector:
        action:
    both_long:
      name: Both Long
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input remote
  attribute: action

condition: !input condition

action:
  - variables:
      command: "{{ trigger.to_state.state }}"
  - choose:
      - conditions: "{{ command == 'single_left' or command == 'left' }}"
        sequence: !input left_click

      - conditions: "{{ command == 'double_left' or command == 'left_double' }}"
        sequence: !input left_double

      - conditions: "{{ command == 'hold_left' or command == 'left_long' }}"
        sequence: !input left_long

      - conditions: "{{ command == 'single_right' or command == 'right' }}"
        sequence: !input right_click

      - conditions: "{{ command == 'double_right' or command == 'right_double' }}"
        sequence: !input right_double

      - conditions: "{{ command == 'hold_right' or command == 'right_long' }}"
        sequence: !input right_long

      - conditions: "{{ command == 'single_both' or command == 'both' }}"
        sequence: !input both_click

      - conditions: "{{ command == 'double_both' or command == 'both_double' }}"
        sequence: !input both_double

      - conditions: "{{ command == 'hold_both' or command == 'both_long' }}"
        sequence: !input both_long

1 Like

Hi - the names of the actions have been updated (as of 2022.4.6) - single_left, single_right, double_left, etc.

Hey, are you using the Zigbee2mqtt addon? the blueprint won’t work with or at least isn’t designed to work with the zha integration.

Yup, using Z2M. Running 1.25.1 I noticed the automation stopped functioning a few versions ago. Only now have i diagnosed the issue.

Wow has it been 2 weeks already,
It seems you are correct the z2m docs do show that it has changed. Xiaomi WXKG07LM control via MQTT | Zigbee2MQTT. But for whatever reason my switch is still using the old values, so that’s something I’ll have to look into, I should be able to just support both sets of actions.

Well I figured out what happened, the Zigbee2mqtt addon changed the repository they use, so I stopped receiving updates, additionally, after switching to the latest version I had to disable legacy mode in the device’s settings, but now I have the same actions you mentioned.

I’ve updated the blueprint to support both versions now :+1:.

Hi. I’m using this blueprint with WXKG02LM_rev2 and works perfectly.

I was using Aqara Buttons All-In-One [Zigbee2MQTT] but the automations were being run 3 times with every click…

Thanks!

1 Like

Hi!
As of ~today, when triggering a sequence with more than 1 action in an automation with this blueprint, it executes the first, and then it’s cancelled.

Example with 2 actions:


Note the 2nd actions is not executed, as it’s “Cancelled” and then there is an empty run right after.

.

The same happens when calling a script. It triggers the script but it cancels it after the first action with “null”. Note that the script runs perfectly when triggered from another button or directly via the UI/dashboard:


Also having of course a second empty run right after:

And the script traces for when using the D1 Double Rocker:

I’m very much confused. Already rebooted and as mentioned, the script works just fine.
Any ideas?

I made a copy of the pure automation (from Traces > Automation config), made the minimal adjustments to make it work standalone, and changed mode:restart to mode:single and seems to fix it.

I don’t know if the fact that the rocker action goes back to blank after a milisecond of the action restarts the automation thus stopping any running actions? But it didn’t happen before. Maybe a HA update changed how HA handles this…

1 Like

To get this to work, I changed mode to single, and removed the entire “attribute: action” line in the trigger section. With that line there the automation never triggered at all.

With those changes this blueprint works really well!