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:
- Is this a valid approach to fix this?
- 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? - What approach should be taken to get other click_types like
long_both_click
anddouble_both_click
working.
Any help is very much appreciated!
Ted