Custom ZHA quirk for Tuya ZG-204ZL motion and illuminance sensor

I recently bought a Tuya 2 in 1 Zigbee Mini PIR Motion Detector +Bright Lux Light Passive Infrared Security Burglar Alarm Sensor only to find out that it currently isn’t supported by ZHA but it is supported by Zigbee2MQTT.

Here is the process for creating a custom quirk so that you can use it in ZHA (I used the Home Assistant File Editor addon to do all of this):

  1. Create a folder for your custom quirks (I created /config/zha_quirks/)
  2. Create a quirk/file in this directory (I followed the guide below and called it “ts0601_pirmotion.py”). This file should contain the quirk from this post - TZE200_3towulqd TS0601 Tuya Motion Sensor with illuminance sensor #1599 (comment)
  3. Add the following to your config.yaml
zha:
  custom_quirks_path: /config/zha_quirks/
  1. Restart Home Assistant
  2. Sensors for Illuminance and Occupancy should be added to your entity (you might need to re-add your device)
2 Likes

@thatguy_za Nice! Inspired me to submit a pull request about that to the ZHA documentation:

https://github.com/home-assistant/home-assistant.io/pull/23884

https://github.com/home-assistant/home-assistant.io/blob/89cbae7fa15f0e282be49a297369c52ab3736d3c/source/_integrations/zha.markdown

Amazing, thanks @Hedda !

Best is for anyone to try to contribute to the documentation is something is missing or not good enough:

https://github.com/home-assistant/home-assistant.io/blob/89cbae7fa15f0e282be49a297369c52ab3736d3c/source/_integrations/zha.markdown

Unfortunately, frenck think that a custom ZHA quirk is similar to a custom integration and would not accept a guide in ZHA documentation for how to add custom quirk device handler to ZHA :-1: :unamused:

https://github.com/home-assistant/home-assistant.io/pull/23884

Posted a related feature request → https://community.home-assistant.io/t/zha-ui-option-to-add-a-custom-quirk-zha-device-handder-via-home-assistant-frontend-gui/454168

Thank you @thatguy_za for the guide. For the quirk to work, do I use s0601_pirmotion.py the script as is or do I need to modify it. If I need to modify it, would you be able to give some guidance to that.

I have this same sensor, connected via zigbee2mqtt. However i am having trouble with it.
Sometimes it does not send any signal even when I put my hand over the sensor. It is as if sensor is asleep and it does not wake to send the signal.
Even the Illuminance sensor does not work well. In history, it shows steps, as if it did not refresh during long periods of time (random, between seconds and 5-10 minutes).
I have two sensors of this type and both have the same issue.
Has anyone experienced this issue with this sensor? Or is it needed any special configuration?

1 Like

Doesn’t really work. It triggers nonstop, seconds after the occupancy is detected, should not trigger the “not occupied” every time you move during the cooldown… it deffinetly does not work properly. Also, seems like it polls/triggers at kinda random times… sometimes seconds later other times minutes later… what a bummer… waste of money on this sensor…

1 Like

Same thing. I contacted the buyer and he reported back that this sensor is not fully compatible yet with Sonoff Zigbee Dongle Plus. I also flashed the latest sonoff firmware ~1 week ago, problem persists.

Again, please understand that a custom quirk is needed because Zigbee devices that do not only use standard configuration and parameters (default ZCL clusters and attributes) but instead also implement custom manufacturer clusters and attributes (also known as “quirks”) will need a custom handler/converter/parser/translator as Python script code in the upstream “ZHA Device Handlers” library repository to extend custom manufacturer device “quirk” support for specific non-standard ZCL clusters and attributes (which Zigbee gateway implementations that depends on zigpy and the ZHA Device Handlers library, like Home Assistant s ZHA integration, then can make use of).

https://github.com/zigpy/zha-device-handlers/#readme

If you can not code that Python script code yourself to write the needed custom handler/converter/parser/translator for adding that specific device to the “ZHA Device Handlers” repository/library then suggest submitting a “device support request” (with device signature and diagnostic information) as new issues → https://github.com/zigpy/zha-device-handlers/issues

See feature request example → https://github.com/zigpy/zha-device-handlers/issues/1599

Without a “device support request” as a new issue posted to the “ZHA Device Handlers” repository/library requesting support for an unsupported device or device feature with Device signature and Diagnostic information the ZHA integration developers will not even know about the device unless they by random chance happened to have bought it themselves.

The reason is why non-standard devices need a custom handler/converter/translator is explained in ZHA integration documentation here → https://www.home-assistant.io/integrations/zha#zha-exception-and-deviation-handling

Zigbee devices that use clusters and attributes that are standard in the official ZCL (Zigbee Cluster Library) do not need custom handlers/converters/translators as explained in the ZHA integration documentation here → https://www.home-assistant.io/integrations/zha#knowing-which-devices-are-supported

PS: Off-topic but FYI, this also works kind of similarly for Zigbee2MQTT which also requires a custom handlers/converters/parsers/translators for specific devices → https://www.zigbee2mqtt.io/advanced/support-new-devices/01_support_new_devices.html

it seemed that the sensor was faulty. I have tried with another one and it works ok. Motion sensor triggers immediately. However, light sensor has a very low refresh rate. it updates after minutes or when motion is detected. The only problem is that first motion is detected and 3s later light sensor is updated, so when I enter the room, it detects that there is still light and don’t turn on the lamp :weary:

I have had to make a complex automation for solving this issue. This is not the best sensor.

Hi, would you share the automation with us?

I have the automation in node red, not in HA.

The idea is:

When contact_sensor change to ON:
     if lux_sensor< min_value_of_lux (eg 150 lux) and light is OFF then
         turn_on light

When lux_sensor change to below min_value_of_lux (eg 150 lux):
   If contact_sensor is ON and light is OFF then
        turn_on light

When contact_sensor is OFF for 60s:
    If light is On then:
        turn_off light

This works. The only problem I have found is when you enter the room short after a lux increase (e.g. when you open blinds). Then this automation will turn on the light even if it is not needed.

1 Like

Hmm, picked up a few of these earlier in the year and just set one up in a low-traffic area for testing. Seems to be behaving as you describe, even though I’m running latest stable firmware on my sonoff dongle and using latest zigbee2mqtt.

The “last_seen” status updated frequently enough, and the connection is strong, but as you say even when the red LED blinks to denote motion detected this just doesn’t get passed along to zigbee2mqtt. Only sometimes. And the lux level in the past 2 days seems to only get updated very very periodically (eg at 2 in the morning, long after it has gotten dark).

Seems like these are for the bin.