Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quirk for Aqara P1 contact sensor #2822

Merged
merged 4 commits into from
Dec 27, 2023
Merged

Add quirk for Aqara P1 contact sensor #2822

merged 4 commits into from
Dec 27, 2023

Conversation

dmulcahey
Copy link
Collaborator

@dmulcahey dmulcahey commented Dec 9, 2023

Proposed change

Title says it all. Fixes: #2349, #1295

TODO:

  • Add config entity for detection distance to ZHA

Additional information

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

Copy link

codecov bot commented Dec 9, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (aeca76d) 87.35% compared to head (61abc62) 87.43%.
Report is 19 commits behind head on dev.

Files Patch % Lines
zhaquirks/xiaomi/aqara/magnet_ac01.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2822      +/-   ##
==========================================
+ Coverage   87.35%   87.43%   +0.08%     
==========================================
  Files         287      291       +4     
  Lines        8835     8908      +73     
==========================================
+ Hits         7718     7789      +71     
- Misses       1117     1119       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheJulianJES TheJulianJES added the new quirk Adds support for a new device label Dec 9, 2023
@matttbe
Copy link
Contributor

matttbe commented Dec 17, 2023

@dmulcahey thank you for having worked on this!

Today, I tried it and it doesn't fully work on my side:

  • The status (open/close) is showing the opposite:
    • For the moment, the door is closed but HA is displaying "Open"
    • In fact, when I open or close the door, it looks like I get two events, e.g.: here I opened the door at 11:08:59 and closed it at 11:09:12
      image
    • I guess that's not because I never configured the detection distance (Koenkk/zigbee-herdsman-converters@2796ef7)
    • This is what I have in the "diagnostics":
"out_clusters": {
  "0x0006": {
    "endpoint_attribute": "on_off",
    "attributes": {
      "0x0000": {
        "attribute_name": "on_off",
        "value": 1
      }
    },
    "unsupported_attributes": {}
  },
  (...)

  • For the battery, HA displays "Unknown" while it has info about it:
"in_clusters": {
  (...)
  "0x0001": {
    "endpoint_attribute": "power",
    "attributes": {
      "0x0033": {
        "attribute_name": "battery_quantity",
        "value": 1
      },
      "0x0031": {
        "attribute_name": "battery_size",
        "value": 8
      },
      "0x0020": {
        "attribute_name": "battery_voltage",
        "value": 32.6
      }
    },
    "unsupported_attributes": {}
  },

Do you not have the same issues on your side? Is it possible I don't have exactly the same hardware?

Here is the full .json file from ZHA for this device: zha-diagnostics.zip

A while ago, I tried to play a bit with it and I noticed that sometimes, I had to invert the on_off value and sometimes not. But I didn't play to much with it, I noticed I had "strange" behaviours and I had to switch to something else.

@TheJulianJES
Copy link
Collaborator

For the moment, the door is closed but HA is displaying "Open"

To confirm, when the magnet is near the sensor, it's showing "opened" instead of "closed"?

it looks like I get two events

That could be because the magnet isn't close enough to the sensor.

I guess that's not because I never configured the detection distance

You can configure it in the clusters UI for now. Go to the device page, click on the three dots on the left, then click on "Manage Zigbee device". After selecting the "clusters" tab, select the OppleCluster below and the detection_distance attribute.
Then, you can read the attribute to see what it's currently set to. You'll need to press the button on the sensor whilst reading the attribute using the button in the UI. Please let me know what the default is.

You can also change the distance by writing 1, 2, or 3 in the upper text field and then pressing "write attribute". Make sure to always leave the lower text field empty.

@TheJulianJES TheJulianJES added the Xiaomi Request/PR regarding a Xiaomi device label Dec 24, 2023
@matttbe
Copy link
Contributor

matttbe commented Dec 24, 2023

@TheJulianJES: thank you for your reply!

For the moment, the door is closed but HA is displaying "Open"

To confirm, when the magnet is near the sensor, it's showing "opened" instead of "closed"?

Yes it is.

it looks like I get two events

That could be because the magnet isn't close enough to the sensor.

That's a good idea. It is quite close: the gap in between is around 5mm, less than the first detection distance of 10mm. (but maybe that's not the gap I should measure).

If I add an extra magnet -- something that came with the sensor, rectangle, around 18mm by 10mm, I don't know what it was for -- on the existing magnet to reduce this distance, it now displays the correct status!

I guess that's not because I never configured the detection distance

You can configure it in the clusters UI for now. Go to the device page, click on the three dots on the left, then click on "Manage Zigbee device". After selecting the "clusters" tab, select the OppleCluster below and the detection_distance attribute. Then, you can read the attribute to see what it's currently set to. You'll need to press the button on the sensor whilst reading the attribute using the button in the UI. Please let me know what the default is.

Thank you for the instructions! I tried to read the attribute after having pressed the button or even while opening the door but I always get an error.

The logs from ZHA: we can see we get info after a few seconds, maybe after the timeout?

home-assistant_zha_2023-12-24T11-43-01.078Z.zip

I don't know if it is related but when I try to re-configure the device, the bindings don't work:

image

The device is quite far from my USB dongle, and I struggled to pair it. That could explain why the bindings don't work? On the other hand, when I open the door, the HA UI always show events being fired up right away.

You can also change the distance by writing 1, 2, or 3 in the upper text field and then pressing "write attribute". Make sure to always leave the lower text field empty.

I tried doing this but I have the same error as when I read the field.

@TheJulianJES
Copy link
Collaborator

Press the button on the device whilst reading or writing the attribute.

@matttbe
Copy link
Contributor

matttbe commented Dec 25, 2023

Press the button on the device whilst reading or writing the attribute.

I tried that multiple times without success. I also tried to press the button multiple times while waiting for the attribute to be read but it didn't help. Could it be due to the distance with the controller or some interferences even if I get the open and close events without issues?

Copy link
Collaborator

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

("Note" for me that also applies here: #2821 (comment))

@dmulcahey dmulcahey merged commit 968315d into dev Dec 27, 2023
14 checks passed
@dmulcahey dmulcahey deleted the dm/aqara_p1_contact branch December 27, 2023 16:29
elupus pushed a commit to elupus/zha-device-handlers that referenced this pull request Jan 17, 2024
* Add quirk for Aqara P1 contact sensor

* fix battery size

* switch cluster implementation

* update quirk
lgraf pushed a commit to lgraf/zha-device-handlers that referenced this pull request May 6, 2024
* Add quirk for Aqara P1 contact sensor

* fix battery size

* switch cluster implementation

* update quirk
@Ma1ch
Copy link

Ma1ch commented Aug 14, 2024

Hey! Thank you for your effort on this quirk!

I have a Conbee ii and using a rpi 4. I have just paired the sensor with these details:
IEEE: 54:ef:44:10:00:d4:54:81
Nwk: 0x315d
Device Type: EndDevice
LQI: 255
RSSI: -52
Quirk: magnet_ac01.LumiMagnetAC01

It seems to be using the python script above, however for some reason it does not react when I physically try to trigger the sensor. It still stays as "open". Pairing works and connection is working fine. I downloaded the json of the diagnostics and it is as attached.

zha-01J2FX0ZNCYY506T9TV5R1QX7P-LUMI lumi.magnet.ac01-7bf832946fb1e82b9231436cf856cb75.json

Have you been able to get this working? The sensor I am trying to configure is MCCGQ13LM.

@TheJulianJES
Copy link
Collaborator

@Ma1ch Make sure the firmware of your Conbee is up-to-date. Otherwise, create a new issue in this repo.

@Ma1ch
Copy link

Ma1ch commented Aug 14, 2024

@TheJulianJES Thanks for the advice, I have just updated the firmware and am still facing the same issue. I will create a new issue!

@TheJulianJES
Copy link
Collaborator

@Ma1ch Remove and re-pair the sensor after updating the Conbee firmware.

@Ma1ch
Copy link

Ma1ch commented Aug 14, 2024

@TheJulianJES Perfect! After doing so, the light on the sensor started shining when bringing the magnet close by, so I got some response from the sensor. Did not reflect back to home assistant yet though, and I tried to reconfigure it, and the light stopped working completely. So I removed the sensor and re-paired it, and it started working, both the light on the device and the status on home assistant. This was great! I've been battling for hours with this. Battery still doesn't show and I am a little puzzled as to why it started working after I re-paired it twice, but regardless I can now start using the sensor. Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new quirk Adds support for a new device Xiaomi Request/PR regarding a Xiaomi device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Device Support Request] Aqara P1 - MCCGQ13LM
4 participants