How to setup local ZHA quirks

Binary sensors can also have attributes.
Take a look for this binary sensor (and perhaps any other entity within this device) under Developer tools > State and take a look for attributes. Maybe you have this info (X, Y, Z) there.

1 Like

thankyou so much, this is what I needed!

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!