Dear all,
I am really happy to share my first quirk success with the community. :-)
It was not so easy, I have programming knowledge but undertanding how a quirk based on zigpy works, that wasn't so easy because of the lack of documentation on internet.
For several weeks I bought the following motion sensor, but I couldn't do anything with it as ZHA does not support it yet:
GIRIER Tuya ZigBee PIR with illuminance
https://fr.aliexpress.com/item/1005007059504735.html?spm=a2g0o.order_list.order_list_main.9.6fb65e5bivBJW1&gatewayAdapt=glo2fra

The device is known under "TS0601 by _TZE200_f1pvdgoh".
Here are the identified tuya data points:
PIR State = 0x01
Battery level = 0x04
Illuminance value = 0x101
Charge State = 0x102
And here is the quirk:
"""Tuya TS0601 occupancy & illuminance sensors"""
from zigpy.quirks.v2 import EntityPlatform
from zigpy.types import t
from zhaquirks.tuya.builder import TuyaQuirkBuilder
from zigpy.zcl.clusters.measurement import OccupancySensing
from zhaquirks.tuya import TuyaLocalCluster
class TuyaOccupancySensing(OccupancySensing, TuyaLocalCluster):
"""Tuya local OccupancySensing cluster."""
class PirState(t.enum8):
"""Pir state"""
pir = 0x00
none = 0x01
@staticmethod
def to_occupancy(x):
""" Map PIR state to occupancy enum. Actually the PirState is Occupancy inverted."""
if x == PirState.pir:
return OccupancySensing.Occupancy.Occupied
return OccupancySensing.Occupancy.Unoccupied
(
TuyaQuirkBuilder("_TZE200_f1pvdgoh", "TS0601")
.tuya_dp(
dp_id=1,
ep_attribute=TuyaOccupancySensing.ep_attribute,
attribute_name=OccupancySensing.AttributeDefs.occupancy.name,
converter=PirState.to_occupancy,
)
.adds(TuyaOccupancySensing)
.tuya_illuminance(dp_id=101)
.tuya_battery(dp_id=4)
.add_to_registry()
)
This quirk gives the following result:

I hope I could help some of you that were in the same case.
Enjoy your motion sensor ;-)
What did help?:
https://gist.github.com/vinzent/2194a8ef531d8e8ec3bc17ea17eab0e9
https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/tuya_motion.py
https://github.com/zigpy/zigpy/blob/dev/zigpy/zcl/clusters/measurement.py
https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/builder/__init__.py
Dear all,
I am really happy to share my first quirk success with the community. :-)
It was not so easy, I have programming knowledge but undertanding how a quirk based on zigpy works, that wasn't so easy because of the lack of documentation on internet.
For several weeks I bought the following motion sensor, but I couldn't do anything with it as ZHA does not support it yet:
GIRIER Tuya ZigBee PIR with illuminance
https://fr.aliexpress.com/item/1005007059504735.html?spm=a2g0o.order_list.order_list_main.9.6fb65e5bivBJW1&gatewayAdapt=glo2fra
The device is known under "TS0601 by _TZE200_f1pvdgoh".
Here are the identified tuya data points:
PIR State = 0x01
Battery level = 0x04
Illuminance value = 0x101
Charge State = 0x102
And here is the quirk:
This quirk gives the following result:
I hope I could help some of you that were in the same case.
Enjoy your motion sensor ;-)
What did help?:
https://gist.github.com/vinzent/2194a8ef531d8e8ec3bc17ea17eab0e9
https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/tuya_motion.py
https://github.com/zigpy/zigpy/blob/dev/zigpy/zcl/clusters/measurement.py
https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/builder/__init__.py