Repository: zigpy/zha-device-handlers

Issue:
[BUG] Since 2023.2.0, Linkind motion sensors reset during motion
**Describe the bug**
My Linkind PIR Zigbee motion sensors stopped working as expected since 2023.2.0. HA will no longer recognize continued motion from these sensors and seems generally confused until I at least wait for the sensor to go idle. I have concluded that the sensors are not at fault because, when I down grade to 2023.1.7, they perform as expected.  I use ZHA with a Conbee II. I have a 2 year old Zigbee mesh that has worked flawlessly until now.

It was recommended I post here from the following official FB group post:  https://www.facebook.com/groups/HomeAssistant/permalink/3449772355294110/
Note that the post comments have a number of concerns about ZHA since HA 2023.2.0 was released.

Steps to reproduce the behavior:
Using a simple, native HA automation that has worked flawlessly (Lights on with motion; Lights off after 2min of idle)
1. Walk into sensor zone, lights turn on
2. Keep moving in sensors zone for over 2min, lights will turn off. I've tested this up to 4 minutes
3. Leave zone for 1min, walking back into zone and it _may_ turn on. How long I have to wait for HA to recognize idle seems to vary

Again, this not a matter of poor automation configuration. The same, exact automations are in pay for 2023.1.7 and 2023.2.0. I also watch the motion entity and it fails to detect idle or motion according to the above experience with the automation.

**Expected behavior**
* Walk into idle zone with lights off,  have entity UI show motion and lights go on
* Remain in motion within zone and entity should continue to show motion and lights should stay on indefinitely, until 2min after motion stops.


**Screenshots**
N/A

<details>
I don't really have much debug details because I really don't even know how to begin debugging this. I will update with more information as I continue to test and investigate.

<!-- Device signature can be acquired by clicking on the "Zigbee Device Signature" button in the device settings view -->
<summary>Device signature</summary>
The only Zigbee related info I see on the device is as follows:
Zigbee info
IEEE: cc:86:ec:ff:fe:cd:54:35
Nwk: 0x4e5b
Device Type: EndDevice
LQI: 127
RSSI: -78
Last Seen: 2023-02-25T15:04:06
Power Source: Battery or Unknown

```yaml
Paste the device signature here.
Don't remove the extra line breaks outside the ``` marks.
```

</details>

<details>
<!-- Diagnostic information can be acquired by clicking on the "Download Diagnostics" button in the device settings view -->
<summary>Diagnostic information</summary>

```yaml
Paste the diagnostic information here.
Don't remove the extra line breaks outside the ``` marks.
```

</details>

<details>
<summary>Additional logs</summary>

```
Paste any additional debug logs here.
Don't remove the extra line breaks outside the ``` marks.
```

</details>

**Additional context**
Add any other context about the problem here.

[Device Support Request] Linkind ZB-MotionSensor-D0003
**Is your feature request related to a problem? Please describe.**

The sensor is recognized in Home Assistant as a motion sensor and reports motion in the logs as Alarm_1; the sensor also has a bright/dark sensor it reports as Alarm_2 on dark. The problem is that if either Alarm is active Home Assistant marks motion as "on" --- if it is dark the sensor does not time out after motion stops until it is bright again and the motion status updates making it useless for detecting repeated motion in dark or near-dark rooms. Note that it only updates the status of bright/dark when it reports on motion start or motion timeout.

**Describe the solution you'd like**

The motion entity reports motion status (Alarm_1) regardless of the light/dark status (Alarm_2). If possible, an entity that reports the light/dark update status. If possible, An additional entity for Tamper status.

**Device signature - this can be acquired by removing the device from ZHA and pairing it again from the add devices screen. Be sure to add the entire content of the log panel after pairing the device to a code block below this line.**

```yaml
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4456, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": 260,
      "device_type": "0x0402",
      "in_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0020",
        "0x0500",
        "0x0b05",
        "0xfc81"
      ],
      "out_clusters": [
        "0x0019"
      ]
    }
  },
  "manufacturer": "lk",
  "model": "ZB-MotionSensor-D0003",
  "class": "zigpy.device.Device"
}
```

**Additional context**

https://zigbee.blakadder.com/Linkind_ZS110040078.html
https://www.linkind.com/product/pir-motion-sensor-zigbee/

Output from activity log showing various states; bright and dark were achieved by placing sensor in front of computer monitor and changing between white and black background:

_NoTamper, Bright, NoMotion 0-0-0 0 48_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=37 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports: 48>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.0

_NoTamper, Bright, Motion 0-0-1 1 49_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=38 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Alarm_1: 49>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_1

_NoTamper, Dark, NoMotion 0-2-0 2 50_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=32 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Alarm_2: 50>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2

_NoTamper, Dark, Motion 0-2-1 3 51_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=31 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Alarm_2|Alarm_1: 51>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2|Alarm_1

_Tamper, Bright, NoMotion 4-0-0 4 52_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=24 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Tamper: 52>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.0

_Tamper, Bright, Motion 4-0-1 5 53_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=23 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Tamper|Alarm_1: 53>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_1

_Tamper, Dark, NoMotion 4-2-0 6 54_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=29 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Tamper|Alarm_2: 54>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2

_Tamper, Dark, Motion 4-2-1 7 55_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=20 command_id=0>
[0x3ab3:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Tamper|Alarm_2|Alarm_1: 55>, <bitmap8.0: 0>, 0, 0]
[0x3ab3:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2|Alarm_1

_Other_
[0x3ab3:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=True is_reply=True disable_default_response=True> manufacturer=4456 tsn=25 command_id=Command.Report_Attributes>
[0x3ab3:1:0x0500] ZCL request 0x000a: [[Attribute(attrid=65531, value=<TypeValue type=uint8_t, value=1>)]]
[0x3ab3:1:0x0500] Attribute report received: 65531=1

Output from join log:

<details>
<summary>Logs</summary>

```python
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Received childJoinHandler frame with [1, <Bool.true: 1>, 0x8009, 04:cd:15:ff:fe:63:7d:48, <EmberNodeType.SLEEPY_END_DEVICE: 4>]
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Received trustCenterJoinHandler frame with [0x8009, 04:cd:15:ff:fe:63:7d:48, <EmberDeviceUpdate.STANDARD_SECURITY_UNSECURED_JOIN: 1>, <EmberJoinDecision.USE_PRECONFIGURED_KEY: 0>, 0x0000]
2022-01-16 12:41:56 INFO (MainThread) [zigpy.application] Device 0x8009 (04:cd:15:ff:fe:63:7d:48) joined the network
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.application] Device 04:cd:15:ff:fe:63:7d:48 changed id (0x8009 => 0x8009)
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Scheduling initialization
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Canceling old initialize call
2022-01-16 12:41:56 INFO (MainThread) [zigpy.device] [0x8009] Requesting 'Node Descriptor'
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x95 request
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_BROADCAST: 4>, EmberApsFrame(profileId=0, clusterId=19, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_SOURCE_EUI64|APS_OPTION_UNKNOWN: 1032>, groupId=0, sequence=13), 255, -82, 0x8009, 255, 255, b'\x81\t\x80H}c\xfe\xff\x15\xcd\x04\x80']
2022-01-16 12:41:56 INFO (MainThread) [bellows.zigbee.application] ZDO Device announce: 0x8009, 04:cd:15:ff:fe:63:7d:48
2022-01-16 12:41:56 INFO (MainThread) [zigpy.application] Device 0x8009 (04:cd:15:ff:fe:63:7d:48) joined the network
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Scheduling initialization
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Canceling old initialize call
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.application] Received frame on uninitialized device <Device model=None manuf=None nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=False> from ep 0 to ep 0, cluster 19: b'\x81\t\x80H}c\xfe\xff\x15\xcd\x04\x80'
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] ZDO request ZDOCmd.Device_annce: [0x8009, 04:cd:15:ff:fe:63:7d:48, 128]
2022-01-16 12:41:56 INFO (MainThread) [zigpy.device] [0x8009] Requesting 'Node Descriptor'
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x97 request
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=2, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=151), 152, b'\x97\t\x80')
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32770, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=14), 255, -82, 0x8009, 255, 255, b'\x97\x00\t\x80\x02@\x80h\x11RR\x00\x00,R\x00\x00']
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.application] Received frame on uninitialized device <Device model=None manuf=None nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=False> from ep 0 to ep 0, cluster 32770: b'\x97\x00\t\x80\x02@\x80h\x11RR\x00\x00,R\x00\x00'
2022-01-16 12:41:56 INFO (MainThread) [zigpy.device] [0x8009] Got Node Descriptor: NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4456, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)
2022-01-16 12:41:56 INFO (MainThread) [zigpy.device] [0x8009] Discovering endpoints
2022-01-16 12:41:56 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x99 request
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:56 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=5, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=153), 154, b'\x99\t\x80')
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32773, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=15), 255, -82, 0x8009, 255, 255, b'\x99\x00\t\x80\x01\x01']
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.application] Received frame on uninitialized device <Device model=None manuf=None nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=False> from ep 0 to ep 0, cluster 32773: b'\x99\x00\t\x80\x01\x01'
2022-01-16 12:41:57 INFO (MainThread) [zigpy.device] [0x8009] Discovered endpoints: [1]
2022-01-16 12:41:57 INFO (MainThread) [zigpy.device] [0x8009] Initializing endpoints [<Endpoint id=1 in=[] out=[] status=<Status.NEW: 0>>]
2022-01-16 12:41:57 INFO (MainThread) [zigpy.endpoint] [0x8009:1] Discovering endpoint information
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x9b request
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=4, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=155), 156, b'\x9b\t\x80\x01')
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32772, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=16), 255, -82, 0x8009, 255, 255, b'\x9b\x00\t\x80\x18\x01\x04\x01\x02\x04\x01\x07\x00\x00\x01\x00\x03\x00 \x00\x00\x05\x05\x0b\x81\xfc\x01\x19\x00']
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.application] Received frame on uninitialized device <Device model=None manuf=None nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=False> from ep 0 to ep 0, cluster 32772: b'\x9b\x00\t\x80\x18\x01\x04\x01\x02\x04\x01\x07\x00\x00\x01\x00\x03\x00 \x00\x00\x05\x05\x0b\x81\xfc\x01\x19\x00'
2022-01-16 12:41:57 INFO (MainThread) [zigpy.endpoint] [0x8009:1] Discovered endpoint information: SizePrefixedSimpleDescriptor(endpoint=1, profile=260, device_type=1026, device_version=1, input_clusters=[0, 1, 3, 32, 1280, 2821, 64641], output_clusters=[25])
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x9d request
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=0, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=157), 158, b'\x00\x9d\x00\x04\x00\x05\x00')
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=0, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=17), 255, -82, 0x8009, 255, 255, b'\x08\x9d\x01\x04\x00\x00B\x02lk\x05\x00\x00B\x15ZB-MotionSensor-D0003']
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0000] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=157 command_id=Command.Read_Attributes_rsp>
2022-01-16 12:41:57 INFO (MainThread) [zigpy.device] [0x8009] Read model 'ZB-MotionSensor-D0003' and manufacturer 'lk' from <Endpoint id=1 in=[basic:0x0000, power:0x0001, identify:0x0003, poll_control:0x0020, ias_zone:0x0500, diagnostic:0x0B05, manufacturer_specific:0xFC81] out=[ota:0x0019] status=<Status.ZDO_INIT: 1>>
2022-01-16 12:41:57 INFO (MainThread) [zigpy.device] [0x8009] Discovered basic device information for <Device model='ZB-MotionSensor-D0003' manuf='lk' nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=True>
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.application] Device is initialized <Device model='ZB-MotionSensor-D0003' manuf='lk' nwk=0x8009 ieee=04:cd:15:ff:fe:63:7d:48 is_initialized=True>
2022-01-16 12:41:57 DEBUG (MainThread) [homeassistant.components.zha.core.gateway] device - 0x8009:04:cd:15:ff:fe:63:7d:48 entering async_device_initialized - is_new_join: True
2022-01-16 12:41:57 DEBUG (MainThread) [homeassistant.components.zha.core.gateway] device - 0x8009:04:cd:15:ff:fe:63:7d:48 has joined the ZHA zigbee network
2022-01-16 12:41:57 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): started configuration
2022-01-16 12:41:57 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:ZDO](ZB-MotionSensor-D0003): 'async_configure' stage succeeded
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0x9f request
2022-01-16 12:41:57 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xa1 request
2022-01-16 12:41:57 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0000]: finished channel configuration
2022-01-16 12:41:57 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xa3 request
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=159), 160, b'\x00\x9f\x00\x01\x00')
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=33, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=161), 162, b'\xa1H}c\xfe\xff\x15\xcd\x04\x01\x01\x00\x03\xc2\xda\x0e\x15\x00o\r\x00\x01')
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=33, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=163), 164, b'\xa3H}c\xfe\xff\x15\xcd\x04\x01 \x00\x03\xc2\xda\x0e\x15\x00o\r\x00\x01')
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=18), 240, -82, 0x8009, 255, 255, b'\x08\x9f\x01\x01\x00\x001\r\x00']
2022-01-16 12:41:58 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=159 command_id=Command.Read_Attributes_rsp>
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32801, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=19), 255, -82, 0x8009, 255, 255, b'\xa1\x00']
2022-01-16 12:41:58 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: started IASZoneChannel configuration
2022-01-16 12:41:58 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xa5 request
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:58 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: bound 'power' cluster: Status.SUCCESS
2022-01-16 12:41:58 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xa7 request
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32801, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=20), 255, -82, 0x8009, 255, 255, b'\xa3\x00']
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=33, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=165), 166, b'\xa5H}c\xfe\xff\x15\xcd\x04\x01\x00\x05\x03\xc2\xda\x0e\x15\x00o\r\x00\x01')
2022-01-16 12:41:58 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: bound 'poll_control' cluster: Status.SUCCESS
2022-01-16 12:41:58 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xa9 request
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=167), 168, b'\x00\xa7\x06\x00 \x00 \x10\x0e0*\x01\x00!\x00 \x10\x0e0*\x01')
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:41:58 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=32, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=169), 170, b'\x00\xa9\x02\x00\x00#\x903\x00\x00')
2022-01-16 12:41:59 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=22), 255, -82, 0x8009, 255, 255, b'\x08\xa7\x07\x00']
2022-01-16 12:41:59 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=167 command_id=Command.Configure_Reporting_rsp>
2022-01-16 12:41:59 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=32, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=23), 246, -82, 0x8009, 255, 255, b'\x08\xa9\x04\x00']
2022-01-16 12:41:59 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0020] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=169 command_id=Command.Write_Attributes_rsp>
2022-01-16 12:41:59 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: Successfully configured reporting for '{'battery_voltage': (3600, 10800, 1), 'battery_percentage_remaining': (3600, 10800, 1)}' on 'power' cluster: [ConfigureReportingResponseRecord(status=0)]
2022-01-16 12:41:59 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: finished channel configuration
2022-01-16 12:41:59 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: 3300.0s check-in interval set: [[WriteAttributesStatusRecord(status=<Status.SUCCESS: 0>)]]
2022-01-16 12:41:59 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: finished channel configuration
2022-01-16 12:41:59 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0019]: finished channel configuration
2022-01-16 12:42:02 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_BROADCAST: 4>, EmberApsFrame(profileId=0, clusterId=54, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_UNKNOWN: 8>, groupId=0, sequence=25), 255, -81, 0x8009, 255, 255, b'\x02\xb4\x01']
2022-01-16 12:42:02 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] ZDO request ZDOCmd.Mgmt_Permit_Joining_req: [180, <Bool.true: 1>]
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32801, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=26), 255, -82, 0x8009, 255, 255, b'\xa5\x00']
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: bound 'ias_zone' cluster: Status.SUCCESS
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xad request
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=173), 174, b'\x00\xad\x02\x10\x00\xf0\xc2\xda\x0e\x15\x00o\r\x00')
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=32801, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=21), 255, -79, 0x8009, 255, 255, b'\xa5\x00']
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] ZDO request ZDOCmd.Bind_rsp: [<Status.SUCCESS: 0>]
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] No handler for ZDO request:ZDOCmd.Bind_rsp([<Status.SUCCESS: 0>])
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=27), 255, -79, 0x8009, 255, 255, b'\x08\xad\x04\x00']
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=173 command_id=Command.Write_Attributes_rsp>
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: wrote cie_addr: 00:0d:6f:00:15:0e:da:c2 to 'ias_zone' cluster: [WriteAttributesStatusRecord(status=<Status.SUCCESS: 0>)]
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: Sending pro-active IAS enroll response
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: finished IASZoneChannel configuration
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xaf request
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: 'async_configure' stage succeeded
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: 'async_configure' stage succeeded
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0000]: 'async_configure' stage succeeded
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: 'async_configure' stage succeeded
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0019]: 'async_configure' stage succeeded
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): completed configuration
2022-01-16 12:42:08 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): stored in registry: ZhaDeviceEntry(name='unk_manufacturer unk_model', ieee='04:cd:15:ff:fe:63:7d:48', last_seen=1642372928.5891716)
2022-01-16 12:42:08 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xb1 request
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=175), 176, b'\x01\xaf\x00\x00\x00')
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:08 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=3, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=177), 178, b'\x01\xb1@\x02\x00')
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=3, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=28), 255, -79, 0x8009, 255, 255, b'\x08\xb1\x0b@\x81']
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0003] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=177 command_id=Command.Default_Response>
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0003]: executed 'trigger_effect' command with args: '(2, 0)' kwargs: '{}' result: [64, <Status.UNSUP_CLUSTER_COMMAND: 129>]
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): started initialization
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:ZDO](ZB-MotionSensor-D0003): 'async_initialize' stage succeeded
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: initializing channel: from_cache: False
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xb3 request
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: initializing channel: from_cache: False
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xb5 request
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0000]: initializing channel: from_cache: False
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0000]: finished channel initialization
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: initializing channel: from_cache: False
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: finished channel initialization
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0019]: initializing channel: from_cache: False
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0019]: finished channel initialization
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=179), 180, b'\x00\xb3\x00\x00\x00')
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=181), 182, b'\x00\xb5\x00 \x00!\x00')
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=29), 255, -80, 0x8009, 255, 255, b'\x08\xb3\x01\x00\x00\x000\x01']
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=179 command_id=Command.Read_Attributes_rsp>
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=32), 255, -80, 0x8009, 255, 255, b'\x08\xb5\x01 \x00\x00 \x1b!\x00\x00 \x86']
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=181 command_id=Command.Read_Attributes_rsp>
2022-01-16 12:42:09 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: finished channel initialization
2022-01-16 12:42:09 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xb7 request
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:09 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=183), 184, b'\x00\xb7\x001\x003\x00')
2022-01-16 12:42:11 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=33), 255, -80, 0x8009, 255, 255, b'\x08\xb7\x011\x00\x000\x023\x00\x00 \x01']
2022-01-16 12:42:11 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=183 command_id=Command.Read_Attributes_rsp>
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: finished channel initialization
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: 'async_initialize' stage succeeded
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0001]: 'async_initialize' stage succeeded
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0000]: 'async_initialize' stage succeeded
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0020]: 'async_initialize' stage succeeded
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0019]: 'async_initialize' stage succeeded
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): power source: Battery or Unknown
2022-01-16 12:42:11 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x8009](ZB-MotionSensor-D0003): completed initialization
2022-01-16 12:42:14 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_BROADCAST: 4>, EmberApsFrame(profileId=0, clusterId=6, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_UNKNOWN: 264>, groupId=0, sequence=34), 255, -82, 0x8009, 255, 255, b'\x03\xfd\xff\x04\x01\x01\x19\x00\x00']
2022-01-16 12:42:14 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] ZDO request ZDOCmd.Match_Desc_req: [0xFFFD, 260, [25], []]
2022-01-16 12:42:14 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=32774, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=3), 185, b'\x03\x00\x00\x00\x01\x01')
2022-01-16 12:42:16 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=25, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_RETRY: 64>, groupId=0, sequence=35), 255, -82, 0x8009, 255, 255, b'\x01\x02\x01\x00h\x11\xfb\x80\x02\x00#Q']
2022-01-16 12:42:16 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=2 command_id=1>
2022-01-16 12:42:16 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] ZCL request 0x0001: [0, 4456, 33019, 1361248258, None]
2022-01-16 12:42:16 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] OTA query_next_image handler for 'lk ZB-MotionSensor-D0003': field_control=0, manufacture_id=4456, image_type=33019, current_file_version=1361248258, hardware_version=None
2022-01-16 12:42:16 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] No OTA image is available
2022-01-16 12:42:16 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=25, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=2), 186, b'\x19\x02\x02\x98')
2022-01-16 12:42:18 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=30), 255, -82, 0x8009, 255, 255, b'\t\x01\x01\r\x00h\x11']
2022-01-16 12:42:18 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=False> manufacturer=None tsn=1 command_id=1>
2022-01-16 12:42:18 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x0001: [<ZoneType.Motion_Sensor: 13>, 4456]
2022-01-16 12:42:18 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: Enroll requested
2022-01-16 12:42:18 DEBUG (MainThread) [zigpy.device] [0x8009] Extending timeout for 0xbb request
2022-01-16 12:42:18 DEBUG (MainThread) [bellows.zigbee.application] Extending timeout for 04:cd:15:ff:fe:63:7d:48/0x8009
2022-01-16 12:42:18 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=187), 188, b'\x01\xbb\x00\x00\x00')
2022-01-16 12:42:19 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=36), 255, -82, 0x8009, 255, 255, b'\x1ch\x11\x03\n\xfb\xff \x00']
2022-01-16 12:42:19 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=True is_reply=True disable_default_response=True> manufacturer=4456 tsn=3 command_id=Command.Report_Attributes>
2022-01-16 12:42:19 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x000a: [[Attribute(attrid=65531, value=<TypeValue type=uint8_t, value=0>)]]
2022-01-16 12:42:19 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Attribute report received: 65531=0
2022-01-16 12:42:24 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_BROADCAST: 4>, EmberApsFrame(profileId=0, clusterId=6, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_UNKNOWN: 264>, groupId=0, sequence=37), 255, -83, 0x8009, 255, 255, b'\x04\xfd\xff\x04\x01\x01\x19\x00\x00']
2022-01-16 12:42:24 DEBUG (MainThread) [zigpy.zdo] [0x8009:zdo] ZDO request ZDOCmd.Match_Desc_req: [0xFFFD, 260, [25], []]
2022-01-16 12:42:24 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=0, clusterId=32774, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=4), 189, b'\x04\x00\x00\x00\x01\x01')
2022-01-16 12:42:26 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=25, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_RETRY: 64>, groupId=0, sequence=38), 244, -82, 0x8009, 255, 255, b'\x01\x04\x01\x00h\x11\xfb\x80\x02\x00#Q']
2022-01-16 12:42:26 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=4 command_id=1>
2022-01-16 12:42:26 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] ZCL request 0x0001: [0, 4456, 33019, 1361248258, None]
2022-01-16 12:42:26 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] OTA query_next_image handler for 'lk ZB-MotionSensor-D0003': field_control=0, manufacture_id=4456, image_type=33019, current_file_version=1361248258, hardware_version=None
2022-01-16 12:42:26 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0019] No OTA image is available
2022-01-16 12:42:26 DEBUG (MainThread) [bellows.ezsp.protocol] Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x8009, EmberApsFrame(profileId=260, clusterId=25, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=4), 190, b'\x19\x04\x02\x98')
2022-01-16 12:42:59 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=39), 255, -80, 0x8009, 255, 255, b'\x18\x05\n!\x00 \xa8']
2022-01-16 12:42:59 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=5 command_id=Command.Report_Attributes>
2022-01-16 12:42:59 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] ZCL request 0x000a: [[Attribute(attrid=33, value=<TypeValue type=uint8_t, value=168>)]]
2022-01-16 12:42:59 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0001] Attribute report received: battery_percentage_remaining=168
2022-01-16 12:45:06 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=40), 255, -74, 0x8009, 255, 255, b'\x1ch\x11\x06\n\xfb\xff \x01']
2022-01-16 12:45:06 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=GLOBAL_COMMAND manufacturer_specific=True is_reply=True disable_default_response=True> manufacturer=4456 tsn=6 command_id=Command.Report_Attributes>
2022-01-16 12:45:06 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x000a: [[Attribute(attrid=65531, value=<TypeValue type=uint8_t, value=1>)]]
2022-01-16 12:45:06 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] Attribute report received: 65531=1
2022-01-16 12:45:06 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=41), 255, -74, 0x8009, 255, 255, b'\x19\x07\x007\x00\x00\x00\x00\x00']
2022-01-16 12:45:06 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=7 command_id=0>
2022-01-16 12:45:06 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Tamper|Alarm_2|Alarm_1: 55>, <bitmap8.0: 0>, 0, 0]
2022-01-16 12:45:06 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2|Alarm_1
2022-01-16 12:45:30 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=42), 253, -90, 0x8009, 255, 255, b'\x19\x08\x003\x00\x00\x00\x00\x00']
2022-01-16 12:45:30 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=8 command_id=0>
2022-01-16 12:45:30 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Alarm_2|Alarm_1: 51>, <bitmap8.0: 0>, 0, 0]
2022-01-16 12:45:30 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2|Alarm_1
2022-01-16 12:46:30 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=1280, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=43), 240, -78, 0x8009, 255, 255, b'\x19\t\x002\x00\x00\x00\x00\x00']
2022-01-16 12:46:30 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=True disable_default_response=True> manufacturer=None tsn=9 command_id=0>
2022-01-16 12:46:30 DEBUG (MainThread) [zigpy.zcl] [0x8009:1:0x0500] ZCL request 0x0000: [<ZoneStatus.Restore_reports|Supervision_reports|Alarm_2: 50>, <bitmap8.0: 0>, 0, 0]
2022-01-16 12:46:30 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x8009:1:0x0500]: Updated alarm state: ZoneStatus.Alarm_2
```

</details>


Discussion:
Please provide the device signature and diagnostic information for the device. You'll find them if you go to the device page of the motion sensor, then click the three dots on the left.
You can download the diagnostic file there and attach it here.

(It'll also include the signature but you can find just that part in the same menu by clicking "Manage Zigbee device" -> "Signature" tab)

The only change I see is that support was added for some kind of Linkind motion sensor by a community member: https://github.com/zigpy/zha-device-handlers/pull/2130
It's possible that this change interferes with your sensors that might be running a different firmware (or similar).

We can check that if you provide signature/diagnostic information. For now, you can download that from the working 2023.1.7 version.
> Please provide the device signature and diagnostic information for the device.
> ...
> The only change I see is that support was added for some kind of Linkind motion sensor by a community member: #2130 It's possible that this change interferes with your sensors that might be running a different firmware (or similar).
> 
> We can check that if you provide signature/diagnostic information. For now, you can download that from the working 2023.1.7 version.

As for change #2130, I do know that Linkind has recently changed their firmware which made  (at least) their PIR devices  non-integratabtle with HA (or at least ZHA).  If you go the [Amazon ratings page for these devices](https://www.amazon.com/product-reviews/B07Y9MST7Y/ref=acr_dp_hist_1?ie=UTF8&filterByStar=one_star&reviewerType=all_reviews#reviews-filter-bar),  starting around 9/2022 Home Assistant users began reporting that the PIR sensors with new firmware no longer worked well with HA.  As my devices are considerably older and I have never used the Linkind hub, I have not had these issues.  But it would make sense that someone with only the newer firmware would submit a fix that unwittingly had a bad effect on the older firmware'd devices.

Within "Manage Zigbee Device" -> "SIGNTURE" tab:
```json
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4456, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": 260,
      "device_type": "0x0402",
      "in_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0020",
        "0x0500",
        "0x0b05",
        "0xfc81"
      ],
      "out_clusters": [
        "0x0019"
      ]
    }
  },
  "manufacturer": "lk",
  "model": "ZB-MotionSensor-D0003",
  "class": "zigpy.device.Device"
}
```

The diagnostic file is attached.

Thank you.


[zha-3c156512e016bff5e5871b2312226cb3-lk ZB-MotionSensor-D0003-3fe117de98e699e28248dd150cee6a5f.json.txt](https://github.com/zigpy/zha-device-handlers/files/10832587/zha-3c156512e016bff5e5871b2312226cb3-lk.ZB-MotionSensor-D0003-3fe117de98e699e28248dd150cee6a5f.json.txt)

Your signature seems like it would match the quirk introduced in 2023.2.0. The original issue there (https://github.com/zigpy/zha-device-handlers/issues/1291) was that motion sensors would basically *never* reset. Normally, a compliant motion sensor sends a "detected" and "no longer detected" report.
Some Linkind sensors only seem to send a "detected" report, but repeat that like every minute, as long as motion is still detected. The quirk implemented functionality to support that.

For now, you can enable custom quirks (https://github.com/zigpy/zha-device-handlers/discussions/693#discussioncomment-857274)

1. Create a folder called `custom_zha_quirks` in your `/config` directory.

2. Then, add something like this to your HA ``configuration.yaml`` (this assumes you're running Home Assistant OS and specifies the path for the custom quirks. If it doesn't work, try just `custom_zha_quirks` (so remove the `/config/` and trailing slash)
```yaml
zha:
  custom_quirks_path: /config/custom_zha_quirks/
```

3. Download this file [linkind_revert_motion.py.zip](https://github.com/zigpy/zha-device-handlers/files/10832616/linkind_revert_motion.py.zip), extract the ZIP, and put it into your `custom_zha_quirks` directory.

4. Then upgrade to HA 2023.2.5 (or 2023.3.0 betas if you want) and see if the issue still happens.

The custom quirks should basically revert to previous behavior.
I fell like I come to this kind of issue again and again over time...

And I think that the current implementation must be wrong. Let me to explain myself.

The current implementation for the `MotionWithReset` listen to the `0x00:status_change_notification` command_id (incorrectly identified as the `ZONE_STATE` attribute):
https://github.com/zigpy/zha-device-handlers/blob/f6ab87e1c48ccb6db262e8732ca6b63d67fb6252/zhaquirks/__init__.py#L267-L270

So, every time that a `status_change_notification` command is received, the code reset the counter (the `_timer_handle`) and start it again for the `reset_s` time.
So, if a device stops to call the command, the `_timer_handle` will reset the `ZONE_STATE` to 0 (and I believe that must be the `ZONE_STATUS` but that's another issue (or not)):
https://github.com/zigpy/zha-device-handlers/blob/f6ab87e1c48ccb6db262e8732ca6b63d67fb6252/zhaquirks/__init__.py#L242-L246

But there is no validation for what value is calling the command, which `zone_status` value is in the call:
https://github.com/zigpy/zigpy/blob/be5b2914a12ac6a19af80c5a83dab40d7957aa01/zigpy/zcl/clusters/security.py#L102-L112

This is not the issue itself, but could affect to the resolution.

So, my guess is that some devices (old firmware?) are sending only the occupied/unoccupied command when the presence/absence is triggered. These were working fine without any quirk but will not with a quirk and the `reset_s`.
Other devices (new firmware?) are calling the occupied command while occupied and stop calling once unoccupied. But it can be also that is calling the command with an 'unoccupied' value, but the implementation handle it as a 'occupied' command.

Then, how can we fix both behaviors?
I don't know. We can try to see which are the attributes in the new firmware devices hopping that there is a `unoccupied` value when no motion detected. If the value is not there I don't know how can we handle both behaviors.


Regarding the `ZONE_STATE` vs `ZONE_STATUS` part, there does seem to be some kind of issue.

This is the cluster_command part that parses the ``0x00`` "Zone Status Change Notification" command:
https://github.com/home-assistant/core/blob/c9dfa15ed611340ed30045486e207ee93247b890/homeassistant/components/zha/core/channels/security.py#L342-L349
From what I can see, that part never actually changes the `ZONE_STATUS` attribute though.
It does correctly call ``async_set_state`` on the binary sensor which correctly triggers the sensor entity in HA.

Not sure if/when this is even called, but this looks like it would break for all devices that use `MotionWithReset`:
https://github.com/home-assistant/core/blob/c9dfa15ed611340ed30045486e207ee93247b890/homeassistant/components/zha/binary_sensor.py#L170-L175

So, the ``_update_attribute(ZONE_STATE, <ON/OFF>)`` methods look like they should really use ``ZONE_STATUS``.
The ``ZONE_STATE`` (0x00) constant is also misused for the "Zone Status Change Notification" (0x00). We should probably have a constant for those. I can look at all those changes in a bit probably.

---

Regarding the problem with this Linkind sensor, that won't help much I guess.
It would help if we have the ``sw_build_id`` (or ``app_version`` or some kind of version identifier) to see if we are really dealing with two "separate sensors" (or if the quirk was created because of network problems ("no motion" message not received properly?)).




> For now, you can enable custom quirks ([#693 (comment)](https://github.com/zigpy/zha-device-handlers/discussions/693#discussioncomment-857274))
> 
> 1. Create a folder called `custom_zha_quirks` in your `/config` directory.
> 2.

@TheJulianJES, 

Is there a way to confirm that this has properly loaded other than the imprecise method of seeing if the symptoms are resolved?  Is there some dev tool I can use to inspect?

Thanks.
@jasongabler Yes, it'll show on the device page if you expand "Zigbee info".
You can click the three dots at the bottom there -> Manage Zigbee device -> Signature tab.
At the bottom of the signature for "class", you want to see something with "custom" (depends on how the quirk is called).
> > For now, you can enable custom quirks ([#693 (comment)](https://github.com/zigpy/zha-device-handlers/discussions/693#discussioncomment-857274))
>
> @TheJulianJES,

@TheJulianJES ,  I can confirm that this quirk has fixed the issue.   I can see in the signature that the quirk is in effect:

`"class": "linkind_revert_motion.LinkindD0003"
`
and the related automations are behavior as expected.

Thank you!
@TheJulianJES ,

Last thought... if I end up buying newer firmware'd versions of these sensors, I'd be stuck again as this quirk would render them useless (and if I remove it, it renders my old sensors useless.). So, will this be integrated into HA/ZHA on a device basis, such that there would be a switch in the UI? Something like "Old Firmware? [ ]"

Thanks!
Yeah, we need to fix this properly.
Keeping it open for now.

(Quirks could match by IEEE as a workaround for you)
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
> Yeah, we need to fix this properly. Keeping it open for now.
> 
> (Quirks could match by IEEE as a workaround for you)

Was this fix implemented in a later version of 

> Yeah, we need to fix this properly. Keeping it open for now.
> 
> (Quirks could match by IEEE as a workaround for you)

Hi there - do you know if this was implemented in a later version? I'm in the same boat with a handful of these sensors that worked very well through 2022 versions. Upon upgrading to 2023 version, exactly 60 seconds after motion is detected, HA always shows motion 'Cleared' regardless of ongoing motion during that 60 seconds. Only after 60 additional seconds after 'motion cleared', with no motion occurring, will it recognize a motion detected event. Example - I walk in a room - lights on; I continue moving for 60 seconds, lights go off every time. Remain in the room moving for 60+ more seconds, lights still will not come back on / motion remains 'cleared'; I must cease motion for full 60 seconds (ie, leave the room) before the  lights then come back on with motion detected event. 
Looking at https://github.com/zigpy/zha-device-handlers/issues/1291 with @1jk's explanation, it seems like the initial fix with resetting after a timeout wasn't really correct. The sensor uses the Alarm_1 bits and Alarm_2 bits of the IasZone status.
If one of these bits is `1`, ZHA considers the sensor to be "on". This is why it was always on previously (dark or motion).

We should filter out Alarm_2 for now and revert the timeout changes IMO.
Great job digging into this.  I'm also interested in getting this sensor working.  Mine seems to get stuck and doesn't want to do anything.
I bought one of these motion sensors recently, and it has similarly been getting stuck on motion detected and refuses to clear until I remove and re-pair with ZHA. 
Yeah… wonder if there is some way to solve this or if it’s just their firmware.  I do see there was solutions over on Hubitat forums but not sure what they ended up doing to make it work.

From: krazos ***@***.***>
Reply-To: zigpy/zha-device-handlers ***@***.***>
Date: Wednesday, February 2, 2022 at 10:16 AM
To: zigpy/zha-device-handlers ***@***.***>
Cc: jfrux ***@***.***>, Comment ***@***.***>
Subject: Re: [zigpy/zha-device-handlers] [Device Support Request] Linkind ZB-MotionSensor-D0003 (Issue #1291)


I bought one of these motion sensors recently, and it has similarly been getting stuck on motion detected and refuses to clear until I remove and re-pair with ZHA.

—
Reply to this email directly, view it on GitHub<https://github.com/zigpy/zha-device-handlers/issues/1291#issuecomment-1028044408>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AABJYRJYBMCE3XCZ2U6XKV3UZFDD7ANCNFSM5MDKBDTQ>.
You are receiving this because you commented.Message ID: ***@***.***>

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Is there any resolution to this issue as yet? I just paired 3 of these motion sensors with ZHA yesterday after a long time running Zigbee2MQTT. Immediately they detected motion they stuck on detected and did not clear without a full delete and repair - only to do it again immediately. They work fine in Zigbee2MQTT. Currently running HA 2022.7.7, which I assume has a reasonably up to date ZHA 
I would also be genuinely interested in a solution. 
I am **currently trying to learn** how to **write quirks properly**, but this one was maybe a little hard for the beginning 👯 

What I have done so far (for 8 Hours until now):

### → Created a quirk that matches the device and gets applied.
```
"""Linkind ZB-MotionSensor-D0003."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
    Basic,
    Identify,
    Ota,
    PollControl,
    PowerConfiguration,
)
from zigpy.zcl.clusters.homeautomation import Diagnostic
from zigpy.zcl.clusters.security import IasZone

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
    SKIP_CONFIGURATION,
)
from zhaquirks.linkind import LinkindBasicCluster

LINKIND_CLUSTER_ID = 0xFC81

class LinkindD0003(CustomDevice):
    """Linkind ZB-MotionSensor-D0003."""

    signature = {
        MODELS_INFO: [("lk", "ZB-MotionSensor-D0003")],
        # <SimpleDescriptor endpoint=1 profile=260 device_type=1026
        # device_version=1 
        # input_clusters=[0, 1, 3, 32, 1280, 2821, 64641]
        # output_clusters=[25]>
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    PollControl.cluster_id,
                    IasZone.cluster_id,
                    Diagnostic.cluster_id,
                    LINKIND_CLUSTER_ID,
                ],
                OUTPUT_CLUSTERS: [Ota.cluster_id],
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    LinkindBasicCluster,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    PollControl.cluster_id,
                    IasZone.cluster_id,
                    Diagnostic.cluster_id,
                    LINKIND_CLUSTER_ID,
                ],
                OUTPUT_CLUSTERS: [Ota.cluster_id],
            }
        },
    }
```

One thing in this quirk might be messed up, I guess:
- The Manufacturer-Specific cluster was written by me, like I saw it on some Aqara devices (no idea if this is right). But as far as I know, there is no way around defining this cluster because otherwise ZHA wouldn't apply this quirk (Cluster-Missmatch)
- But anyway, it is applied when joining the device:
<img width="1022" alt="Google Chrome - Einstellungen – Home Assistant_2023-01-24_19 21 11@2x" src="https://user-images.githubusercontent.com/62359912/214375862-0c4c97f0-acf9-425f-979c-8a2ddd39ea85.png">


### What I don't know how to do: How to get the Occupancy Sensor working?

For my understanding, the [IasZone Cluster](https://github.com/zigpy/zigpy/blob/b94cfe12903b21ed146e556c1e514e2abc16611f/zigpy/zcl/clusters/security.py#L41) should handle the "Strings" inside the ZoneStatus. But as it seems, this is not happening properly. (I have the same issue, the Occupancy is and will stay as "detected")

So now I am a little confused.
- Shouldn't this be handled by the IasZone or is it normal that this doesn't work out of the box? (For the strings inside the ZoneStatus, see the [initial issue](https://github.com/zigpy/zha-device-handlers/issues/1291#issue-1105212201))
- Is it because this device uses inside ZoneStatus Alarm_2 as "Dark-Sensor" and Alarm_1 as "Motion-Sensor"? (Might be quite unusual)
- Do we somehow need to modify (if possible) the way IasZone interprets these "strings"?
- Will we need a custom attribute mapping with a kind of lambda handler, like for [some Tuya devices](https://github.com/zigpy/zha-device-handlers/issues/1599#issuecomment-1219634462)? (And if yes, how to establish a DPToAttributeMapping without the TuyaDPType?)

Could someone point me in the right direction or link up an example-quirks? I wouldn't normally do this, but maybe 
@javicalle has some advice or tips to give? 

Additional Reference (Z2M Converter): https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/devices/linkind.js#L113
Perhaps one additional Question, regarding the Z2M Converter: If I get this correctly, the Method used to get the readings from the sensor (which works perfectly in Z2M) is [this one](https://github.com/Koenkk/zigbee-herdsman-converters/blob/d8913308b6acf7ca1a5d03eacd8b9b39a7a14984/converters/fromZigbee.js#L1068). Is there a "method" like this in ZHA which could be used to read the sensor?

Maybe I am completely on the wrong trail with my questions and ideas here, everything is possible when learning something new 😁

Thanks to everyone who is trying to help 🙏 & please excuse the many questions 🤓



<details>
  <summary>My Diagnostics for the device</summary>
  
  ```
{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.1.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.7",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Berlin",
    "os_name": "Linux",
    "os_version": "5.15.76-v8",
    "supervisor": "2022.12.1",
    "host_os": "Home Assistant OS 9.4",
    "docker_version": "20.10.19",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {},
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "config_flow": true,
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "requirements": [
      "bellows==0.34.6",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.90",
      "zigpy-deconz==0.19.2",
      "zigpy==0.53.0",
      "zigpy-xbee==0.16.2",
      "zigpy-zigate==0.10.3",
      "zigpy-znp==0.9.2"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "1A86",
        "pid": "55D4",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus v2"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "0403",
        "pid": "6015",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate+"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      },
      {
        "type": "_zigate-zigbee-gateway._tcp.local.",
        "name": "*zigate*"
      },
      {
        "type": "_zigstar_gw._tcp.local.",
        "name": "*zigstar*"
      },
      {
        "type": "_slzb-06._tcp.local.",
        "name": "slzb-06*"
      }
    ],
    "dependencies": [
      "file_upload"
    ],
    "after_dependencies": [
      "onboarding",
      "usb",
      "zeroconf"
    ],
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 24133,
    "manufacturer": "lk",
    "model": "ZB-MotionSensor-D0003",
    "name": "lk ZB-MotionSensor-D0003",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4456,
    "power_source": "Battery or Unknown",
    "lqi": 126,
    "rssi": null,
    "last_seen": "2023-01-24T16:06:48",
    "available": true,
    "device_type": "EndDevice",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4456, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": 260,
          "device_type": "0x0402",
          "in_clusters": [
            "0x0000",
            "0x0001",
            "0x0003",
            "0x0020",
            "0x0500",
            "0x0b05",
            "0xfc81"
          ],
          "out_clusters": [
            "0x0019"
          ]
        }
      }
    },
    "active_coordinator": false,
    "entities": [
      {
        "entity_id": "binary_sensor.lk_zb_motionsensor_d0003_iaszone",
        "name": "lk ZB-MotionSensor-D0003"
      },
      {
        "entity_id": "button.lk_zb_motionsensor_d0003_identify",
        "name": "lk ZB-MotionSensor-D0003"
      },
      {
        "entity_id": "sensor.lk_zb_motionsensor_d0003_battery",
        "name": "lk ZB-MotionSensor-D0003"
      }
    ],
    "neighbors": [],
    "routes": [],
    "endpoint_names": [
      {
        "name": "IAS_ZONE"
      }
    ],
    "user_given_name": null,
    "device_reg_id": "4920654c5d5f2a7058834d9c24cedd6d",
    "area_id": "schlafzimmer",
    "cluster_details": {
      "1": {
        "device_type": {
          "name": "IAS_ZONE",
          "id": 1026
        },
        "profile_id": 260,
        "in_clusters": {
          "0x0000": {
            "endpoint_attribute": "basic",
            "attributes": {
              "0x0004": {
                "attribute_name": "manufacturer",
                "value": "lk"
              },
              "0x0005": {
                "attribute_name": "model",
                "value": "ZB-MotionSensor-D0003"
              }
            },
            "unsupported_attributes": {}
          },
          "0x0001": {
            "endpoint_attribute": "power",
            "attributes": {
              "0x0020": {
                "attribute_name": "battery_voltage",
                "value": 29
              },
              "0x0021": {
                "attribute_name": "battery_percentage_remaining",
                "value": 196
              },
              "0x0031": {
                "attribute_name": "battery_size",
                "value": 2
              },
              "0x0033": {
                "attribute_name": "battery_quantity",
                "value": 1
              }
            },
            "unsupported_attributes": {}
          },
          "0x0003": {
            "endpoint_attribute": "identify",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0020": {
            "endpoint_attribute": "poll_control",
            "attributes": {
              "0x0000": {
                "attribute_name": "checkin_interval",
                "value": 13200
              }
            },
            "unsupported_attributes": {}
          },
          "0x0500": {
            "endpoint_attribute": "ias_zone",
            "attributes": {
              "0x0000": {
                "attribute_name": "zone_state",
                "value": 1
              },
              "0x0001": {
                "attribute_name": "zone_type",
                "value": 13
              },
              "0x0002": {
                "attribute_name": "zone_status",
                "value": 48
              },
              "0x0010": {
                "attribute_name": "cie_addr",
                "value": [
                  132,
                  69,
                  183,
                  38,
                  0,
                  75,
                  18,
                  0
                ]
              }
            },
            "unsupported_attributes": {}
          },
          "0x0b05": {
            "endpoint_attribute": "diagnostic",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0xfc81": {
            "endpoint_attribute": "manufacturer_specific",
            "attributes": {},
            "unsupported_attributes": {}
          }
        },
        "out_clusters": {
          "0x0019": {
            "endpoint_attribute": "ota",
            "attributes": {},
            "unsupported_attributes": {}
          }
        }
      }
    }
  }
}
  ```
  
</details>
IMHO the `IasZone` needs a proper way to manage the 'extra' status:
* https://github.com/home-assistant/core/issues/72828

What I would suggest to you here will be:
* import the `MotionWithReset` class
```python
from zhaquirks import MotionWithReset
```
* use it in the replacement part:
```python
    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    LinkindBasicCluster,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    PollControl.cluster_id,
                    MotionWithReset,
                    Diagnostic.cluster_id,
                    LINKIND_CLUSTER_ID,
                ],
                OUTPUT_CLUSTERS: [Ota.cluster_id],
            }
        },
    }
```

This class will reset the sensor status at 30 seconds (if no movement detected).
If not working you can implement a custom cluster to do the same.
I can't believe it, **seems to work** 💙
![Google Chrome - Einstellungen – Home Assistant_2023-01-25_00 25 20@2x](https://user-images.githubusercontent.com/62359912/214443490-f2907564-53b0-47e2-bc03-e95f45619d68.png)

It would be great if someone else verified the current state for a pull request. Even though I might end up creating a custom cluster for this (see below)... But if considered working, I would see this maybe as a basic Version for getting support in ZHA. 👇

<details>
  <summary>Current quirk</summary>
  
  ```
"""Linkind ZB-MotionSensor-D0003."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
    Basic,
    Identify,
    Ota,
    PollControl,
    PowerConfiguration,
)
from zigpy.zcl.clusters.homeautomation import Diagnostic
from zigpy.zcl.clusters.security import IasZone

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.linkind import LinkindBasicCluster
from zhaquirks import MotionWithReset

LINKIND_CLUSTER_ID = 0xFC81

class LinkindD0003(CustomDevice):
    """Linkind ZB-MotionSensor-D0003."""

    signature = {
        MODELS_INFO: [("lk", "ZB-MotionSensor-D0003")],
        # <SimpleDescriptor endpoint=1 profile=260 device_type=1026
        # device_version=1 
        # input_clusters=[0, 1, 3, 32, 1280, 2821, 64641]
        # output_clusters=[25]>
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    PollControl.cluster_id,
                    IasZone.cluster_id,
                    Diagnostic.cluster_id,
                    LINKIND_CLUSTER_ID,
                ],
                OUTPUT_CLUSTERS: [Ota.cluster_id],
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    LinkindBasicCluster,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    PollControl.cluster_id,
                    MotionWithReset,
                    Diagnostic.cluster_id,
                    LINKIND_CLUSTER_ID,
                ],
                OUTPUT_CLUSTERS: [Ota.cluster_id],
            }
        },
    }
  ```
  
</details>

So, just to get my Head around this: The MotionWithReset is basically taking the IasZone.cluster_id and interpreting the Return values differently (I remember the Translation example from the GitHub-Page)?

Thank you so much @javicalle  🙏
And 2 additional questions (So we even might beat Z2M's attributes):  

1. In Z2M there is also a Tamper "Entity". Is there a way to "extract" this too? (I guess this would need a custom cluster, right?)

~~2. To set the timeout to 2 Minutes (if I remember this correct, this is the default Reporting-Interval for the linkind), something like this would be required?~~
```
class MotionCluster(MotionWithReset):
    """Motion cluster."""

    reset_s: int = 120
    send_occupancy_event: bool = True
```
~~(And afterward of course using MotionCluster instead of MotionWithReset in replacement part)~~
Edit: Not necessary, forget about it 😅

3. There is a Cluster which says, "current_zone_sensitivity_level". Would it be possible to set these values to? If I recall correctly, I saw some Tuya quirks defining an enum where values like 0=low 1=med... were defined. This would require a custom cluster, right?

I'm glad that you get it working.

> The MotionWithReset is basically taking the IasZone.cluster_id and interpreting the Return values differently (I remember the Translation example from the GitHub-Page)?

No. What is doing is starting a counter every time that a status report is recieved:
https://github.com/zigpy/zha-device-handlers/blob/d0732016c78c12b4f28930ea6affd385140af44e/zhaquirks/__init__.py#L267-L270

The counter (at `reset_s` seconds) will 'clear' the `IasZone` status (and trigger an event):
https://github.com/zigpy/zha-device-handlers/blob/d0732016c78c12b4f28930ea6affd385140af44e/zhaquirks/__init__.py#L242-L246

About your questions:

> 1. In Z2M there is also a Tamper "Entity". Is there a way to "extract" this too?

IMHO that is a discussion for the ZHA integration and not for the quirk side.

Currently the `ZoneStatus` can report a bunch of events/status:
https://github.com/zigpy/zigpy/blob/297a2b0f364fe7a31de3b4966d70d1a67d432358/zigpy/zcl/clusters/security.py#L41-L54

In ZHA, only the `Alarm_1` and `Alarm_2` are considerated.
I see 2 approachs here:
* that the `IasZone` sensor becomes a multi-state sensor and exposes all possible values
* that new sensors be implemented for the rest of the status (`IasTamper`, `IasBattery`, ...)

The first approach is less friendly to manage and in automatizations.
The second one have the problem that there is no way to know which status will report any device. Then what to do? Create all the entities for all the status? Just a few? Create in disabled mode?
In Z2M has been addressed in their own way and ZHA must do theirs.

> 3\. There is a Cluster which says, "current_zone_sensitivity_level". Would it be possible to set these values to? If I recall correctly, I saw some Tuya quirks defining an enum where values like 0=low 1=med... were defined. This would require a custom cluster, right?

IMHO the goal of any quirk is to fix any functionality of the device that does not work due to a bad implementation of the zigbee standard. Period.
That is a clear example: the device reports the IasZone status but device is not usefull because doesn't restore the 'clear' status. A quirk to the rescue.
Does the device reports/implements any 'sensitivity level'? If it does and isn't working, I would try to fix it. But if the device doesn't implements it, IMHO we should not try to implement it programmatically (or at least add it to the library).


Thank you so much @javicalle and the time you put in your answer 💙

That really helped me out understanding how to approach it the ZHA way and gave me the possibility to take a look at some Motion-Quirks which were already created (and understand them better).

Do you have a PayPal-Link where I cloud give you a little something for the time you took explaining this stuff to me? (And for some questions I might have in the future 😁)
I'm glad to have been helpful.
Can you create the PR with the working code?

> Do you have a PayPal-Link where I cloud give you a little something for the time you took explaining this stuff to me?

I appreciate the offer but I don't have.
@dmulcahey, are there any tip/coffee/beer jar for this offerings or donations? 

Resolving patch:
diff --git a/zhaquirks/linkind/motion.py b/zhaquirks/linkind/motion.py
--- a/zhaquirks/linkind/motion.py
+++ b/zhaquirks/linkind/motion.py
@@ -1,6 +1,6 @@
 """Linkind Motion Sensors."""
 from zigpy.profiles import zha
-from zigpy.quirks import CustomDevice
+from zigpy.quirks import CustomCluster, CustomDevice
 from zigpy.zcl.clusters.general import (
     Basic,
     Identify,
@@ -11,7 +11,6 @@
 from zigpy.zcl.clusters.homeautomation import Diagnostic
 from zigpy.zcl.clusters.security import IasZone
 
-from zhaquirks import MotionWithReset
 from zhaquirks.const import (
     DEVICE_TYPE,
     ENDPOINTS,
@@ -25,10 +24,18 @@
 LINKIND_CLUSTER_ID = 0xFC81
 
 
-class MotionClusterLinkind(MotionWithReset):
-    """Motion cluster."""
+class IasZoneLinkind(CustomCluster, IasZone):
+    """IasZone cluster for Linkind devices that ignores Alarm_2.
 
-    reset_s: int = 60
+    The sensor uses Alarm_1 for motion and Alarm_2 for brightness. Tamper is apparently also provided by the tamper bit.
+    As ZHA only needs either Alarm_1 or Alarm_2 to activate the motion entity, we need to ignore Alarm_2 for now.
+    """
+
+    def _update_attribute(self, attrid, value):
+        if attrid == IasZone.AttributeDefs.zone_status.id:
+            # always set Alarm_2 bit to 0
+            value = value & ~IasZone.ZoneStatus.Alarm_2
+        super()._update_attribute(attrid, value)
 
 
 class LinkindD0003(CustomDevice):
@@ -68,7 +75,7 @@ class LinkindD0003(CustomDevice):
                     PowerConfiguration.cluster_id,
                     Identify.cluster_id,
                     PollControl.cluster_id,
-                    MotionClusterLinkind,
+                    IasZoneLinkind,
                     Diagnostic.cluster_id,
                     LINKIND_CLUSTER_ID,
                 ],


Test patch:
diff --git a/tests/test_linkind.py b/tests/test_linkind.py
new file mode 100644
--- /dev/null
+++ b/tests/test_linkind.py
@@ -0,0 +1,38 @@
+import pytest
+from zigpy.zcl.clusters.security import IasZone
+
+import zhaquirks
+
+from tests.common import ClusterListener
+
+zhaquirks.setup()
+
+
+@pytest.mark.parametrize("quirk", (zhaquirks.linkind.motion.LinkindD0003,))
+async def test_linkind_motion_ignore_alarm_2(zigpy_device_from_quirk, quirk):
+    """Test that the quirk for the Linkind motion sensor ignores the IasZone Alarm_2 bit."""
+    device = zigpy_device_from_quirk(quirk)
+
+    ias_zone_cluster = device.endpoints[1].ias_zone
+    ias_zone_listener = ClusterListener(ias_zone_cluster)
+    ias_zone_status_attr_id = IasZone.AttributeDefs.zone_status.id
+
+    # ZHA calls update_attribute on the IasZone cluster when it receives a status_change_notification
+    ias_zone_cluster.update_attribute(
+        ias_zone_status_attr_id, IasZone.ZoneStatus.Alarm_2
+    )
+
+    # verify Alarm_2 bit was set to 0
+    assert len(ias_zone_listener.attribute_updates) == 1
+    assert ias_zone_listener.attribute_updates[0][0] == ias_zone_status_attr_id
+    assert ias_zone_listener.attribute_updates[0][1] == 0
+
+    # call again with Alarm_1
+    ias_zone_cluster.update_attribute(
+        ias_zone_status_attr_id, IasZone.ZoneStatus.Alarm_1
+    )
+
+    # verify Alarm_1 was not ignored
+    assert len(ias_zone_listener.attribute_updates) == 2
+    assert ias_zone_listener.attribute_updates[1][0] == ias_zone_status_attr_id
+    assert ias_zone_listener.attribute_updates[1][1] == IasZone.ZoneStatus.Alarm_1