[Z2M] Aqara Opple 4 boutons blueprint (WXCJKG12LM)

Hello everyone,

I’m sharing my blueprint on Aqara Opple 4 boutons (WXCJKG12LM) for zigbee2mqtt.

Inspired from @razvanmdobre blueprint for the 6 boutton version.

This blueprint has no default values compared to his.

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

    Inspired by the blueprint of @razvanmdobre (https://community.home-assistant.io/t/zigbee2mqtt-aqara-opple-switch-3-bands/256212)

    Each band button has single, double, triple, hold & release"
  domain: automation
  input:
    switch:
      name: Aqara switch
      description: Aqara switch to use
      selector:
        entity:
          domain: sensor
          integration: mqtt
    button_1_single:
      name: Button 1 - simple click
      description: Action to run on triple click of button 1
      default: []
      selector:
        action: null
    button_1_double:
      name: Button 1 - double click
      description: Action to run on triple click of button 1
      default: []
      selector:
        action: null
    button_1_triple:
      name: Button 1 - triple click
      description: Action to run on triple click of button 1
      default: []
      selector:
        action: null
    button_1_hold:
      name: Button 1 - hold click
      description: Action to run on triple click of button 1
      default: []
      selector:
        action: null
    button_1_release:
      name: Button 1 - on release
      description: Action to run after hold then release
      default: []
      selector:
        action: null
    button_2_single:
      name: Button 2 - single click
      description: Action to run on triple click of button 2
      default: []
      selector:
        action: null
    button_2_double:
      name: Button 2 - double click
      description: Action to run on triple click of button 2
      default: []
      selector:
        action: null
    button_2_triple:
      name: Button 2 - triple click
      description: Action to run on triple click of button 2
      default: []
      selector:
        action: null
    button_2_hold:
      name: Button 2 - hold click
      description: Action to run on triple click of button 2
      default: []
      selector:
        action: null
    button_2_release:
      name: Button 2 - on release
      description: Action to run after hold then release
      default: []
      selector:
        action: null
    button_3_single:
      name: Button 3 - simple click
      description: Action to run on triple click of button 3
      default: []
      selector:
        action: null
    button_3_double:
      name: Button 3 - double click
      description: Action to run on triple click of button 3
      default: []
      selector:
        action: null
    button_3_triple:
      name: Button 3 - triple click
      description: Action to run on triple click of button 3
      default: []
      selector:
        action: null
    button_3_hold:
      name: Button 3 - hold click
      description: Action to run on triple click of button 3
      default: []
      selector:
        action: null
    button_3_release:
      name: Button 3 - on release
      description: Action to run after hold then release
      default: []
      selector:
        action: null
    button_4_single:
      name: Button 4 - single click
      description: Action to run on triple click of button 4
      default: []
      selector:
        action: null
    button_4_double:
      name: Button 4 - double click
      description: Action to run on triple click of button 4
      default: []
      selector:
        action: null
    button_4_triple:
      name: Button 4 - triple click
      description: Action to run on triple click of button 4
      default: []
      selector:
        action: null
    button_4_hold:
      name: Button 4 - hold click
      description: Action to run on triple click of button 4
      default: []
      selector:
        action: null
    button_4_release:
      name: Button 4 - on release
      description: Action to run after hold then release
      default: []
      selector:
        action: null
  source_url: https://community.home-assistant.io/t/z2m-aqara-opple-4-boutons-blueprint-wxcjkg12lm/279950
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"

Changelog:

  • Feb 7. 2022: Added Release action to all switches

Don’t hesitate to let me know if there are issues. I’ll try to solve them as soon as possible.
Have a great time & stay safe
Chris

Could you please also add the bits for release of a button hold? I think those are button_1_release, button_2_release, etc. Thanks!!

Hi @baru .

I’m sorry, I’m in the middle of moving from one region of France to another. All of Home Assistant is right now in a cardboard box in storage waiting for me to find a new house. I wont be able to do this for a while.

Don’t hesitate to take this template and improve it on your own as I can’t maintain it for now.

Cheers

Is there someone that can help me? I’m trying to use Opple with a Sonoff 4ch Pro tasmotized and used on HA as a Cover. I’d like to make the following:

When I press button 1 → I’d open the cover (therefore call the service cover.open)
When I press again button 1 → I’d stop the cover (therefore call the service cover.stop)

Do you have any idea on how to do that? Shall I modify the blueprint or create a specific automation?

Thanks

Anyone have this working in ZHA?

Would cover.toggle suit your use case?

1 Like

Aqara Opple 6 Buttons For Zha Looks like what you’re after

@baru ,

I’m finally back on HA ! Took a s*** ton of time sorry. I’ve added what you needed.

Haven’t had a chance to test it unfortunately

Hi all, and thank you for sharing.
I’ve a blueprint that is written in the same way but it has been developed for xiaomi clicker that works almost same way but with just one button.
I cannot manage the automation to work because of this:
Error: UndefinedError: ‘dict object’ has no attribute ‘to_state’
I tried also to change the variable definition in many ways solving the error, but the variable “command” seems to be always empty. Could you please advise?

I could well be doing something wrong but it seems like the state change isn’t triggering the automation for me. I’m using Zigbee2MQTT and HA running as docker containers.
I can see the following state change received:

"event_type": "state_changed",
...
        "new_state": {
            "entity_id": "sensor.0x54ef44100042b717_action",
            "state": "button_2_single",
...

However the automation for “button_2_single” doesn’t run.
Is anyone else seeing issues like this?

Hi @hypnosis ,

Sorry I didn’t get back to you earlier. It’s hard to say with the information at hand.

I would advise you to open a thread (not in the Blueprints exchange though, to have better visibility by everyone), with all details about the integration and what you do exactly for testing.

Otherwise it will be hard to help you out.
Chris

Might very well be me mate ! :slight_smile:

I have installed one though some weeks ago at home and it’s working great.

I confirm this is the same kind of event I receive. As details this is what happens on my side:

Event 53 fired 9:37 AM:
{
    "event_type": "state_changed",
    "data": {
        "entity_id": "sensor.kitchen_remote_action",
        "old_state": {
            "entity_id": "sensor.kitchen_remote_action",
            "state": "button_2_single",
            "attributes": {
                "action": "",
                "battery": 100,
                "linkquality": 96,
                "operation_mode": null,
                "temperature": 25,
                "voltage": 3059,
                "icon": "mdi:gesture-double-tap",
                "friendly_name": "Kitchen Remote action"
            },
            "last_changed": "2022-04-28T07:37:03.316789+00:00",
            "last_updated": "2022-04-28T07:37:03.332157+00:00",
            "context": {
                "id": "dcfa88aac6349889fc4b96928b1823c5",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "sensor.kitchen_remote_action",
            "state": "",
            "attributes": {
                "action": "",
                "battery": 100,
                "linkquality": 96,
                "operation_mode": null,
                "temperature": 25,
                "voltage": 3059,
                "icon": "mdi:gesture-double-tap",
                "friendly_name": "Kitchen Remote action"
            }...

This is then followed automatically by:

Event 54 fired 9:37 AM:
{
    "event_type": "automation_triggered",
    "data": {
        "name": "Kitchen Remote",
        "entity_id": "automation.z2m_aqara_opple_switch_2_bands",
        "source": "state of sensor.kitchen_remote_action"
    },
    "origin": "LOCAL",
    "time_fired": "2022-04-28T07:37:03.352382+00:00",
    "context": {
        "id": "5492a98e9f94642fa06d38eaad92c6ab",
        "parent_id": "dcfa88aac6349889fc4b96928b1823c5",
        "user_id": null
    }
}

Maybe you can send me the details of your automation configuration?
Thanks
Chris

Wow, thanks, I didn’t expect such quick responses!

In working on the issue, I stumbled upon the following thread which mentions that the problem is likely that the state "button_1_single” is being set and then immediately being set back to an empty string.

This correlates with the events that I’m seeing when debugging.
To workaround it, I implemented code similar to the last post in that thread, making a separate automation for each button press.

I had never noticed that but yes you are right ! Fortunately for me it doesn’t seem to bother my automation. It sill triggers all right every time I press the button. And it makes sense because what triggers the rule, is the state_change. So whether it goes back to NULL shouldn’t impact the automation execution…

Are you running the blueprint as the automation directly? Or something else?

Cheers

That is what I thought initially too.
Yes, I created an automation directly from the blueprint.
Are you running Z2M and HA dockerized? I’m wondering whether that makes any difference.

One other thing to note (and I’m not sure if it matters or not) is that my Z2M configuration.yaml file has “homeassistant_legacy_entity_attributes” disabled.

Unfortunately I’m only relatively new to HA so my debugging abilities there are fairly limited.

Cheers,
Brent

Hey @brash,

Not anymore. Right now am running HA OS on an Intel Nuc.

I was looking at your setting that I didn’t know and I stumbled on another setting called legacy_triggers. The documentation says:

  # Optional: Home Assistant legacy triggers (default: shown below), when enabled:
  # - Zigbee2mqt will send an empty 'action' or 'click' after one has been send
  # - A 'sensor_action' and 'sensor_click' will be discoverd
legacy_triggers: true

Maybe you can set that option to false (default is ON). That would prevent the empty value from being sent?

I checked my settings and indeed… it’s enabled. Careful that changing this setting requires an HA restart

Here is the link to the doc

See you!

Interesting…
I come across with exactly same problem: Z2M, the blueprint and WXCJKG12LM… and HA on docker (moving slowly from Hassos)

Somehow this one particular blueprint don’t want to work.

So I made simple automation test:

alias: test1b
description: ''
trigger:
  - platform: state
    entity_id:
      - sensor.aqara4button_action
    to: button_1_single
condition: []
action:
  - service: switch.toggle
    data: {}
    target:
      device_id: d875be96231967c96acaac5930395d10
mode: single

and this works perfectly well.

I wonder what is the difference between the blueprint and this simple auto?
I love the blueprint, simplifies configuration a lot.

Hey @marekorok ,

That’s interesting !

To be fair i’ve no idea what the difference between the two are…

I just opened the blueprint and everything looks allright :frowning:

Something just caught my interest though, can you check your Z2M logs and press on one of the remotes buttons?

Mine shows this:

Info <small>2022-05-10 22:03:28</small>`MQTT publish: topic 'zigbee2mqtt/Kitchen Remote', payload '{"action":"","battery":100,"linkquality":96,"operation_mode":null,"temperature":25,"voltage":3075}'`

Info <small>2022-05-10 22:03:28</small>`MQTT publish: topic 'zigbee2mqtt/Kitchen Remote/action', payload 'button_4_single'`

What is bothering me is the “operation_mode” of the remote as null. Are you seing something else yourselves?

@Brash did you get any luck on this?

I might need to rework this blueprint all together, but since it is working at home, I don’t really have the will power to do so :rofl:

yes, I see the same operation_mode: null

If I get it right, it is used when you want to change binding and control directly something (like bulb) not using coordinator, from z2m doc:
https://www.zigbee2mqtt.io/devices/WXCJKG13LM.html#binding
by default it works in event mode.

I have even forced ‘event’ setting following the documentation but no change for blueprint, still does not work.

Info <small>2022-05-11 10:38:42</small>`MQTT publish: topic 'zigbee2mqtt/Aqara4Button', payload '{"action":"button_1_single","battery":100,"linkquality":174,"operation_mode":"event","voltage":3037}'`
Info <small>2022-05-11 10:38:42</small>`MQTT publish: topic 'zigbee2mqtt/Aqara4Button', payload '{"action":"","battery":100,"linkquality":174,"operation_mode":"event","voltage":3037}'`
Info <small>2022-05-11 10:38:42</small>`MQTT publish: topic 'zigbee2mqtt/Aqara4Button/action', payload 'button_1_single'`

I guess it’s irrelevant in our case

I agree, not relevant in this situation.

Can you check your automation using the blueprint traces to see if the event of pressing the button is actually even recorded there and why the action is not being triggered?