No Xiaomi Aqara Wireless Switch long_click, both_double_click and both_long_click support?

I have a Xiaomi WXKG02LM Aqara smart light double switch. Currently I have some automation’s that are triggered on the event_type: xiaomi_aqara.click and click_type: single and click_type: both. Those run just fine.

Example that works:

automation:
  - alias: automation_room1
    trigger:
      platform: event
     event_type: xiaomi_aqara.click
      event_data:
        entity_id: binary_sensor.wall_switch_right_158d00027c19e9
        click_type:  <some click type>  <---  single or both 
    action:
      service: light.turn_on
     entity_id: light.room1

I also tried to use other click_types like long_click_press, long_click_release, hold, double_click, long_click, double_both_click and long_both_click, but those did not work.

I read in the documentation, in this forum and on github that my Xiaomi WXKG02LM Aqara smart light double switch only supports single and both clicks.

However, my Aqara Wireless Switch (Double) shows more than just the click_types single and both when I turned on debug logging:

logger:
    default: warn
    logs:
      homeassistant.components.xiaomi_aqara: debug
      homeassistant.components.automation: debug
      homeassistant.components.automation: debug

I can see the following click_types in the logging:

# click
2018-12-24 11:36:42 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'channel_0': 'click'}
2018-12-24 11:36:42 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'channel_0': 'click'}
2018-12-24 11:36:42 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'channel_0': 'click'}

# long_click
2018-12-24 11:36:46 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'channel_0': 'long_click'}
2018-12-24 11:36:46 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'channel_0': 'long_click'}
2018-12-24 11:36:46 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'channel_0': 'long_click'}

# double_click
2018-12-24 11:36:50 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'channel_0': 'double_click'}
2018-12-24 11:36:50 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'channel_0': 'double_click'}
2018-12-24 11:36:50 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'channel_0': 'double_click'}

#both_click
2018-12-24 11:36:55 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'dual_channel': 'both_click'}
2018-12-24 11:36:55 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'dual_channel': 'both_click'}
2018-12-24 11:36:55 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'dual_channel': 'both_click'}

# long_both_click
2018-12-24 11:37:00 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'dual_channel': 'long_both_click'}
2018-12-24 11:37:00 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'dual_channel': 'long_both_click'}
2018-12-24 11:37:00 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'dual_channel': 'long_both_click'}

# double_both_click
2018-12-24 11:37:03 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d00027c19e9: off>: {'dual_channel': 'double_both_click'}
2018-12-24 11:37:03 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d00027c19e9: off>: {'dual_channel': 'double_both_click'}
2018-12-24 11:37:03 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d00027c19e9: off>: {'dual_channel': 'double_both_click'}
2018-12-24 11:37:03 WARNING (MainThread) [custom_components.binary_sensor.xiaomi_aqara] Unsupported click_type detected: double_both_click

So it sends events on these click_types:

click
long_click
double_click
both_click
long_both_click
double_both_click

I looked into the Xiaomi binary sensor component code to see how the click events are parsed.

I found out that the click_types for a long press in the code differs from click_types of my switch.

click_type in …/binary_sensor/xiaomi_aqara.py code click_type WXKG02LM
long_click_press long_click
long_click_release - not supported -
click click
double_click double_click
both_click both_click
shake - not supported -
- not supported - long_both_click
- not supported double_both_click

To make a long_click possible I added two lines (see below) to the code and stored that file in ..config/custom_components/binary_sensor/xiaomi_aqara.py as a custom component:

    def parse_data(self, data, raw_data):
        """Parse data sent by gateway."""
        value = data.get(self._data_key)
        if value is None:
            return False

        if value == 'long_click_press':
            self._state = True
            click_type = 'long_click_press'
        elif value == 'long_click_release':
            self._state = False
            click_type = 'hold'
        elif value == 'click':
            click_type = 'single'
        elif value == 'double_click':
            click_type = 'double'
        elif value == 'both_click':
            click_type = 'both'
        elif value == 'shake':
            click_type = 'shake'

# added to support long press click

        elif value == 'long_click':
            click_type = 'long_click_press'
# end

        elif value in ['long_click', 'long_both_click']:
            return False
        else:
            _LOGGER.warning("Unsupported click_type detected: %s", value)
            return False

        self._hass.bus.fire('xiaomi_aqara.click', {
            'entity_id': self.entity_id,
            'click_type': click_type
        })
        self._last_action = click_type

        return True

With this small change a click_type: long_click_press now works in my automation, for example:

automation:
  - alias: automation_room1
    trigger:
      platform: event
     event_type: xiaomi_aqara.click
      event_data:
        entity_id: binary_sensor.wall_switch_right_158d00027c19e9
        click_type:  long_click_press
    action:
      service: light.turn_on
     entity_id: light.room1

My questions are:

  1. Is this a valid approach to fix this?
  2. The original binary_sensor/xiaomi_aqara.py does parse the click events ‘long_click’ and ‘long_both_click’ explicitly, but does not do anything with it. Why?
  3. What approach should be taken to get other click_types like long_both_click and double_both_click working.

Any help is very much appreciated!

Ted

I found a github issue where a single press on some types of Xiaomi switches caused a click and a long_click at the same time (single press):

https://github.com/home-assistant/home-assistant/issues/14694#issuecomment-394143456

The long_click event did cause an error in the log:

Unsupported click_type detected: long_click

This issue was reported for these types of switches:

https://www.gearbest.com/alarm-systems/pp_610095.html (WXKG02LM)
https://www.gearbest.com/access-control/pp_626696.html
https://www.gearbest.com/smart-light-bulb/pp_257679.html

In combination with this gateway configuration:

Xiaomi gateway:
Version code: 188
Zigbee: 20
fw_ver: 1.4.1_155
lumi.gateway.v3

As listed in the Gitub issue, @Syssi tried to reproduce the issue without success. He may used another type of switch or his gateway may run another firmware version.

I am also using the same WXKG02LM double switch in combination with the same gateway (version code: 208, lumi.gateway.v3, fw_ver: 1.4.1.159) without having getting a click and a long_click at the same time. When I short press, I get a click and when I press long, I get a long_click.

To suppress this error message, the long_click was ignored using this commit:

https://github.com/syssi/home-assistant/commit/4ee00eeac6b311b8d3fa56c081c618dc76b78408

Same story for the long_both_click. Some Xiaomi double switch produces a both_click and a long_both_click at the same time.

https://github.com/home-assistant/home-assistant/issues/14802

The long_both_click caused this error message in the log:

Unsupported click_type detected: long_both_click

The long_both_press was ignored using this commit:

https://github.com/syssi/home-assistant/commit/b0b937e9adfb7fba50e7605685bdfbcba8560c60

It is not my intention to judge anyone on previous decisions. On the contrary, I appreciate all the effort that everyone has put into developing this Xiaomi component.

I am just trying to understand how it works and may be help to achieve long_click, both_long_click, double_click and both_double_click support for my WXKG02LM switch.

May be it is possible to fix the long_click issue in an other way and at the same time add long_click support for the WXKG02LM? May be a firmware update?

I noticed a differ in switch model in mine and @syssi logging. Although on the back of my switch it says WXKG02LM, my log file reports 'model': 'remote.b286acn01'?! This type is not documented in the documentation. See my logging below:

DEBUG (Thread-3) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'remote.b286acn01', 'sid': '158d00027c19e9', 'short_id': 53379, 'data': '{"channel_0":"long_click"}'}

@Syssi tested the switch models 86sw2 (in the documentation known as WXKG02LM) and switch (in the documentation known as WXKG01LM), see github issue, see his logging snippets below:

DEBUG (Thread-24) [xiaomi_gateway] MCAST (report) << {'model': '86sw2', 'data': '{"dual_channel":"both_click"}', 'cmd': 'report', 'sid': '158d000128ccad', 'short_id': 37691}
MCAST (report) << {'sid': '158d000164413f', 'data': '{"status":"long_click_press"}', 'model': 'switch', 'cmd': 'report', 'short_id': 49393}

And @jojoro1/@jojoro tested with switch model 86sw1 (in the documentation known as WXKG03LM). His logging snippet below:

DEBUG (Thread-2) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': '86sw1', 'sid': '158d00013ff70e', 'short_id': 32227, 'data': '{"channel_0":"click"}'}

The question is: Is my WXKG02LM (model: remote.b286acn01) different from other WXKG02LM (model: 86sw2)? Or is that caused by the gateway firmware or something else?

I hope anyone has some answers for me.

Thanks for your sustainable research. :slight_smile: Long story short: Did you see this recent code change: https://github.com/home-assistant/home-assistant/pull/19518

I’m unabe to reproduce the issues (#14802 & #14694) with a recent gateway firmware with my 86sw2:

2018-12-26 08:51:27 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_1":"click"}', 'cmd': 'report'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:27 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_0":"click"}', 'cmd': 'report'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:27 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:28 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_1":"click"}', 'cmd': 'report'}
2018-12-26 08:51:28 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:28 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:28 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:29 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_0":"click"}', 'cmd': 'report'}
2018-12-26 08:51:29 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:29 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:29 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:31 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_1":"click"}', 'cmd': 'report'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:31 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_0":"click"}', 'cmd': 'report'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:31 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:32 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_1":"click"}', 'cmd': 'report'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:32 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_0":"click"}', 'cmd': 'report'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:32 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_0': 'click'}
2018-12-26 08:51:34 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"dual_channel":"both_click"}', 'cmd': 'report'}
2018-12-26 08:51:34 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'dual_channel': 'both_click'}
2018-12-26 08:51:34 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'dual_channel': 'both_click'}
2018-12-26 08:51:34 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'dual_channel': 'both_click'}
2018-12-26 08:51:35 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 51549, 'sid': '158d00013fa58e', 'model': 'motion', 'data': '{"status":"motion"}', 'cmd': 'report'}
2018-12-26 08:51:35 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Motion Sensor_158d00013fa58e: off>: {'status': 'motion'}
2018-12-26 08:51:35 DEBUG (Thread-22) [xiaomi_gateway] MCAST (report) << {'short_id': 3442, 'sid': '158d000128ccad', 'model': '86sw2', 'data': '{"channel_1":"click"}', 'cmd': 'report'}
2018-12-26 08:51:35 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:35 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Right)_158d000128ccad: off>: {'channel_1': 'click'}
2018-12-26 08:51:35 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d000128ccad: off>: {'channel_1': 'click'}

Merry christmas: Add a new click_type "long_both" by syssi · Pull Request #19573 · home-assistant/core · GitHub

1 Like

That is good news!

And a pull request for double_both click:

I have the same switches, marked as WXKG02LM. I however can’t get anything but single and both to work. I have enabled logging and viewed in the file the results of my clicks. The only things I see are: click and both click.

Any ideas why I haven’t got the extended click types as described? It would be really useful to extend the use of these switches and hang off them further automation’s.

From my log:
2019-02-19 18:45:29 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Left)_158d0001639d8f: off>: {‘dual_channel’: ‘both_click’}

2019-02-19 18:43:19 DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Wall Switch (Both)_158d0001639d8f: off>: {‘channel_1’: ‘click’}

2019-02-19 22:22:10 DEBUG (Thread-12) [xiaomi_gateway] MCAST (report) << {‘cmd’: ‘report’, ‘model’: ‘86sw2’, ‘sid’: ‘158d0001639d8f’, ‘short_id’: 56269, ‘data’: ‘{“dual_channel”:“both_click”}’}

HUB info:

Version code:221

Zigbee通道:26

网关信息:

“1.4.1_164”,“hw_ver”:“MW300”,“model”:“lumi.gateway.v3”,“mcu_fw_ver”:“0158”,“wifi_fw_ver”:“SD878x-14.76.36.p84-702.1.0-WM”,“ap”

Thanks