Zigbee2MQTT - Aqara Opple switch 2 bands blueprint (WXCJKG12LM)

Blueprint to support Aqara Opple switch 2 bands (WXCJKG12LM).

Simple and clean Blueprint with all possible functions supported by this switch.
The buttons support:

  • Single press
  • Double press
  • Triple press
  • Hold
  • Release

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

blueprint:
  name: Z2M - Aqara Opple switch 2 bands
  description: 'Control anything you want with Aqara Opple switch 2 bands (WXCJKG12LM).


    Each band button has single, double, triple, hold & release'
  domain: automation
  input:
    switch:
      name: Aqara Opple switch
      description: Aqara Opple switch to use
      selector:
        entity:
          domain: sensor
          integration: mqtt
    button_1_single:
      name: Top Left button - single click
      description: Action to run on single click of top left button
      default: []
      selector:
        action: {}
    button_1_double:
      name: Top Left button - double click
      description: Action to run on double click of top left button
      default: []
      selector:
        action: {}
    button_1_triple:
      name: Top Left button - triple click
      description: Action to run on triple click of top left button
      default: []
      selector:
        action: {}
    button_1_hold:
      name: Top Left button - hold click
      description: Action to run on hold click of top left button
      default: []
      selector:
        action: {}
    button_1_release:
      name: Top Left button - release
      description: Action to run on release of top left button
      default: []
      selector:
        action: {}
    button_2_single:
      name: Top Right button - single click
      description: Action to run on single click of top right button
      default: []
      selector:
        action: {}
    button_2_double:
      name: Top Right button - double click
      description: Action to run on double click of top right button
      default: []
      selector:
        action: {}
    button_2_triple:
      name: Top Right button - triple click
      description: Action to run on triple click of top right button
      default: []
      selector:
        action: {}
    button_2_hold:
      name: Top Right button - hold click
      description: Action to run on hold click of top right button
      default: []
      selector:
        action: {}
    button_2_release:
      name: Top Right button - release
      description: Action to run on release of top right button
      default: []
      selector:
        action: {}
    button_3_single:
      name: Bottom Left button - single click
      description: Action to run on single click of bottom left button
      default: []
      selector:
        action: {}
    button_3_double:
      name: Bottom Left button - double click
      description: Action to run on double click of bottom left button
      default: []
      selector:
        action: {}
    button_3_triple:
      name: Bottom Left button - triple click
      description: Action to run on triple click of bottom left button
      default: []
      selector:
        action: {}
    button_3_hold:
      name: Bottom Left button - hold click
      description: Action to run on hold click of bottom left button
      default: []
      selector:
        action: {}
    button_3_release:
      name: Bottom Left button - release
      description: Action to run on release of bottom left button
      default: []
      selector:
        action: {}
    button_4_single:
      name: Bottom Right button - single click
      description: Action to run on single click of bottom right button
      default: []
      selector:
        action: {}
    button_4_double:
      name: Bottom Right button - double click
      description: Action to run on double click of bottom right button
      default: []
      selector:
        action: {}
    button_4_triple:
      name: Bottom Right button - triple click
      description: Action to run on triple click of bottom right button
      default: []
      selector:
        action: {}
    button_4_hold:
      name: Bottom Right button - hold click
      description: Action to run on hold click of bottom right button
      default: []
      selector:
        action: {}
    button_4_release:
      name: Bottom Right button - release
      description: Action to run on release of bottom right button
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/zigbee2mqtt-aqara-opple-switch-2-bands-blueprint-wxcjkg12lm/353884
mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input 'switch'
  attribute: action
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- choose:
  - conditions:
    - '{{ command == ''button_1_single'' }}'
    sequence: !input 'button_1_single'
  - conditions:
    - '{{ command == ''button_2_single'' }}'
    sequence: !input 'button_2_single'
  - conditions:
    - '{{ command == ''button_3_single'' }}'
    sequence: !input 'button_3_single'    
  - conditions:
    - '{{ command == ''button_4_single'' }}'
    sequence: !input 'button_4_single'
  - conditions:
    - '{{ command == ''button_1_double'' }}'
    sequence: !input 'button_1_double'    
  - conditions:
    - '{{ command == ''button_2_double'' }}'
    sequence: !input 'button_2_double'
  - conditions:
    - '{{ command == ''button_3_double'' }}'
    sequence: !input 'button_3_double'
  - conditions:
    - '{{ command == ''button_4_double'' }}'
    sequence: !input 'button_4_double'
  - conditions:
    - '{{ command == ''button_1_triple'' }}'
    sequence: !input 'button_1_triple'
  - conditions:
    - '{{ command == ''button_2_triple'' }}'
    sequence: !input 'button_2_triple'
  - conditions:
    - '{{ command == ''button_3_triple'' }}'
    sequence: !input 'button_3_triple'
  - conditions:
    - '{{ command == ''button_4_triple'' }}'
    sequence: !input 'button_4_triple'
  - conditions:
    - '{{ command == ''button_1_hold'' }}'
    sequence: !input 'button_1_hold'
  - conditions:
    - '{{ command == ''button_2_hold'' }}'
    sequence: !input 'button_2_hold'
  - conditions:
    - '{{ command == ''button_3_hold'' }}'
    sequence: !input 'button_3_hold'
  - conditions:
    - '{{ command == ''button_4_hold'' }}'
    sequence: !input 'button_4_hold'
  - conditions:
    - '{{ command == ''button_1_release'' }}'
    sequence: !input 'button_1_release'
  - conditions:
    - '{{ command == ''button_2_release'' }}'
    sequence: !input 'button_2_release'
  - conditions:
    - '{{ command == ''button_3_release'' }}'
    sequence: !input 'button_3_release'
  - conditions:
    - '{{ command == ''button_4_release'' }}'
    sequence: !input 'button_4_release'
2 Likes

This is the first blueprint I use, and although it seem to have imported correct, I can’t get the automation I created to work.

I’m pressing buttons on my switch but nothing happens. in fact, the automation says it has never run.

For entity, I select sensor.button_action … is that correct? (it’s the only option I have)

Hi Daniel-san.
Yes, that’s correct, you should choose sensor.button_action as entity and all should work for you.
I have this blueprint running for myself and no issues since set this up 1 year ago.
Please check once again if everything in automation is correct. Or post screenshot here to see your setup.

Thank you
Den

I have the same problem. in the middle of moving from deconz to Z2M. If i create an own automation, listening to the buttons actions, it works, but using the blueprint, it is never triggered

Could you please provide your automation log/settings?

Due to my new account I am not able to provide more pictures in description with examples or settings I found working for me.

In my case the blueprint stopped working too. It seems like an update broke it at some point, not sure when.

It appears broken since the trigger payload may be different than what the blueprint expects; The action is missing, and so it won’t trigger. Assuming we remove the attribute from the trigger, I still don’t know how to retrieve the command from trigger.state.to_state or how to update the trigger so it uses trigger.state.from_state == ''

Here’s a sample trigger from a state change using z2m:

trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: state
  entity_id: sensor.button1
  from_state:
    entity_id: sensor.button1
    state: button_2_double
    attributes:
      icon: mdi:gesture-double-tap
      friendly_name: some friendly name
    last_changed: '2023-03-05T04:48:42.189673+00:00'
    last_updated: '2023-03-05T04:48:42.189673+00:00'
    context:
      id: id
      parent_id: null
      user_id: null
  to_state:
    entity_id: sensor.button1
    state: ''
    attributes:
      icon: mdi:gesture-double-tap
      friendly_name: some friendly name
    last_changed: '2023-03-05T04:48:42.192843+00:00'
    last_updated: '2023-03-05T04:48:42.192843+00:00'
    context:
      id: id
      parent_id: null
      user_id: null
1 Like

Hi @ufierro

that’s weird. as I am using same integration I have wrote for everyone and all is ok.
Could you please try to remove my blueprint and try to reinstall it again? Maybe with newer version of Home Assistant something gone wrong in the code…
Please let me know.

Thank you

It wasnt working for me too. Spent lot of time, lookig at other blueprints (i have 0 expiriance with HASS blueprints and syntax). and now it works:
Would be great if author fix his version and update it, so everybody could use it.

blueprint:
  name: Z2M - Aqara Opple switch 2 bands
  description: 'Control anything you want with Aqara Opple switch 2 bands (WXCJKG12LM).


    Each band button has single, double, triple, hold & release'
  domain: automation
  input:
    switch:
      name: Aqara Opple switch
      description: Aqara Opple switch to use
      selector:
        entity:
          domain:
          - sensor
          integration: mqtt
          multiple: false
    button_1_single:
      name: Top Left button - single click
      description: Action to run on single click of top left button
      default: []
      selector:
        action: {}
    button_1_double:
      name: Top Left button - double click
      description: Action to run on double click of top left button
      default: []
      selector:
        action: {}
    button_1_triple:
      name: Top Left button - triple click
      description: Action to run on triple click of top left button
      default: []
      selector:
        action: {}
    button_1_hold:
      name: Top Left button - hold click
      description: Action to run on hold click of top left button
      default: []
      selector:
        action: {}
    button_1_release:
      name: Top Left button - release
      description: Action to run on release of top left button
      default: []
      selector:
        action: {}
    button_2_single:
      name: Top Right button - single click
      description: Action to run on single click of top right button
      default: []
      selector:
        action: {}
    button_2_double:
      name: Top Right button - double click
      description: Action to run on double click of top right button
      default: []
      selector:
        action: {}
    button_2_triple:
      name: Top Right button - triple click
      description: Action to run on triple click of top right button
      default: []
      selector:
        action: {}
    button_2_hold:
      name: Top Right button - hold click
      description: Action to run on hold click of top right button
      default: []
      selector:
        action: {}
    button_2_release:
      name: Top Right button - release
      description: Action to run on release of top right button
      default: []
      selector:
        action: {}
    button_3_single:
      name: Bottom Left button - single click
      description: Action to run on single click of bottom left button
      default: []
      selector:
        action: {}
    button_3_double:
      name: Bottom Left button - double click
      description: Action to run on double click of bottom left button
      default: []
      selector:
        action: {}
    button_3_triple:
      name: Bottom Left button - triple click
      description: Action to run on triple click of bottom left button
      default: []
      selector:
        action: {}
    button_3_hold:
      name: Bottom Left button - hold click
      description: Action to run on hold click of bottom left button
      default: []
      selector:
        action: {}
    button_3_release:
      name: Bottom Left button - release
      description: Action to run on release of bottom left button
      default: []
      selector:
        action: {}
    button_4_single:
      name: Bottom Right button - single click
      description: Action to run on single click of bottom right button
      default: []
      selector:
        action: {}
    button_4_double:
      name: Bottom Right button - double click
      description: Action to run on double click of bottom right button
      default: []
      selector:
        action: {}
    button_4_triple:
      name: Bottom Right button - triple click
      description: Action to run on triple click of bottom right button
      default: []
      selector:
        action: {}
    button_4_hold:
      name: Bottom Right button - hold click
      description: Action to run on hold click of bottom right button
      default: []
      selector:
        action: {}
    button_4_release:
      name: Bottom Right button - release
      description: Action to run on release of bottom right button
      default: []
      selector:
        action: {}
mode: queued

trigger:
  - platform: state
    entity_id: !input switch

condition:
  - "{{ trigger.to_state.state != '' }}"

action:
  - variables:
      command: "{{ trigger.to_state.state }}"
  - choose:
    - conditions:
      - '{{ command == "button_1_single" }}'
      sequence: !input button_1_single
    - conditions:
      - '{{ command == ''button_2_single'' }}'
      sequence: !input button_2_single
    - conditions:
      - '{{ command == ''button_3_single'' }}'
      sequence: !input button_3_single
    - conditions:
      - '{{ command == ''button_4_single'' }}'
      sequence: !input button_4_single
    - conditions:
      - '{{ command == ''button_1_double'' }}'
      sequence: !input button_1_double
    - conditions:
      - '{{ command == ''button_2_double'' }}'
      sequence: !input button_2_double
    - conditions:
      - '{{ command == ''button_3_double'' }}'
      sequence: !input button_3_double
    - conditions:
      - '{{ command == ''button_4_double'' }}'
      sequence: !input button_4_double
    - conditions:
      - '{{ command == ''button_1_triple'' }}'
      sequence: !input button_1_triple
    - conditions:
      - '{{ command == ''button_2_triple'' }}'
      sequence: !input button_2_triple
    - conditions:
      - '{{ command == ''button_3_triple'' }}'
      sequence: !input button_3_triple
    - conditions:
      - '{{ command == ''button_4_triple'' }}'
      sequence: !input button_4_triple
    - conditions:
      - '{{ command == ''button_1_hold'' }}'
      sequence: !input button_1_hold
    - conditions:
      - '{{ command == ''button_2_hold'' }}'
      sequence: !input button_2_hold
    - conditions:
      - '{{ command == ''button_3_hold'' }}'
      sequence: !input button_3_hold
    - conditions:
      - '{{ command == ''button_4_hold'' }}'
      sequence: !input button_4_hold
    - conditions:
      - '{{ command == ''button_1_release'' }}'
      sequence: !input button_1_release
    - conditions:
      - '{{ command == ''button_2_release'' }}'
      sequence: !input button_2_release
    - conditions:
      - '{{ command == ''button_3_release'' }}'
      sequence: !input button_3_release
    - conditions:
      - '{{ command == ''button_4_release'' }}'
      sequence: !input button_4_release

Couldn’t get this working at first. Debugging through zigbee2mqtt and the automation traces showed me the problem: each button press was causing two events, the first with the correct action value (e.g. “button_1_single”) immediately followed by an event with an empty action value.
Because the blueprint sets the automation mode to “restart” the action to turn the lights-on action gets cancelled by the “empty” event before it is carried out.
I changed the mode to “queued” in the template (at line 138) and restarted, and now it appears to work for me…