How to setup local ZHA quirks

I already tried this, but did not see the x, y, z values. In any case, I just tried listening to zha_event, and can see the X, Y, Z data. Now I can write an automation based on it thanks to your links above!

1 Like

Hi,

For anyone thatā€™s following this thread. I had to add the database path to in order to actually load the quirks. I added:

zha:
  database_path: /config/zigbee.db 
  enable_quirks: true
  custom_quirks_path: /config/zhaquirks
3 Likes

Update: submitted new how-to guide for adding custom quirks to ZHA to the ZHA Device Handlers repo:

Hi,

Iā€™ve been trying to add a custom quirk for the TuYa Pir Motion and Illuminance sensors I bought, because ZHA recognizes some of the sensors as a smoke alarm and after initializing doesnā€™t receive any update from the sensor: it just states ā€œclearā€.

So I followed the steps as described above and in some other topics (thanks @Hedda for the detailed description):

  1. added to configuration.yaml:
zha: 
  database_path: /config/zigbee.db 
  enable_quirks: true
  custom_quirks_path: /config/zha_quirks/
  1. added a folder ā€œzha_quirksā€ to ā€œconfigā€
  2. downloaded the .py-file from here and put that in the new folder
  3. deleted the device from ZHA
  4. restarted HA
  5. put the device in discovery mode
  6. added a new device in ZHA

The device was then initialized and added. But it still doesnā€™t work. If I download diagnostics, it states halfway:

"data": {
    "ieee": "**REDACTED**",
    "nwk": 19146,
    "manufacturer": "_TZE200_3towulqd",
    "model": "TS0601",
    "name": "_TZE200_3towulqd TS0601",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4417,
    "power_source": "Battery or Unknown",
    "lqi": 248,
    "rssi": -38,
    "last_seen": "2023-04-23T21:05:05",
    "available": true,
    "device_type": "EndDevice",

It seems like ZHA doesnā€™t recognises it should use the installed quirk. The manufacturer and model are the same as described in the quirk:

class PirMotion(CustomDevice):
    """Tuya PIR motion sensor."""

    signature = {
        MODELS_INFO: [("_TZE200_3towulqd", "TS0601")],
        ENDPOINTS: {
            # endpoints=1 profile=260 device_type=0x0402
            # in_clusters=[0x0000, 0x0001, 0x0500],
            # out_clusters=[0x000a, 0x0019]
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    TuyaPowerConfigurationCluster.cluster_id,
                    IasZone.cluster_id,
                ],
                OUTPUT_CLUSTERS: [
                    Time.cluster_id,
                    Ota.cluster_id,
                ],
            }
        },
    }

My question: am I overlooking something here?

Iā€™ll copy the start of the diagnostics file also in, so my installation details are also provided:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.4.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.10",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Amsterdam",
    "os_name": "Linux",
    "os_version": "5.15.84-v8",
    "supervisor": "2023.04.0",
    "host_os": "Home Assistant OS 9.5",
    "docker_version": "20.10.22",
    "chassis": "embedded",
    "run_as_root": true
  },

...some custom components mentioned here...

  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "after_dependencies": [
      "onboarding",
      "usb"
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "config_flow": true,
    "dependencies": [
      "file_upload"
    ],
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "requirements": [
      "bellows==0.35.1",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.97",
      "zigpy-deconz==0.20.0",
      "zigpy==0.54.1",
      "zigpy-xbee==0.17.0",
      "zigpy-zigate==0.10.3",
      "zigpy-znp==0.10.0"
    ],

Suggest post your details to that issue ā†’ https://github.com/zigpy/zha-device-handlers/issues/1599

Thanks! I hadnā€™t seen that thread and found the improved quirk further down the conversation. I updated the quirk on my system and now it works like a charm!

For reference, the working quirk can be found in this post ā†’ _TZE200_3towulqd TS0601 Tuya Motion Sensor with illuminance sensor Ā· Issue #1599 Ā· zigpy/zha-device-handlers Ā· GitHub

How do you manage to solve the problem ?
I think also that it used the quirk from the library and not the custom one.
I used the last py file posted in the the issue _TZE200_3towulqd TS0601 Tuya Motion Sensor with illuminance sensor Ā· Issue #1599 Ā· zigpy/zha-device-handlers Ā· GitHub
Thank you for your help

Iā€™m also interested in solving his issue as I am bumping into the same.

Following the instructions did not work. I am not seeing the new quirk name showing under the device, despite re-pairing, restarting, etc.

Post new issue to ZHA Device Handlers for your device signature ID if there is not already one ā†’ https://www.home-assistant.io/integrations/zha#how-to-add-support-for-new-and-unsupported-devices

Iā€™m silly. The quirk I was using was not for my device :sweat_smile:

New comment

Can anybody help?

FYI, posted an updated version the the community guide section here ā†’ Zigbee Guide: How-to setup local custom device handler quirks in ZHA integration

2 Likes

@cckp database_path was the missing piece for me. Thanks for posting!

HI,

sorry for it but I0m tring for the first time to add a quirk in my HA os but when I chek the configuraiton I get the following error:
ā€œInvalid config for ā€˜zhaā€™ at configuration.yaml, line 18: not a directory for dictionary value ā€˜zha->custom_quirks_pathā€™, got ā€˜config/zha_quirks/ā€™ā€

What I havent foudn a folder Custom therfore I created a new folder under the directory Homeassistant. I put the PY file there and then in configuration. yaml I inserted your code. but then I get the error. I customized youā€™re code replacing the folder config whit the folder name Homeassistant but nothing.

Iā€™m sure is a stupid thing but would be great a little support :slight_smile:

There is a step-by-step guide here that is probably a little easier to follow:

https://community.home-assistant.io/t/zigbee-guide-how-to-setup-local-custom-device-handler-quirks-in-zha-integration/683473

Also see here for an shorter/simpler less-detailed summerized guide:

Thank yoo for your answer!

Probably Iā€™m making a mystake with the folder. I need to teel you that I0m not a programmer soā€¦ :smiley:

Becouse Iā€™m utilizing Home assistant OS just wiorking with File editor in HA I0m not sure if Iā€™m utilizing the right folder.

In file editor Iā€™m always in the folder HomeAssistant. There I created the new folder for the Quirks.

Therfore I tought to utiize the following code:

Preformatted text database_path: /HomeAssistant/zigbee.db >> #I have Zigbee.db file in the Home assistant folder
enable_quirks: true
custom_quirks_path: /HomeAssistant/zha_quirks/ #where ZHA_quirks is the name of new folder where put the Quirk`

Iā€™m operating right?

Thank you so much!