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

Fix Linkind motion sensor detection #2874

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Dec 30, 2023

Proposed change

Fixes the issue where Linkind motion sensors get reset after 60 seconds (during continuous motion).
Also fixes the issue where brightness triggers the motion entity.

Explanation

According to the OP in #1291, the Linkind motion sensor uses three bits for the IasZone zone_status:

  • Alarm_1 for detected motion
  • Alarm_2 for detected brightness
  • tamper for detected tamper

ZHA currently creates a binary sensor for motion, but turns it on if either Alarm_1 or Alarm_2 is set to 1.
As we want to ignore the brightness bit for the motion sensor entity, this PR modifies the quirk to always ignore the Alarm_2 bit on this motion sensor, so only Alarm_1 (motion) is considered for the motion sensor entity.

A test to verify the added code works was also added.

Previous quirk with timeout to reset

#2130 added a quirk which reset the motion sensor after a timeout (expecting continuous reports every 60 seconds).
This caused issues for some users at least (perhaps different firmware versions?).
Z2M does not use a timeout to reset the sensor, so we likely also shouldn't.


In #2225, @jasongabler removed the added quirk entirely and the motion sensors started working again. (Maybe old versions do not use the Alarm_2 bit for brightness at all?)
If you're around, can you try this version of the quirk to see if it (still) works for you?
@LAHA2 Please also confirm if this works.

@1jk, @jfrux, @dmackenzie123, @TheRealSimon42 were the ones that had issues with the motion sensor getting stuck.
If you can, please also try if this quirk version (still) works for you.

Install as a custom quirk:

To install this as a custom quirk, download the the motion.py file.
Then, add this to your HA configuration.yaml. Copy the downloaded .py file in the (newly) created custom_zha_quirks directory and restart HA.

Additional information

Fixes #2225, fixes #1291

Partly reverts #2130 / commit 7f5c506.

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

@TheJulianJES TheJulianJES added the bugfix This PR fixes a bug label Dec 30, 2023
Copy link

codecov bot commented Dec 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a2911a0) 87.50% compared to head (c0eb75b) 87.50%.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2874   +/-   ##
=======================================
  Coverage   87.50%   87.50%           
=======================================
  Files         292      292           
  Lines        8952     8954    +2     
=======================================
+ Hits         7833     7835    +2     
  Misses       1119     1119           

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

@LAHA2
Copy link

LAHA2 commented Dec 31, 2023

I can confirm this resolved the issue I was having. The status of the motion sensor now remains 'Detected' as long as motion is ongoing. 60 seconds after motion ceases, the status reverts to 'Cleared'.

Thank you!!

@TheJulianJES
Copy link
Collaborator Author

Awesome, thanks for letting me know!

@TheJulianJES TheJulianJES merged commit 6b9516d into zigpy:dev Jan 5, 2024
14 checks passed
@1jk
Copy link

1jk commented Jan 14, 2024

I can also confirm that this quirk resolves the issue of no motion detection in dark. Log section below.

Deactivation, activation, and deactivation in the dark

Logbook:

motion ZB-Motion Sensor-D0003 cleared (no motion detected)
9:00:32 PM - 22 minutes ago
motion ZB-Motion Sensor-D0003 detected motion
8:59:25 PM - 23 minutes ago
motion ZB-Motion Sensor-D0003 cleared (no motion detected)
8:47:20 PM - 35 minutes ago

ZCL Log:

Line 10232: 2024-01-13 20:47:20.072 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received ZCL frame: b'\x19c\x002\x00\x00\x00\x00\x00'
Line 10233: 2024-01-13 20:47:20.073 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.CLUSTER_COMMAND: 1>, is_manufacturer_specific=0, direction=<Direction.Client_to_Server: 1>, disable_default_response=1, reserved=0, *is_cluster=True, *is_general=False), tsn=99, command_id=0, *direction=<Direction.Client_to_Server: 1>)
Line 10234: 2024-01-13 20:47:20.073 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame: IasZoneLinkind:status_change_notification(zone_status=<ZoneStatus.Alarm_2|Supervision_reports|Restore_reports: 50>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)
Line 10235: 2024-01-13 20:47:20.074 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received command 0x00 (TSN 99): status_change_notification(zone_status=<ZoneStatus.Alarm_2|Supervision_reports|Restore_reports: 50>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)
Line 13225: 2024-01-13 20:59:25.816 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received ZCL frame: b'\x19d\x003\x00\x00\x00\x00\x00'
Line 13226: 2024-01-13 20:59:25.819 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.CLUSTER_COMMAND: 1>, is_manufacturer_specific=0, direction=<Direction.Client_to_Server: 1>, disable_default_response=1, reserved=0, *is_cluster=True, *is_general=False), tsn=100, command_id=0, *direction=<Direction.Client_to_Server: 1>)
Line 13227: 2024-01-13 20:59:25.821 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame: IasZoneLinkind:status_change_notification(zone_status=<ZoneStatus.Alarm_1|Alarm_2|Supervision_reports|Restore_reports: 51>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)
Line 13228: 2024-01-13 20:59:25.822 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received command 0x00 (TSN 100): status_change_notification(zone_status=<ZoneStatus.Alarm_1|Alarm_2|Supervision_reports|Restore_reports: 51>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)
Line 13527: 2024-01-13 21:00:32.469 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received ZCL frame: b'\x19e\x002\x00\x00\x00\x00\x00'
Line 13528: 2024-01-13 21:00:32.470 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.CLUSTER_COMMAND: 1>, is_manufacturer_specific=0, direction=<Direction.Client_to_Server: 1>, disable_default_response=1, reserved=0, *is_cluster=True, *is_general=False), tsn=101, command_id=0, *direction=<Direction.Client_to_Server: 1>)
Line 13529: 2024-01-13 21:00:32.471 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Decoded ZCL frame: IasZoneLinkind:status_change_notification(zone_status=<ZoneStatus.Alarm_2|Supervision_reports|Restore_reports: 50>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)
Line 13530: 2024-01-13 21:00:32.472 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Received command 0x00 (TSN 101): status_change_notification(zone_status=<ZoneStatus.Alarm_2|Supervision_reports|Restore_reports: 50>, extended_status=<bitmap8: 0>, zone_id=0, delay=0)

elupus pushed a commit to elupus/zha-device-handlers that referenced this pull request Jan 17, 2024
Fixes the issue where Linkind motion sensors get reset after 60 seconds (during continuous motion).
Also fixes the issue where "brightness" triggers the motion entity.
@Sandman-wr
Copy link

There's a lot to read here, was there a problem with the Linkind semsor staying ON, as 24/7 detecting? I have that problem, and also with ZHA still showing it detecting with the battery removed. ??

lgraf pushed a commit to lgraf/zha-device-handlers that referenced this pull request May 6, 2024
Fixes the issue where Linkind motion sensors get reset after 60 seconds (during continuous motion).
Also fixes the issue where "brightness" triggers the motion entity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes a bug
Projects
None yet
4 participants