WXKG12LM - Aqara Wireless Mini Switch

I recently purchased Aqara Wireless Mini Switch [WXKG12LM].

When I add it to my homeassistant using Aqara Gateway Integration, it doesn’t give me the action types it is only showing On/Off and battery level change in automations. (as shown in the image below)

I tried looking for answers in the community and ran into this option of using blueprint. So I used the following blueprint Link

But when I go to automations and click on this print, it says no device found. Sharing a screenshot below:

Would be grateful if someone could kindly guide me in the right direction on how to get the missing entities/triggers for this mini switch.

Would appreciate if anyone who is using this model of Aqara Wireless Mini Switch could kindly share a fix. Thank you :slight_smile:

Hello, I’m working on a similar item and am currently drafting an blueprint to address a related issue. I to have this button hooked up through the Aqara gateway. I then have it published to HA through Matter.

The blueprint you are using is assuming you have it published to HA via ZHA. I am not sure that you can do that with the Aqara hub. This is what I feel is leading to the mismatch you show above.

I have gotten some data using the event monitor and have rigged up an automation by hand that fires.
The data from the Monitor:

event_type: state_changed
data:
  entity_id: event.steph_s_button
  old_state:
    entity_id: event.steph_s_button
    state: "2024-03-04T16:34:41.772+00:00"
    attributes:
      event_types:
        - initial_press
        - short_release
        - long_press
        - long_release
        - multi_press_ongoing
        - multi_press_complete
      event_type: initial_press
      newPosition: 1
      device_class: button
      friendly_name: Steph's Button
    last_changed: "2024-03-04T16:34:41.773034+00:00"
    last_updated: "2024-03-04T16:34:41.773034+00:00"
    context:
      id: 01HR552GZDH1GVJ6Y7RKDEXYQ9
      parent_id: null
      user_id: null
  new_state:
    entity_id: event.steph_s_button
    state: "2024-03-04T16:34:41.775+00:00"
    attributes:
      event_types:
        - initial_press
        - short_release
        - long_press
        - long_release
        - multi_press_ongoing
        - multi_press_complete
      event_type: short_release
      previousPosition: 1
      device_class: button
      friendly_name: Steph's Button
    last_changed: "2024-03-04T16:34:41.775231+00:00"
    last_updated: "2024-03-04T16:34:41.775231+00:00"
    context:
      id: 01HR552GZF9S9W4T8BQ4HS8Y1D
      parent_id: null
      user_id: null
origin: LOCAL
time_fired: "2024-03-04T16:34:41.775231+00:00"
context:
  id: 01HR552GZF9S9W4T8BQ4HS8Y1D
  parent_id: null
  user_id: null

I latched on the the event_type of multi_press_complete and the totalNumberOfPressesCounted to get responsed to both single and double presses. It isn’t pretty and is very much me stumbling around in the dark. Here is the automation:

- id: '1709081381187'
  alias: SButton
  description: ''
  trigger:
  - platform: state
    entity_id:
    - event.steph_s_button
    attribute: event_type
    to: multi_press_complete
  condition: []
  action:
  - choose:
    - conditions:
      - condition: numeric_state
        entity_id: event.steph_s_button
        attribute: totalNumberOfPressesCounted
        above: 0
        below: 2
      sequence:
      - service: switch.toggle
        metadata: {}
        data: {}
        target:
          entity_id: switch.readinglight
    - conditions:
      - condition: numeric_state
        entity_id: event.steph_s_button
        above: 1
        below: 3
        attribute: totalNumberOfPressesCounted
      sequence:
      - service: tts.speak
        metadata: {}
        data:
          cache: true
          media_player_entity_id: media_player.kitchen_group
          message: Two
        target:
          entity_id: tts.google_en_com

I am trying to shoehorn it into a blueprint that i’ll happily share for criticism and destruction hopefully soon.

1 Like

Thank you for the kind response.

I will try adding the button via ZHA and update you if my current blueprint works then.

Meanwhile will also be looking forward to your blueprint.

Here are things roughed in without any testing. I’m sure there are plenty of things to fix to make it work. I had hoped to at least rough out the structure and logic. Only accounts for completed sequences as it is based off the multi_press_complete state change.

First attempt sloggin thought this. Don’t laugh too loudly. Thank you!

blueprint:
  name: Matter - Aqara Wireless Mini Switch
  description: Automate your Aqara Wireless Mini Switch when run via Matter
  author: EFH52
  domain: automation
  input:
    target_switch:
      name: Aqara Wireless Mini Switch
      description: Target Aqara Wireless Mini Switch to monitor
      selector:
        entity:
          integration: matter
          model: Aqara Wireless Mini Switch
    short_release_action:
      name: Short Press Complete
      description: Action to take when Short Press is completed
      default: []
      selector:
        action: {}
    long_release_action:
      name: Long Press Complete
      description: Action to take when Long Press is completed
      default: []
      selector:
        action: {}
    two_release_action:
      name: Double Press Complete
      description: Action to take when Double Press is completed
      default: []
      selector:
        action: {}
    three_release_action:
      name: Triple Press Complete
      description: Action to take when Triple Press is completed
      default: []
      selector:
        action: {}
    four_release_action:
      name: Quadruple Press Complete
      description: Action to take when Quadruple Press is completed
      default: []
      selector:
        action: {}

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input target_switch

action:
  - variables:
      - command: "{{ trigger.to_state.attributes.event_type }}"
      - presses: "{{ trigger.to_state.attributes.totalNumberOfPressesCounted }}"
  - sequence:
      - condition: "{{ command == 'multi_press_complete' }}"
        sequence:
          - choose:
              - condition: "{{ presses == 1 }}"
                sequence:
                  - choose:
                      - condition: "{{ command == 'short_release' }}"
                        sequence: !input short_release_action
                      - condition: "{{ command == 'long_release' }}"
                        sequence: !input long_release_action
              - condition: "{{ presses == 2 }}"
                sequence: !input two_press
              - condition: "{{ presses == 3 }}"
                sequence: !input three_press
              - condition: "{{ presses == 4 }}"
                sequence: !input four_press

Hi there,

Not sure if it would be off topic but i have a quick question on your experience with Aqara mini switch.
Like you, I recently purchased it and linked it through matter.
When I click on the button, I get multiple events (2 to 3) and not just a single one.
Aqara app shows right amount of click.
I am trying to make an automation based on single/double click but this behavior prevents any correct interpretation of the action.

I found this old topic on GitHub about this behavior saying Aqara fixed it… but it seems not.

Are you experiencing the same issue?
Any idea if blueprint would solve issue?

Thanks :pray:t2:

That link was for the Aqara app having fixed things. I’ve gotten it to work for single and double by tracking the multipress event.

Use event type for the trigger.

Choose your entity, choose event type as the attribute, choose to multipresscomplete. Then set the upper and lower limits either side the number of presses you each to trigger. It is messy, but it works.

Many thanks for your advice!
I am trying the event type you suggested but it seems I cannot define upper/lower limits.


Is there a subsection I am missing?

The Upper/Lower limits you’re searching for can’t be found in the Trigger (When) section you’re showing.

You have to set them as Conditions (And if section) as per the post further up.

Sorry, I am not yet super fluent in YAML. :sweat_smile:
I followed steps and it works now ! Although I really do not understand how. :man_facepalming:t3:

Here is my final automation.


alias: Télécommande Victoria Rose
description: ""
trigger:
  - platform: state
    entity_id:
      - event.telecommande_victoria
    attribute: event_type
    to: multi_press_complete
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: event.telecommande_victoria
            attribute: totalNumberOfPressesCounted
            above: 0
            below: 2
        sequence:
          - service: light.turn_on
            metadata: {}
            data:
              rgb_color:
                - 255
                - 0
                - 255
              brightness_pct: 1
            target:
              device_id: 613053aaaf513ff719827a83e8d3c578
      - conditions:
          - condition: numeric_state
            entity_id: event.telecommande_victoria
            attribute: totalNumberOfPressesCounted
            above: 1
            below: 3
        sequence:
          - service: light.turn_on
            metadata: {}
            data:
              rgb_color:
                - 0
                - 0
                - 255
              brightness_pct: 1
            target:
              device_id: 613053aaaf513ff719827a83e8d3c578
mode: single

Here is where I landed. I have function (debugging still shows in this blueprint), but it stops at the double press. In the Aqara app, it only shows single, double, and long as options. So i’m guessing things changes in the firmware.

blueprint:
  name: Matter - Aqara Wireless Mini Switch
  description: Automate your Aqara Wireless Mini Switch when run via Matter (with long/short press differentiation)
  author: EFH52 (enhanced by AI)
  domain: automation
  input:
    target_switch:
      name: Aqara Wireless Mini Switch
      description: Target Aqara Wireless Mini Switch to monitor
      selector:
        entity:
          integration: matter
          domain: event
          device_class: button

    short_press_action:
      name: Short Press Action
      description: Action to take on a short press
      default: []
      selector:
        action: {}

    long_press_action:
      name: Long Press Action
      description: Action to take on a long press
      default: []
      selector:
        action: {}

    double_press_action:
      name: Double Press Action
      description: Action to take on a double press
      default: []
      selector:
        action: {}

    triple_press_action:
      name: Triple Press Action
      description: Action to take on a triple press
      default: []
      selector:
        action: {}

    quadruple_press_action:
      name: Quadruple Press Action
      description: Action to take on a quadruple press
      default: []
      selector:
        action: {}

mode: single
max_exceeded: silent

trigger:
  - platform: state
    entity_id: !input target_switch
    attribute: event_type

action:
  - service: persistent_notification.create
    data:
      title: "Aqara Mini Switch Debug"
      message: "Event triggered:  event_type={{ trigger.to_state.attributes.event_type }}"

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'short_release' }}"
        sequence: !input short_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'long_press' }}"
        sequence: !input long_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_complete' and trigger.to_state.attributes.totalNumberOfPressesCounted == 2 }}"
        sequence: !input double_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_complete' and trigger.to_state.attributes.totalNumberOfPressesCounted == 3 }}"
        sequence: !input triple_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_complete' and trigger.to_state.attributes.totalNumberOfPressesCounted == 4 }}"
        sequence: !input quadruple_press_action

Seems, i misread my model number. I have the WXKG11LM.

Am I just crazy or did the recent version of home assistant make it so that the “to” field only works if it’s different from the current state?

I was right, it seems to take any event as part of the attribute event_type as only changing when it’s anything other than the original button type you press. For example, if you single press the button, it won’t change until you do something like a double press, then a single press. I’ve changed the script to only remove the attribute and suddenly it’s working again. Not sure what it was about the version back from September that broke this, but I’m very happy to get this working again.

blueprint:
  name: Matter - Aqara Wireless Mini Switch
  description: Automate your Aqara Wireless Mini Switch when run via Matter (with long/short press differentiation)
  author: EFH52 (enhanced by AI)
  domain: automation
  input:
    target_switch:
      name: Aqara Wireless Mini Switch
      description: Target Aqara Wireless Mini Switch to monitor
      selector:
        entity:
          integration: matter
          domain: event
          device_class: button

    short_press_action:
      name: Short Press Action
      description: Action to take on a short press
      default: []
      selector:
        action: {}

    long_press_action:
      name: Long Press Action
      description: Action to take on a long press
      default: []
      selector:
        action: {}

    double_press_action:
      name: Double Press Action
      description: Action to take on a double press
      default: []
      selector:
        action: {}

    triple_press_action:
      name: Triple Press Action
      description: Action to take on a triple press
      default: []
      selector:
        action: {}

    quadruple_press_action:
      name: Quadruple Press Action
      description: Action to take on a quadruple press
      default: []
      selector:
        action: {}

mode: single
max_exceeded: silent

trigger:
  - platform: state
    entity_id: !input target_switch

action:
  - service: persistent_notification.create
    data:
      title: "Aqara Mini Switch Debug"
      message: "Event triggered:  event_type={{ trigger.to_state.attributes.event_type }}"

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_1' }}"
        sequence: !input short_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'long_press' }}"
        sequence: !input long_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_2' and trigger.to_state.attributes.totalNumberOfPressesCounted == 2 }}"
        sequence: !input double_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_2' and trigger.to_state.attributes.totalNumberOfPressesCounted == 3 }}"
        sequence: !input triple_press_action

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.attributes.event_type == 'multi_press_2' and trigger.to_state.attributes.totalNumberOfPressesCounted == 4 }}"
        sequence: !input quadruple_press_action

EDIT: I also realized that Aqara I think changed the events to something else. So, I also changed the names to properly reflect the button event names.

EDIT2: Here’s an easy button that’s stored on github:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Edit 3: I couldn’t get the triple and quadruples to work. So, I removed them in the import. I left them in this comment though since maybe someone else can figure out how to modify it for it to work.

You are legend! Works perfectly!

1 Like

Comments like these motivates people like me to try more of this thing. Happy to help!

You really came in clutch - I spent a stupid amount of time trying to work around events not working right - thanks!

Thanks for posting this! Makes making automations for these buttons a lot easier.
The only thing I’ve noticed is that whenever the matter integration reloads, it’s as if the buttons are all triggered, and as most of them are toggles, it just means my lights all change whenever homeassistant reboots or the matter integration is reloaded. Is that something you’ve run into as well, and if so, how did you resolve it?

Thanks!

Can’t say I have. I restart my system frequently and havent run into that issue.

Actually, now that you mention it, I notice it does trigger an event for some of my buttons. That is a bit weird. I wonder if that’s caused if the last press you had was a single press or not. I notice it specifically does this when the previous state is unknown. So adding a conditional should fix it. I’ll do that later today and see if that fixes it.