Zigbee2MQTT - Aqara Wireless Switch (single, double, triple, quadruple)

@Malte nice first blueprint!

Seems to work flawlessly with my buttons. The only improvement I could come up with for now is that adding the line integration: mqtt under entity for the input device will limit the number of selectable sensors.

The first section would then look like:

blueprint:
  name: Aqara Wireless Switch
  description: 'Control anything using Aqara Wireless Switch'
  domain: automation
  input:
    switch:
      name: Switch
      description: Action sensor of Aqara Wireless Switch to use
      selector:
        entity:
          domain: sensor
          integration: mqtt
1 Like

@sharki Thanks for the feedback and the idea. I implemented it right away.

hi, i am getting the following error on the editor

unknown tag !<!input> at line 60, column 27:
      entity_id: !input switch
                              ^

i made no changes

Can you please check if really no change has been made to the file? I just compared the different versions of the code and other than the changes I wanted to make no differences are present.

To be honest with you I very recently made the switch from Zigbee2MQTT to the native ZHA integration so I cannot fully verify functionality. But since I switched I just changed this line:

name: Aqara Wireless Switch (single, double, triple, quadruple)

Maybe someone else can verify that it still works.

Do you know how to add a wait_template/timeout for the long click (hold action) to allow longer/2 seconds press and hold the button?

Could you describe again a little more precisely what you want to do? This blueprint is designed to match the return commands of the entity created by Zigbee2MQTT

I’m was looking how to make the long-press be executed after holding a button for 5 seconds.

As I don’t own a switch that sends the long-pressed command I can’t help you on this one either. But are you sure that it does send that command to Zigbee2MQTT? Or do you want me to integrate another command from a button into this blueprint?

Yes, i’m sure. it sends the “release” command when the button was released and then you can build an automation on duration the button was hold. for example hold 3 seconds = turn off single light, hold 5 seconds = turn off all light.
I solved it like this:

....
....
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.attributes.action == ''hold'' }}'
      sequence:
      - delay:
          seconds: 3
      - wait_for_trigger:
        - platform: device
          domain: mqtt
          device_id: xxxxxx
          type: action
          subtype: release
        - platform: device
          domain: mqtt
          type: click
          subtype: long_release
        timeout: '5'
        continue_on_timeout: false

Hi

sorry I’m a newbie in HA. I’ve set my HA on a raspberry soon, with zigbee2mqtt. It works fine.
I’ve just bought an aqara switch [WRS-R02] Xiaomi WRS-R02 control via MQTT | Zigbee2MQTT with 2 buttons. It’s supposed to have single, double, long press … actions but when I try to add an automatisation, the only actions I have are : button1_single/triple, button2_single, toggle1.
Does this blueprint can help me? I’ve searched in this forum and zigbee2mqtt but I didn’t found anything good.

thank you very much !

Hi @bertrand, glad to have you on board with HA :slight_smile:
I’m sorry, but this blueprint won’t do for you. I designed it specifically for the button above. You’ll probably have to write your own blueprint. After a quick search, I found this blueprint, which is only for ZHA, but could serve as an example for a Xiaomi switch with two buttons. Combine it with this blueprint and it should quite easily do the trick.

thanks @Malte I will check that!

This still working?

Executed: 27 November 2021, 20:00:08
Error: UndefinedError: 'dict object' has no attribute 'to_state'

Automation config

mode: restart
max_exceeded: silent
trigger:
  - platform: state
    entity_id: sensor.0x00158d0005724b64_action
    attribute: click
action:
  - variables:
      command: '{{ trigger.to_state.state }}'
  - choose:
      - conditions:
          - '{{ command == ''single'' }}'
        sequence:
          - type: turn_on
            device_id: 5f35bb0207544d35d7fb7bd650cae958
            entity_id: light.0x804b50fffece18ed
            domain: light
      - conditions:
          - '{{ command == ''double'' }}'
        sequence:
          - type: turn_off
            device_id: 5f35bb0207544d35d7fb7bd650cae958
            entity_id: light.0x804b50fffece18ed
            domain: light
      - conditions:
          - '{{ command == ''triple'' }}'
        sequence: []
      - conditions:
          - '{{ command == ''quadruple'' }}'
        sequence: []
id: '1638039571004'
alias: Aqara Wireless Switch (single, double, triple, quadruple)
description: ''

Blueprint config

id: '1638039571004'
alias: Aqara Wireless Switch (single, double, triple, quadruple)
description: ''
use_blueprint:
  path: Malte/zigbee2mqtt-aqara-wireless-switch-single-double-triple-quadruple.yaml
  input:
    switch: sensor.0x00158d0005724b64_action
    press_single:
      - type: turn_on
        device_id: 5f35bb0207544d35d7fb7bd650cae958
        entity_id: light.0x804b50fffece18ed
        domain: light
    press_double:
      - type: turn_off
        device_id: 5f35bb0207544d35d7fb7bd650cae958
        entity_id: light.0x804b50fffece18ed
        domain: light

Sorry for the late answer. I sadly cannot help you with the blueprint, as I changed my setup. I know that it used to work but don’t know if they changed something fundamental about blueprints…

I came across this while migrating from ZHA to Zigbee2MQTT and debugged the issue for why it wasn’t working. You can remove the “attribute: click” line in the trigger as the single/double/etc action is stored in the main state. With that change, it should work.

I will change it, but can’t check it myself in hopes that others who want to use it can.

I hope that someone can help : I am trying to use the blueprint to control a number of lights/group of lights together

“single” action → light.turn_on for all of the individual lights devices or the group entity

“double” action → light.turn_off for all of the individual lights devices or the group entity

Everythig works well with this blueprint as long as there is only one device to control.

As soon as there is a group of lights or multiple individual lights devices (even calling up a scene or a separate automation that control >1 light) it no longer works well ?

Am I the only one in this situation ?

I have checked that the action reports correctly in mqtt_explorer and in the log.

When manually running the light.turn_on from a group of lights everything works well but if that same action on a group of light follows the wirelss switch action trigger it no longer works ???

Am I really the only one in this same situation ?
Have others tried to control more than one device using the blueprint action trigger ?

Hi,
I discovered nearly the same problem and changed the mode in the blueprint YAML to:
mode: queued

After that it worked fine for me.

@Sommer

I can’t thank you enough !
This has been driving me mad for some time :wink:

Exactly as you indicated: the addition of the line mode: queued fixed the problem.

Much appreciated !

alias: Livingroom Lights group using WXKG12LM Wireless Switch
description: ""
mode: queued
use_blueprint:

@Sommer @IamMattM I officially changed the mode reflecting the feedback you gave. I switched to ZHA so I cannot verify the change but maybe you can give me a feedback. Thanks in advance!