Yoda-x/ha-zha-new

WXKG11LM - Xiaomi Aqara Smart Wireless Switch support

Closed this issue · 35 comments

Hi Yoda :)

Recently I bought mentioned in title Aqara switch and I'm trying to use it with your implementation of ZHA.
It's succesfully paired, with some errors while adding, but works after all.

Problem is that it's reporting WARNING
"Updating zha_new switch tool longer than 10 seccongs"

and second problem is that sometimes (like twice a day) trigger itself (triggering autiomation which listen to state change of switch)

I'm using you newer MASTER branch code
The devices in bellow looks like this:
Device: NWK: 0x507a IEEE: 00:15:8d:00:01:e7:a1:74 Endpoints: 1: profile=0x104, device_type=24321 Input Clusters: Basic (0) On/Off (6) Manufacturer Specific (65535) Output Clusters: Basic (0) Groups (4) Manufacturer Specific (65535)
Image of Switch

I think it's not handled by your code, it's rather just working because standard ZHA works partially.
Can you confirm?

If you need anything more to solve/adding support for this let me know please.
Thanks in advance

Hi
this device is not supported, or not prepared. can you send me your zigbee db, or the exract for this switch?
I assume it is this one:

Thanks

There you can get my .db file

URL is correct - this is exactly the switch i bought.

Cheers!

please add this file in your devices directory. It just set the device type as binary_sensor. binary_sensors are not pulled every 30 sec, they send the updates on demand.
Can you check in the logbook what causes the trigger? goes it from on to off or from some other state like unavailable

File added and Warning in log about updating gone - thanks

I already tried to catch what causing this unwanted turning on, but with no success.
Problem is that after boot the Hass sesnor has status OFF, after first use it changes to ON and stayed like this for ever. There is nothing in logbook about change this status.

However my automation rule triggers after I press the button:

`- action:

  • service: switch.toggle
    data:
    entity_id: 'switch.bedroom_spotlights'
    alias: 'Aqara button'
    trigger:
    • platform: state
      entity_id: binary_sensor.lumi_lumisensor_switchaq2_01e7a174_1_on_off`

Here is a part of zigbee log when self-turning on occured. Hope it will help you to find anything useful.

ok, this makes it somehow clear.
If this switch acts as the one I have (the battery driven wall switch from aqara) it just sends an message if you press it. it's not sending "1" for the state, its like you use it, a toggle notification. thus every time you press the button it send the state to "on", and never to off.
if a message comes in zha updates the state, which not changes the state, but the internal attribute, when is was last triggered.
From the ha documentation:

Triggers when the state of a given entity changes. If only entity_id is given trigger will activate for all state changes, even if only state attributes change.

sorry, don't helps. please disable logging for bellows and enable it for zigpy and custom_components

thanks

Yes, it seems to work exactly how you described it above.

Here is new log

Last entries (00:4x:xx) is time when self turn-on happened

Ah, thats better.

  1. I see the reason for the self turn:-on The switch sends an keepalive when you not pressed a button for ~50min. This is to keep the zigbee controller happy. I will prepare a better device file for you. It may take some days
  2. I think you can fix your problem in the meantime your self. Every time you press the button

Attribute report received: 0=Bool.false, 0=Bool.true

it sends status=0, when pressing and status=1
releasing. If you change your automation to trigger for state changes from 0->1 you should be good.

ad1) Would great, thanks a lot :)

ad2) Maybe this is dump question, but how can I detect that?
There is no any suitable attribute nor state (it's always ON, not integer value)

przechwytywanie

can you try

trigger:
  platform: state
  entity_id:  binary_sensor.lumi_lumisensor_switchaq2_01e7a174_1_on_off
  from: "off"
  to: "on"

in your script.
If toggling still works, this should prevent the unwanted triggers. Should be a quick check.
thanks

Thanks I set that ... give me some time to report if it helped :)

Unfortunatelly trick doesn't work ...

This binary sensor has always state ON, so there is no transition from OFF to ON.

Code I used:

`- action:

  • service: switch.toggle
    data:
    entity_id: 'switch.bedroom_spotlights'
    alias: 'Aqara button'
    trigger:
    • platform: state
      entity_id: binary_sensor.lumi_lumisensor_switchaq2_01e7a174_1_on_off
      from: 'off'
      to: 'on'`

Please try out the preview branch for zha_new /bellows/zigpy and let me know how it works:
it uses now events:
eg, the script below should list the events in the logbook like this:
click event: Entity binary_sensor.lumi_lumisensor_86sw2un_01f466c1_3_on_off, type toggle

- alias: click_log
  id: click_log
  initial_state: True
  trigger:
    platform: event
    event_type: click
    # optional
    event_data:
      channel: OnOff
  action:
    - service: logbook.log
      data_template:
        name: "click event: "
        message: "Entity {{ trigger.event.data.entity_id  }}, type {{ trigger.event.data.type }}"

If you see the events in you logbook it should be easy to adjust your toggle script.

Thanks a lot.

Updated zha_new, zigpy and bellow. No errors so far and it's working as expected :)

Thank you!!!

Edit: #1: According to tech information this sensor should support single click and double click.
If you are interested to add also double one, please instruct me what logs you need

Edit #2: I see in the code that you add support for attributes like battery and so on in case of this sensor. But none of it appeared in details of mine. Only Last Seen attribute is new.

BTW. Soon I'm going to receive WXKG02LM Aqara Smart Light Switch. Are you interested to add support for it too? ;)

nice to hear:-)
2: battery information should be updated every 50 minutes with the keep alive. If you don't see it now. please let me know. It's more a raw estimate
2: send me log files for a double click, maybe the information is already there and just need to be mangled
3: thats the one I have, no need to add support for it

  1. Nope, few hours of working and still no battery information.
    Tell me what you need for it, I will provide :)

przechwytywanie

  1. This is single press:
    2018-09-11 22:09:52 DEBUG (MainThread) [zigpy.zcl] [0x0b40:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x65ce4110>>, <Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x65ce4730>>]] 2018-09-11 22:09:52 DEBUG (MainThread) [zigpy.zcl] [0x0b40:1:0x0006] Attribute report received: 0=Bool.false, 0=Bool.true 2018-09-11 22:09:52 DEBUG (MainThread) [custom_components.binary_sensor.zha_new] Attribute report received on cluster [0x0006:0:]=Bool.false 2018-09-11 22:09:52 DEBUG (MainThread) [custom_components.device.lumi_sensor_switch_aq2] parse 0 Bool.false ('lumi.sensor_switch.aq2',) {'cluster_id': 6} 2018-09-11 22:09:52 DEBUG (MainThread) [custom_components.binary_sensor.zha_new] Attribute report received on cluster [0x0006:0:]=Bool.true 2018-09-11 22:09:52 DEBUG (MainThread) [custom_components.device.lumi_sensor_switch_aq2] parse 0 Bool.true ('lumi.sensor_switch.aq2',) {'cluster_id': 6}

And this is when I double press
2018-09-11 22:09:58 DEBUG (MainThread) [zigpy.zcl] [0x0b40:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x6e67d190>>, <Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x590d1bb0>>]] 2018-09-11 22:09:58 DEBUG (MainThread) [zigpy.zcl] [0x0b40:1:0x0006] Attribute report received: 0=Bool.false, 0=Bool.true 2018-09-11 22:09:58 DEBUG (MainThread) [custom_components.binary_sensor.zha_new] Attribute report received on cluster [0x0006:0:]=Bool.false 2018-09-11 22:09:58 DEBUG (MainThread) [custom_components.device.lumi_sensor_switch_aq2] parse 0 Bool.false ('lumi.sensor_switch.aq2',) {'cluster_id': 6} 2018-09-11 22:09:58 DEBUG (MainThread) [custom_components.binary_sensor.zha_new] Attribute report received on cluster [0x0006:0:]=Bool.true 2018-09-11 22:09:58 DEBUG (MainThread) [custom_components.device.lumi_sensor_switch_aq2] parse 0 Bool.true ('lumi.sensor_switch.aq2',) {'cluster_id': 6}

  1. GREAT !

I'm getting the following attributes for double/triple/quad presses. I'm seeing attr_id==32768 on cluster_id==6 indicating the number of presses:

2018-09-11 16:36:14 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d080>>, <Attribute attrid=0 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d7f0>>]]
2018-09-11 16:36:14 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] Attribute report received: 0=Bool.false, 0=Bool.true
2018-09-11 16:36:14 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: on> 0 Bool.false
2018-09-11 16:36:14 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: off> 0 Bool.true
2018-09-11 16:36:16 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=32768 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d9b0>>]]
2018-09-11 16:36:16 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] Attribute report received: 32768=2
2018-09-11 16:36:16 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: on> 32768 2
2018-09-11 16:36:19 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=32768 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d9b0>>]]
2018-09-11 16:36:19 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] Attribute report received: 32768=3
2018-09-11 16:36:19 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: on> 32768 3
2018-09-11 16:36:19 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] ZCL request 0x000a: [[<Attribute attrid=65281 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d080>>]]
2018-09-11 16:36:19 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] Attribute report received: 65281=b'\x04!\xa8\x01\n!\x00\x00'
2018-09-11 16:36:21 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=32768 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d080>>]]
2018-09-11 16:36:21 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] Attribute report received: 32768=3
2018-09-11 16:36:21 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: on> 32768 3
2018-09-11 16:36:21 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] ZCL request 0x000a: [[<Attribute attrid=65281 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d198>>]]
2018-09-11 16:36:21 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] Attribute report received: 65281=b'\x04!\xa8\x01\n!\x00\x00'
2018-09-11 16:36:24 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] ZCL request 0x000a: [[<Attribute attrid=32768 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d198>>]]
2018-09-11 16:36:24 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0006] Attribute report received: 32768=4
2018-09-11 16:36:24 DEBUG (MainThread) [homeassistant.components.switch.zha] Attribute updated: <Entity None: on> 32768 4
2018-09-11 16:36:24 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] ZCL request 0x000a: [[<Attribute attrid=65281 value=<zigpy.zcl.foundation.TypeValue object at 0x7f44a5b4d160>>]]
2018-09-11 16:36:24 DEBUG (MainThread) [zigpy.zcl] [0x1cf2:1:0x0000] Attribute report received: 65281=b'\x04!\xa8\x01\n!\x00\x00'

@Adminiuga do you have the same device, I don't see this attribute in the log of @KLUSEK .
But should not a problem to create an event if this attribute is received and send the value with the event, The automation script then need to do something useful with it. I wil modify the device file.
Thanks for the information

@KLUSEK
1: please don't press the button for 1 h, I know it's difficult:-)
2: can you provide a longer log extract, both cases you showed are the same. Maybe 10 sec, thus, everything should be visible.
thanks

@Yoda-x I seem to have the same device as OP. at the back I get:
Aqara WXKG11KM WXKG11LM
CMIT ID:2016DP6442

bellows devices output:

Device:
  NWK: 0xbeef
  IEEE: 00:de:ad:00:be:ef:de:ad
  Endpoints:
    1: profile=0x104, device_type=24321
      Input Clusters:
        Basic (0)
        On/Off (6)
        Manufacturer Specific (65535)
      Output Clusters:
        Basic (0)
        Groups (4)
        Manufacturer Specific (65535)

PS: apparently I can't type, but going to blame it on k & l keys being to close to one another

Regarding to information I found today there are following devices (look almost the same):

Xiaomi Wireless switch (WXKG01LM) (1x - 4x click, Key Held, Key released)
Aqara Wireless switch (WXKG11LM) supports 1x - 4x click (lumi_lumisensor_switchaq2)
Aqara Wireless switch with Gyro (WXKG12LM) 1x, 2x click, key held, key released, Shaken (lumi_lumisensor_switchaq3)

@Yoda-x I will do today :)

I take a look on the homey xiaomi implementation, I think from there comes your information also.
And the driver implementation was quite informative, as they use sometimes different clusters and attributes.
Forwarding the events to HASS should not an issue. From there it's an automation task to handle them useful. As I don't have one of these switches it's difficult to test.

Hi Master Yoda.

Unfortunately, even after whole night with no touching the button ;) there is no attributes like battery updated.

Here is the log: home-assistant.log

And those are times where is tried single, double etc clicks:
10:54:27 - 1x click
11:10:22 - 2x click
11:10:48 - 3x click
11:11:28 - 4x click

ok, please update zha. I added events for the clicks, please check if you see these.
About the battery monitoring. The logs show that the keepalive message comes to the DH file, and I see no reason why it not shows in the gui. Can you enable full debug for HASS and udpate zha. I added a debug statement at the end. Just want to see if the attributes getting updated and what HASS is doing with the updated information.
The event name is "click" and has data attributes: entity_id(->entity_id), channel (-> OnOff), type (-> toggle), data (-> 1, 2,3 or other number)

Okay, multiclick works :)

BTW. It seems you missed variable in this line:
_LOGGER.debug('updated Attributes:', attributes)
after fixing it to:
_LOGGER.debug('updated Attributes: %s', attributes)

I can see in my logs that attributes are logged:
2018-09-16 22:25:53 DEBUG (MainThread) [custom_components.device.lumi_sensor_switch_aq2] updated Attributes: {'path': 0, 'X-attrib-4': 5032, 'last seen': datetime.datetime(2018, 9, 16, 22, 25, 53, 700364, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)}
but they are still missing in HASS UI - weird.
Do you think removing sensor from .db and adding it again may change anything?

I will check in the morning if there is any battery info

can you enable full debug?

logger:
  default: debug

And yes, try to remove it from the DB and then start over again.

I did some clean up and bug fixing which may have resolved it. Please update zha_new/zigpy/bellows to the newest preview and try again

This is the log from the night

home-assistant (1).log

It's not from updated version yet. I will update and check again soon :) thanks

Hi
any news here?

Thanks

Unfortunately not.

I run the latest preview and no battery info for this particular sensor. But I can live with that as long as it works super stable after all :)

cool.

Hi @KLUSEK
Did you managed to receive WXKG02LM and get it working?
I'm having the issue with it: #71

Hi @KLUSEK
Did you managed to receive WXKG02LM and get it working?
I'm having the issue with it: #71

Hi, No I haven't tried after all. The switch is still in the box, waiting ;)

Good luck