[Edge] Driver for Aqara Switches and Remotes

this is a known issue, I made some effort to debug this, but do not know how to handle it in a better way.

The ST Edge has a built-in function that subscribes to the changes in the important clusters, in that way it detects that a device is alive and pools the latest state of the device. In our case, there is a subscription to clusters OnOff and Power.

As you might know, old Xiaomi/Aqara has buttons and switches on the same cluster but on different endpoints. It would be beneficial to keep pooling switches state. However, with buttons, there is an issue - the device is answering that button is not pressed OnOff: false.
And it is exactly the same message that comes first when a user presses the button.
In the case of a short press, it’s easy to tell apart - there is another message OnOff: true comes instantly after.
But Hold is another story, the OnOff: true will come only when the button is released.

As the workaround is to use OnOff:true for Hold detection, but there is a huge delay in reaction, or even risk of the device reset because a user will not see any action and keep holding the button for more than 10 seconds.

I did not find a way to control which endpoints the pool message is sent.

I get most of that.

However, the log I posted earlier (if I’ve understood it correctly) shows the DTH sending a message to the device, which then sends a response. This response is then interpreted as the button being ‘held’.

My question is why is the original message from the hub to the device being sent every 8 minutes. Unfortunately I haven’t (yet?) managed to work out what that message means. Is it the Hub pooling the device?

Also, these devices send a non-standard zigbee message of the form ‘on/off: 0’ or on/off: 1’, when the button is held. Is edge able to catch this?

yes, exactly

it was non-standard in DTH, in Edge everything is much simpler and handled by the platform.

I admit I need to study this stuff more carefully.

However, I wonder whether it would be better for the polling to be linked to something else, such as the basic cluster, which could be handled without any side effects. Alternatively on/off with a check whether anything has actually changed before acting on the response.

I wonder whether it would be better for the polling to be linked to something else, such as the basic cluster, which could be handled without any side effects.

Well, it happens implicitly. and currently, I don’t know how to control the monitored attributes

you can start your search from st/zigbee/device.lua

--- Check all monitored attributes for this device and send a read where necessary
---
--- This will look through all monitored attributes that have been added to this device
--- and if we have not heard from or sent a read in above the expected interval, we will
--- send a read attribute to update our status.
function ZigbeeDevice:check_monitored_attributes()
  local monitored_attrs = self:get_field(MONITORED_ATTRIBUTES_KEY) or {}
  local cur_time = os.time()
  for cluster, attrs in pairs(monitored_attrs) do
    for attr, config in pairs(attrs) do
      if (cur_time - (config.last_heard_time or 0) > config.expected_interval) and
          (cur_time - config.last_read_time > config.expected_interval)
      then
        config.last_read_time = cur_time
        log.info(string.format("Doing health check read for [%s]:%04X:%04X", self.device_network_id, cluster, attr))
        self:send(device_management.attr_refresh(self, cluster, attr, config.mfg_code))
      end
    end
  end
end

Would you be able to add the “Aqara WXCJKG13LM Button” to you driver. This is a 3 button, battery operated device.

Thanks!

Hello Bralok,

I have two-button device from this series (WXCJKG11LM)

It is possible to make it work but it is more problematic, as there is a light group control is a default mode. What it can mean to you

  • it won’t work perfectly out of the box, it will take a few reinstallations, you have to master getting logs and forcibly reinstalling the driver
  • the remote connected to the default group will trigger ALL THE LIGHTS in your house. (Testing in the evening when you are not alone is not recommended)
  • I do not own any 6 button device so it will require additional testing and UI adjustments.

please let me know if you have any questions and still want to proceed :wink:

That’s ok for me. Just to make sure I understood correctly:

Does reinstalling mean uninstalling and then installing as usual? :stuck_out_tongue_closed_eyes:. Where can I get the logs?

That’s fine.

I would recommend starting with

this is a tool to get logs and install drivers from your computer.

I’ve added a new fingerprint for your device, you should be able to link the device now.

Hi, would you be able to add this Aqara one button battery operated device, WXKG12LM?

well, as far as I can see it does not behave like other buttons/switches.
The gyroscope is something that can’t be implemented without a device.

I’ll try to figure out something with a basic function.

the fingerprint is added, you can link the device and try.

After some fine work of @veonua , the device Aqara opploe (WXCJKG11LM) six buttons is fully working.

Thanks a lot!

EDIT: In case anyone try to pair the device: you must select scan nearby in the app and then long press the link button as many times as needed until the device is recognised (4 or 5 times are usually enough). Then, in the configuration, select Button events (normal) even though is already selected. Afterwards, repeat the pairing process again.

Hi, thanks for adding the fingerprint to the driver, but for some reason pairing the button with the hub it is found as Thing and no driver. I tried pairing at least 10 times, but no luck.

In CLI logs I did not see anything. But it would not show there if it is not finding fingerprint match with any of the hub installed drivers? So something is not going right there.

Do you use “Search nearby”?
Do you have any other edge device?
I can recommend to deactivate/remove the old driver if you have it

I did use Search Nearby and have other buttons, light bulbs, power plugs using Edge drivers. This Aqara button and IKEA led driver are last ones to switch over to Edge.

I could try replacing the battery as it took longer to pair compared to other devices…

Here is the signature again if you want to check for any typos;
Data
application: 05
endpointId: 01
manufacturer: LUMI
model: lumi.sensor_switch.aq3
zigbeeNodeType: SLEEPY_END_DEVICE
Raw Description 01 0104 5F01 01 04 0000 0012 0006 0001 01 0000

- id: "WXKG12LM"
    deviceLabel: WXKG12LM Wireless Switch (Single Rocker)
    manufacturer: LUMI
    model: lumi.sensor_switch.aq3
    deviceProfileName: button

This is from the old device handler;

// WXKG12LM
fingerprint deviceId: ‘5F01’, inClusters: ‘0000,0001,0006,0012’, outClusters: ‘0000’, manufacturer: ‘LUMI’, model: ‘lumi.sensor_switch.aq3’, deviceJoinName: 'Aqara Button WXKG12LM

Does the device I’d need to be 5F01 new driver to work?

It took more than half an hour to pair the device, but I forgot to remove the old DTH. So now trying again with DTH removed.

Am I reading you correct that for the WXKG02LM (Wireless 2 button) the option for " button 3" (both buttons at the same time) isn’t possible with your driver?

it is possible, but now it sends 3 events.

button 1 pressed
button 2 pressed
group 1 pressed

because I want to toggle both my wired and unwired lights at the same time