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

First of all: this is my first blueprint so if a made a mistake somewhere please let me know and I’ll do my best to correct it.

This blueprint adds support for the Aqara Wireless Switch created by Zigbee2MQTT. It’s inspired by @SeanM’s blueprint.

Supported actions are:

  • Single
  • Double
  • Triple
  • Quadruple

Note: There is quite a similar wireless switch out there which looks exactly like the one this blueprint can be used for but it has different button press actions (e.g. long press) which this blueprint doesn’t support.

Import the blueprint by using the forum topic URL!

Changelog

  • 2021-02-04: Adjust name of blueprint to differ from the similar switch with different types of button presses
  • 2021-01-07: Added mqtt as integration type for the sensor
  • 2020-12-22: Initial version
blueprint:
  name: Aqara Wireless Switch (single, double, triple, quadruple)
  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

    press_single:
      name: Single button press
      description: Action to run on single button press
      default: []
      selector:
        action: {}
    
    press_double:
      name: Double button press
      description: Action to run on double button press
      default: []
      selector:
        action: {}
    
    press_triple:
      name: Triple button press
      description: Action to run on double triple press
      default: []
      selector:
        action: {}
    
    press_quadruple:
      name: Quadruple button press
      description: Action to run on double quadruple press
      default: []
      selector:
        action: {}

mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input switch
  attribute: click

action:
  - variables:
      command: "{{ trigger.to_state.state }}"
      
  - choose:
      - conditions:
          - "{{ command == 'single' }}"
        sequence: !input press_single
      
      - conditions:
          - "{{ command == 'double' }}"
        sequence: !input press_double
      
      - conditions:
          - "{{ command == 'triple' }}"
        sequence: !input press_triple
      
      - conditions:
          - "{{ command == 'quadruple' }}"
        sequence: !input press_quadruple

A screenshot of the Blueprint:

4 Likes

@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…