zigpy / zha-device-handlers

ZHA device handlers bridge the functionality gap created when manufacturers deviate from the ZCL specification, handling deviations and exceptions by parsing custom messages to and from Zigbee devices.
Apache License 2.0
747 stars 682 forks source link

[Device Support Request] TS0601 _TZE204_vawy74yh Smoke detector #3421

Open Keffu3636 opened 1 week ago

Keffu3636 commented 1 week ago

Problem description

Please provide support for the device TS0601 _TZE204_vawy74yh

Solution description

Looks like it is working with Z2M - https://www.zigbee2mqtt.io/devices/ZSS-HM-SSD01.html

Screenshots/Video

Screenshots/Video [Paste/upload your media here]

Device signature

Device signature ```json [Paste the device signature here] ```

Diagnostic information

Diagnostic information ```json [Paste the diagnostic information here] ```

Logs

Logs ```python [Paste the logs here] ```

Custom quirk

Custom quirk ```python [Paste your custom quirk here] ```

Additional information

No response

Keffu3636 commented 1 week ago

Managed to patch something together and I'm getting attribute values now . Anyone with deeper knowledge please comment if I'm on the right track :) Thanks!

Sources used: https://github.com/Koenkk/zigbee-herdsman-converters/blob/b405404c2d8db02d94feb3a114c9baf2bd2fcf4e/src/devices/moes.ts#L400 and most of the code I took from here: https://github.com/zigpy/zha-device-handlers/issues/3249#issuecomment-2282969644 Many thanks to the authors.

import zigpy.types as t
from typing import Any, Type
from zigpy.profiles import zha 
from zigpy.quirks import CustomDevice, CustomCluster
from zigpy.zcl.clusters.general import (
    Basic,
    Groups,
    Identify,
    OnOff,
    Ota,
    PowerConfiguration,
    Scenes,
    Time,
)
from zigpy.zcl.clusters.security import IasZone
from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya.mcu import TuyaMCUCluster
from zhaquirks.tuya import (
    TuyaManufCluster,
    DPToAttributeMapping,
    EnchantedDevice,
    TuyaNoBindPowerConfigurationCluster,
)

ZONE_TYPE = 0x0001

class TuyaSmokeSensorCluster(TuyaMCUCluster):
    """Tuya manufacturer cluster for smoke sensor."""

    # Copy the attributes from the base class
    attributes = TuyaMCUCluster.attributes.copy()

    # Update the attributes with the custom ones for this smoke sensor
    attributes.update(
        {
            0xEF01: ("smoke", t.uint8_t, True),  # Smoke status
            0xEF09: ("self_test", t.uint8_t, True),  # Self-test result (Enum)
            0xEF0E: ("battery_state", t.uint8_t, True),  # Battery state (raw value)
            0xEF0F: ("battery", t.uint8_t, True),  # Battery level (raw value)
            0xEF10: ("silence", t.Bool, True),  # Silence alarm (On/Off)
        }
    )

    dp_to_attribute = {
        1: DPToAttributeMapping(
            TuyaMCUCluster.ep_attribute,
            "smoke",
        ),
        9: DPToAttributeMapping(
            TuyaMCUCluster.ep_attribute,
            "self_test",
        ),
        14: DPToAttributeMapping(
            TuyaMCUCluster.ep_attribute,
            "battery_state",
        ),
        15: DPToAttributeMapping(
            TuyaMCUCluster.ep_attribute,
            "battery",
        ),
        16: DPToAttributeMapping(
            TuyaMCUCluster.ep_attribute,
            "silence",
        ),
    }

    data_point_handlers = {
        1: "_dp_2_attr_update",
        9: "_dp_2_attr_update",
        14: "_dp_2_attr_update",
        15: "_dp_2_attr_update",
        16: "_dp_2_attr_update",
    }

class TuyaIasZone(CustomCluster, IasZone):
    """IAS Zone."""

    _CONSTANT_ATTRIBUTES = {ZONE_TYPE: IasZone.ZoneType.Fire_Sensor}

class MoesSmokeSensor(EnchantedDevice):
    """ZHA quirk for Moes ZSS-HM-SSD01 smoke sensor."""

    signature = {
        MODELS_INFO: [("_TZE204_vawy74yh", "TS0601")],
             ENDPOINTS: {
                 1: {
                    PROFILE_ID: zha.PROFILE_ID,
                    DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                    INPUT_CLUSTERS: [
                        Groups.cluster_id,
                        Scenes.cluster_id,
                        TuyaMCUCluster.cluster_id,
                        Basic.cluster_id,
            ],
            OUTPUT_CLUSTERS: [
                Time.cluster_id,
                Ota.cluster_id,
            ],
        },
    },
}

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    Groups.cluster_id,
                    Basic.cluster_id,
                    Scenes.cluster_id,
                    TuyaNoBindPowerConfigurationCluster,
                    TuyaSmokeSensorCluster,
            ],
                OUTPUT_CLUSTERS: [
                    Time.cluster_id,
                    Ota.cluster_id,
                ],
            },
        },
    }

image

Using ZHA-toolkit for entities, let's see how it is going to work.

pulsar895 commented 5 days ago

Hello,

I've just made a pull request for the smoke detector to be seen: https://github.com/zigpy/zha-device-handlers/pull/3447

I hope that others a little more at ease than me will know how to add the battery status...

Keffu3636 commented 5 days ago

Sorry, but what does it mean exactly?

pulsar895 commented 4 days ago

The modification I've proposed allows the device to indicate whether it detects smoke or not. Adding battery status is beyond my capabilities. I hope someone will be able to translate from z2m to zha so we can get all the elements.

Keffu3636 commented 13 hours ago

Any idea why I get enum8.undefined_0x01 as value when quering smoke? Battery is fine.

image image

Keffu3636 commented 11 hours ago

After HA restart it start to populate values correctly. It works, but I don't have much confidence in it :)

Keffu3636 commented 9 hours ago

.. and when I triggered an actual alarm on a device itself I got num8.undefined_0x00 reading value for smoke attribute. Any ideas for quirk?