Xiaomi Button No longer registers single or double press!

@syssi So since update to 0.84.0b4 (and also the stable release 0.84.1) the buttons seem to be broken again. So no last_action updates and no automation triggers

I can see the action working on the gateway, but not in HA.
Tested devices:

  • Button 1st generation
  • Button 2nd generation
  • Aqara Wireless Switch (Single)
  • Aqara Wireless Switch (Double)

All those are not working anymore.

Here is one of my automations:

- id: lighting_all_switch
  alias: '[Licht] Alle Schalter'
  trigger:
  - event_data:
      click_type: both
      entity_id: binary_sensor.wall_switch_both
    event_type: xiaomi_aqara.click
    platform: event
  - event_data:
      click_type: single
      entity_id: binary_sensor.wall_switch
    event_type: xiaomi_aqara.click
    platform: event
  - event_data:
      click_type: single
      entity_id: binary_sensor.switch
    event_type: xiaomi_aqara.click
    platform: event
  - event_data:
      click_type: single
      entity_id: binary_sensor.switch_2
    event_type: xiaomi_aqara.click
    platform: event
  action:
  - data:
      entity_id: group.licht
    service: light.toggle

Here are the buttons in the dev-state page:

My system:

  • HassOS 1.13
  • Hass.io supervisor 141
  • HA 0.84.1
  • Raspberry Pi 3 Model B+

If you need more information or anything I can test, please let me know.

Edit:

In the logs I see this:


But all other aqara sensors are working (door, temperature, motion etc.)

I also tried to reset the gateway and re-add it, but still the same issue

Edit 2:

The only way I get the last_action not display anything different then null is to hammer on the switches. Then the gateway says something like “positive connection” (in chinese) and the last_action changes to single. But the automation is still not triggered


For the round aqara button the hold seems to work (and also the long_click_press which is triggered during the hold)

My fix isnt’ part of 0.84(.1). You’ve to wait for 0.85. It’s not broken again. It’s still broken. :wink: Trust me the issue will be solved soon.

1 Like

soon as in 9th january

1 Like

Yes the next release will be on 09.01

Do you have any idea, how I can edit the file myself on hassio? Or fix it myself in any way?

Edit:
Adding the content of the xiaomi_aqara.py file with your fix to /config/custom_components/binary_sensor/xiaomi_aqara.py should work, right?

Edit2:
I can confirm, that now the right last_action is displayed in the dev-state page, but still it does not trigger any automation


Edit3:
So I recreated all my automations and now they seem to work again :slight_smile:

Thanks for the help!

The fix is part of 0.84.2 now!

1 Like

I’ve just updated to 84.2 and my switches now work
 thank you :wink:

hmm. mine now shows the clicks as registered after upgrading to 84.2, but automation still doesn’t run.
84.0 and 84.1 doesn’t even show any clicks being registered at all.
I revered to 82.1 and it is all working now


So seems like my fix is not there yet, waiting for next year. No biggie.

Merry Christmas and Happy New Year to all !

The same situation here, issue not fixed yet in 0.84.2. In version 82.1 my Xiao mi WXKG02LM AQARA Smart switch still works fine.

In 0.84.2 the sensors below are registered and visible on the dev-stat page in the GUI, but their state remain off no matter I push one or both buttons.

binary_sensor.wall_switch_left_158d00xxxxxxxx
binary_sensor.wall_switch_right_158d00xxxxxxxx
binary_sensor.wall_switch_both_158d00xxxxxxxx

My other Xiaomi sensors (like below) work just fine in 0.83.x and 0.84.x:

binary_sensor.motion_sensor_158d000xxxxxxxx
sensor.temperature_158d000xxxxxxxx
sensor.pressure_158d000xxxxxxxx
sensor.humidity_158d000xxxxxxxx

Edit:

Down here my xiaomi debug logging.

dec 17 07:08:44 nuc.bachstraat20 docker[12783]: 2018-12-17 07:08:44 DEBUG (SyncWorker_12) [homeassistant.components.xiaomi_aqara] Expecting 1 gateways
dec 17 07:08:44 nuc.bachstraat20 docker[12783]: 2018-12-17 07:08:44 INFO (SyncWorker_12) [homeassistant.components.xiaomi_aqara] Discovering Xiaomi Gateways (Try 1)
dec 17 07:08:50 nuc.bachstraat20 docker[12783]: 2018-12-17 07:08:50 DEBUG (SyncWorker_12) [homeassistant.components.xiaomi_aqara] Gateways discovered. Listening for broadcasts
dec 17 07:09:14 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:14 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d000xxxxxxx: 18.4>: {'voltage': 2975, 'temperature': '1839', 'humidity': '5412', 'pressure': '100955'}
dec 17 07:09:14 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:14 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 54.1>: {'voltage': 2975, 'temperature': '1839', 'humidity': '5412', 'pressure': '100955'}
dec 17 07:09:14 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:14 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Pressure_158d000xxxxxxx: 1009.5>: {'voltage': 2975, 'temperature': '1839', 'humidity': '5412', 'pressure': '100955'}
dec 17 07:09:21 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:21 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Plug_158d000xxxxxxx: on>: {'voltage': 3600, 'status': 'on', 'inuse': '1', 'power_consumed': '1484', 'load_power': '1.66'}
dec 17 07:09:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d000xxxxxxx: off>: {'lux': '4'}
dec 17 07:09:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_158d000xxxxxxx: 4.0>: {'lux': '4'}
dec 17 07:09:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d000xxxxxxx: off>: {'status': 'motion'}
dec 17 07:09:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Illumination_158d000xxxxxxx: 4.0>: {'status': 'motion'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 52.2>: {'temperature': '2070'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d000xxxxxxx: 20.5>: {'temperature': '2070'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Pressure_158d000xxxxxxx: 1009.7>: {'temperature': '2070'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 52.2>: {'humidity': '5149'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d000xxxxxxx: 20.7>: {'humidity': '5149'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Pressure_158d000xxxxxxx: 1009.7>: {'humidity': '5149'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 51.5>: {'pressure': '100975'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Temperature_158d000xxxxxxx: 20.7>: {'pressure': '100975'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Pressure_158d000xxxxxxx: 1009.7>: {'pressure': '100975'}
dec 17 07:09:41 nuc.bachstraat20 docker[12783]: 2018-12-17 07:09:41 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 51.5>: {'voltage': 2985, 'temperature': '2070', 'humidity': '5149', 'pressure': '100975'}
dec 17 07:10:28 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:28 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Humidity_158d000xxxxxxx: 64.2>: {'voltage': 2975, 'temperature': '1796', 'humidity': '6423', 'pressure': '101025'}
dec 17 07:10:28 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:28 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Pressure_158d000xxxxxxx: 1010.2>: {'voltage': 2975, 'temperature': '1796', 'humidity': '6423', 'pressure': '101025'}
dec 17 07:10:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000xxxxxxx: off>: {'channel_0': 'click'}
dec 17 07:10:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000xxxxxxx: off>: {'channel_0': 'click'}
dec 17 07:10:36 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:36 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000xxxxxxx: off>: {'channel_0': 'click'}
dec 17 07:10:43 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:43 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000xxxxxxx: off>: {'channel_1': 'click'}
dec 17 07:10:43 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:43 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000xxxxxxx: off>: {'channel_1': 'click'}
dec 17 07:10:43 nuc.bachstraat20 docker[12783]: 2018-12-17 07:10:43 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000xxxxxxx: off>: {'channel_1': 'click'}

The 6th - 4th last lines appeared when I pressed the left button. The last 3 lines appeared when I pressed the right button.

I’m having the same issue.
I’ve changed the event to xiaomi_aqara.click and it worked until last update.
I’ve noticed that all xiaomi devices stopped to send events: I’ve some door/windows sensor and motion detection. I can see the state but they doesn’t fire events anymore.

Any idea?

If you just updated from 0.82 to 0.84 and automation stops working, please make sure you have updated all event type values which now require “xiaomi_aqara.” prefix

0.82

event_type: click

Now:

event_type: xiaomi_aqara.click

This worked after update to 0.83 till last version

- alias: Toggle light
  trigger: 
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d0002287ab4
      click_type: single    
  action:
    service: light.toggle
    data:
        entity_id: light.yeelight_rgb_34ce00818743

This one stopped to work after last update:

- alias: Alarm
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0001e15d46
      to: 'on'
    - platform: state
      entity_id: binary_sensor.door_window_sensor_158d00019fec42
      to: 'on'
  action:
    - service: notify.telegram_message
    [...]

I opened an issue:

1 Like

This doesn’t work for me. Even in HA 0.84.3.

I tested my automation using an example (see below) provided by @syssi and it proved the sensor is working. The conclusion is that my action is not working any more.

- alias: Test single click event of the wall switch
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.wall_switch_left_158d00027c19e9
      click_type: single
  action:
    - service: persistent_notification.create
      data:
        title: "Aqara Wall Switch"
        message: "Single press of the left button detected"

With this example I get notifications in the UI.

Edit: My automation was disabled. After I enabled the automation it worked again.

Problem solved.
In all automation must be set:

initial_state: 'on'

2 Likes

Thanks a million :slight_smile:

That worked for me! Couldn’t figure it out last night.

Example working code:

- alias: Long Click to toggle Light Strip
  initial_state: 'on'
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_118xxxxxxxxxxx
      click_type: long_click_press
  action:
    - service: light.toggle
      entity_id:
        - light.light_strip
2 Likes

I can confirm this worked for me

Thanks
J

1 Like

since updating from 0.82.0 to 0.84.6 my Xiaomi buttons no longer work for the double_click and long_press_click
 I updated the code to account for the breaking changes hence the single click is working. Anyone know if this is a HA fault that is yet to be fixed?

Here is an example of one package which is only working for the single click but not the other click types:

automation:
  - alias: Ensuite Remote Button
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d00016bf679
          click_type: single
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d00016bf679
          click_type: double
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d00016bf679
          click_type: long_click_press

    action:
      - service: switch.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "single" %} switch.circadian_lighting_ensuite_circadian_lighting {% endif %}'
      - service: light.turn_on
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "single" %} light.ensuite_light {% endif %}'
          brightness: 255
          rgb_color: [255,255,255]
      - service: automation.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "single" %} automation.ensuite_light_auto_on_motion {% endif %}'
      - service: automation.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "single" %} automation.ensuite_light_off_after_2mins {% endif %}'

      - service: light.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "double" %} light.ensuite_light {% endif %}'
      - service: automation.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "double" %} automation.ensuite_light_auto_on_motion {% endif %}'
      - service: automation.turn_off
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "double" %} automation.ensuite_light_off_after_2mins {% endif %}'
      
      - service: switch.turn_on
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "long_click_press" %} switch.circadian_lighting_ensuite_circadian_lighting {% endif %}'
      - service: automation.turn_on
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "long_click_press" %} automation.ensuite_light_auto_on_motion {% endif %}'
      - service: automation.turn_on
        data_template:
          entity_id: '{% if trigger.event.data.click_type == "long_click_press" %} automation.ensuite_light_off_after_2mins {% endif %}'

This is working for me. We have some syntax differences.

########################################
############ Mini Button ###############
########################################
  - id: mini_button
    alias: "Mini Button"
    trigger:
      platform: event
      event_type: xiaomi_aqara.click
      event_data:
        entity_id: binary_sensor.mini_button
    action:
      - service_template: >
          {% if trigger.event.data['click_type'] == 'long_click_press' %}
            homeassistant.toggle
          {% elif trigger.event.data['click_type'] == 'single', 'double' %}
            homeassistant.turn_on
          {% else %}
            homeassistant.toggle
          {% endif %}
        data_template:
          entity_id: >
            {% if trigger.event.data['click_type'] == 'single' %}
              script.tv_lights
            {% elif trigger.event.data['click_type'] == 'double' %}
              script.pause_living_room_harmony
            {% elif trigger.event.data['click_type'] == 'long_click_press' %}
              input_boolean.block_all_motion_lights
            {% else %}
              light.gateway_light2
            {% endif %}
      - service: input_select.select_option
        data_template:
          entity_id: input_select.mini_button_last_action
          option: > 
            {% if trigger.event.data['click_type'] == 'single' %}
              Single Click
            {% elif trigger.event.data['click_type'] == 'double' %}
              Double Click
            {% elif trigger.event.data['click_type'] == 'long_click_press' %}
              Long Press
            {% else %}
              Unknown
            {% endif %}
3 Likes

Finally got around to updating my switches. Thanks for the code!!!