ZHA quirk for Huacaoe TYZGTH1CH-B1RF (Zigbee temperature sensor)

I got this cheap Zigbee temperature sensor from Amazon, and I managed to get it working with a modified quirk, so I’m sharing my info on it here.

Huacaoe TYZGTH1CH-B1RF

I discovered that with my Home Assistant ZHA setup, I could only control the switch function, but not get the temperature information. It didn’t quite work with the TS000F_TZ3218_7fiyo3kv.py quirk that was recommended for it, but with some help from AI, I managed to get it working. So I’m just sharing it here in case it’s helpful for someone. I haven’t taken the time to understand exactly how it works, so I’m mostly trusting the AI on this one, but it seems to work well. For general info on how to install a quirk, see Add a how-to guide for how end-users can use a custom quirk in ZHA by Hedda · Pull Request #2419 · zigpy/zha-device-handlers · GitHub.

"""Huacaoe TYZGTH1CH-B1RF On/Off Switches with Thermometer support for Home Assistant with ZHA. Originally based on the quirk tuya TS000F _TZ3218_7fiyo3kv from klibro. """

from zigpy.profiles import zgp, zha
from zigpy.zcl.clusters.general import (
    Basic,
    GreenPowerProxy,
    Groups,
    Identify,
    OnOff,
    Ota,
    Scenes,
    Time,
)
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.zcl.clusters.measurement import TemperatureMeasurement

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODEL,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)

from zhaquirks.tuya import (
    EnchantedDevice,
    TuyaZBE000Cluster,
    TuyaZBOnOffAttributeCluster,
    TuyaLocalCluster,
    TuyaZBExternalSwitchTypeCluster,
)
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster


class TuyaTemperatureMeasurement(TemperatureMeasurement, TuyaLocalCluster):
    """Tuya local TemperatureMeasurement cluster."""

class TemperatureHumidityManufCluster(TuyaMCUCluster):
    """Tuya Manufacturer Cluster with Temperature and Humidity data points."""

    # Try all plausible Tuya dp numbers seen in logs/users
    dp_to_attribute: dict[int, DPToAttributeMapping] = {
        102: DPToAttributeMapping(
            TuyaTemperatureMeasurement.ep_attribute,
            "measured_value",
            converter=lambda x: x * 10,  # decidegree to centidegree
        ),
        115: DPToAttributeMapping(
            TuyaTemperatureMeasurement.ep_attribute,
            "measured_value",
            converter=lambda x: x * 10,
        ),
        123: DPToAttributeMapping(
            TuyaTemperatureMeasurement.ep_attribute,
            "measured_value",
            converter=lambda x: x * 10,
        ),
    }

    data_point_handlers = {
        102: "_dp_2_attr_update",
        115: "_dp_2_attr_update",
        123: "_dp_2_attr_update",
    }


class Tuya_1G_Switch_Temperature(EnchantedDevice):
    """Tuya 1 gang switch with temperature measurement."""

    signature = {
        MODEL: "TS000F",
        MODELS_INFO: [
            ("_TZ3218_b1rf", "TS000F"),  # Add your Huacaoe device
            ("_TZ3218_7fiyo3kv", "TS000F"),  # Keep original for future
        ],
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    TuyaZBE000Cluster.cluster_id,
                    TuyaZBExternalSwitchTypeCluster.cluster_id,
                    TemperatureHumidityManufCluster.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            242: {
                PROFILE_ID: zgp.PROFILE_ID,
                DEVICE_TYPE: zgp.DeviceType.PROXY_BASIC,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
            },
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    TuyaZBOnOffAttributeCluster,
                    TuyaZBE000Cluster,
                    TuyaZBExternalSwitchTypeCluster,
                    TemperatureHumidityManufCluster,
                    TuyaTemperatureMeasurement,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            242: {
                PROFILE_ID: zgp.PROFILE_ID,
                DEVICE_TYPE: zgp.DeviceType.PROXY_BASIC,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
            },
        },
    }
1 Like

Thank you. It works in Zigbee Home Automation.