ZHA Quirks

1.1.1 · active · verified Thu Apr 16

ZHA Quirks is a Python library implementing custom Zigpy device handlers (quirks) for the ZHA (Zigbee Home Automation) integration in Home Assistant. It provides support for many Zigbee devices that do not fully conform to the Zigbee Alliance specifications, allowing them to function correctly within Home Assistant. As of version 1.1.1, it continues to expand its device support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the structure for creating a custom ZHA quirk, which is the primary way developers interact with this library's capabilities. This Python code defines a device quirk class that Home Assistant's ZHA integration (via `zigpy`) can automatically discover and load. The code itself is not meant to be run standalone to 'do' something directly, but rather to be integrated into a Home Assistant setup as a module. Replace `MyManufacturer`, `MyTempSensor`, and cluster definitions with your device's actual signature and desired behavior.

import logging
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, Device
from zigpy.zcl.clusters.general import Basic, Identify
from zigpy.zcl.clusters.measurement import TemperatureMeasurement

_LOGGER = logging.getLogger(__name__)

class MyCustomTemperatureCluster(CustomCluster, TemperatureMeasurement):
    cluster_id = TemperatureMeasurement.cluster_id
    # Add any specific attributes or commands for this custom cluster if necessary

class MyCustomDeviceQuirk(Device):
    """Custom quirk for a hypothetical MyManufacturer Temp Sensor."""

    signature = {
        # The 'signature' must exactly match the device's reported model_id and manufacturer.
        # This determines if the quirk is applied to a discovered device.
        "model_id": "MyTempSensor",
        "manufacturer": "MyManufacturer",
        # Endpoint configuration is defined in 'replacement', not directly in 'signature'.
    }

    replacement = {
        1: zha.Endpoint(
            profile_id=zha.PROFILE_ID,
            device_type=zha.DeviceType.TEMPERATURE_SENSOR,
            input_clusters=[
                Basic.cluster_id,
                MyCustomTemperatureCluster, # Use your custom cluster or a standard one
                Identify.cluster_id,
            ],
            output_clusters=[]
        )
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        _LOGGER.info(f"MyCustomDeviceQuirk detected: {self.model_id} from {self.manufacturer}")

# To make this quirk functional within Home Assistant's ZHA integration:
# 1. Save this code as a .py file (e.g., `my_custom_sensor.py`) in a dedicated directory, 
#    for example, `/config/custom_zha_quirks/` within your Home Assistant configuration.
# 2. Add the following to your Home Assistant `configuration.yaml`:
#    `zha: 
#      custom_quirks_path: /config/custom_zha_quirks/`
# 3. Restart Home Assistant.
# 4. If the device was previously paired, you might need to 'Reconfigure device' from its 
#    ZHA device page or, in some cases, remove and re-pair the device to apply the quirk.

# Replace `MyManufacturer`, `MyTempSensor`, and cluster definitions with your device's actual details.

view raw JSON →