Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Device Support Request] TS0601_TZE200_drs6j6m5 #3557

Open
DanielSobczak opened this issue Nov 27, 2024 · 1 comment
Open

[Device Support Request] TS0601_TZE200_drs6j6m5 #3557

DanielSobczak opened this issue Nov 27, 2024 · 1 comment

Comments

@DanielSobczak
Copy link

DanielSobczak commented Nov 27, 2024

Problem description

I recently have bought a led driver Lifud LF-GAZ150A6250-24.
Device can be added via ZHA to HA, but there are no switches available.
Purchased from here.

Solution description

I would like to control the brightness and be able to turn off/on light.

Screenshots/Video

Screenshots/Video

[Paste/upload your media here]

Device signature

Device signature
{
  "node_descriptor": {
    "logical_type": 1,
    "complex_descriptor_available": 0,
    "user_descriptor_available": 0,
    "reserved": 0,
    "aps_flags": 0,
    "frequency_band": 8,
    "mac_capability_flags": 142,
    "manufacturer_code": 4417,
    "maximum_buffer_size": 66,
    "maximum_incoming_transfer_size": 66,
    "server_mask": 10752,
    "maximum_outgoing_transfer_size": 66,
    "descriptor_capability_field": 0
  },
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0051",
      "input_clusters": [
        "0x0000",
        "0x0004",
        "0x0005",
        "0xef00"
      ],
      "output_clusters": [
        "0x000a",
        "0x0019"
      ]
    },
    "242": {
      "profile_id": "0xa1e0",
      "device_type": "0x0061",
      "input_clusters": [],
      "output_clusters": [
        "0x0021"
      ]
    }
  },
  "manufacturer": "_TZE200_drs6j6m5",
  "model": "TS0601",
  "class": "zigpy.device.Device"
}

Diagnostic information

Diagnostic information
[Paste the diagnostic information here]

Logs

Logs
[Paste the logs here]

Custom quirk

Custom quirk
"""Tuya dimmable led controller."""
from zigpy.profiles import zgp, zha
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.zcl.clusters.general import (
    Basic,
    GreenPowerProxy,
    Groups,
    Identify,
    LevelControl,
    OnOff,
    Ota,
    Scenes,
    Time,
)

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya import NoManufacturerCluster, TuyaDimmerSwitch, TuyaSwitch
from zhaquirks.tuya.mcu import (
    TuyaInWallLevelControl,
    TuyaLevelControlManufCluster,
    TuyaOnOff,
    TuyaOnOffNM,
    MoesSwitchManufCluster
)




class DimmableLedController(TuyaSwitch):
    """Tuya dimmable led controller."""

    signature = {
        MODELS_INFO: [("_TZE200_drs6j6m5", "TS0601")],
        ENDPOINTS: {
            1: {
                PROFILE_ID: 260,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    4, 5, 61184, 0
                ],
                OUTPUT_CLUSTERS: [25, 10],
            },
            242: {
                PROFILE_ID: 41440,
                DEVICE_TYPE: 97,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [33],
            },
        },
    }
    replacement = {
        ENDPOINTS: {
             1: {
                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                INPUT_CLUSTERS: [
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    Basic.cluster_id,
                    MoesSwitchManufCluster,
                    TuyaOnOffNM,
                ],
                OUTPUT_CLUSTERS: [25, 10],
            }
        }
    }

Additional information

With the above quirk I'm able to control the on/off state, to add brightness control I've tried to use TuyaLevelControl, TuyaLevelControlManufCluster and TuyaInWallLevelControl but they didn't work for me.

As I have seen, this device is supported by Zigbee2MQTT where they set

[3, 'brightness', tuya.valueConverter.scale0_254to0_1000],

as tuya datapoint
After trying to figure out what should be send I noticed that the values within payload might need to be changed from transition_time to transtime - I was trying to customize F000LevelControlCluster but due to not fully understanding what exactly needs to be send I was not able to control the brightness.

@DanielSobczak
Copy link
Author

Ok, some update, I'm able now to control the brightness - issue was with the dp to attribute mapping. Lifud is using id 3 to control level instead of 2.

This can potentially work on the same set of devices as on Zigbee2MQTT

'_TZE200_86nbew0j', '_TZE200_io0zdqh1', '_TZE200_drs6j6m5', '_TZE200_ywe90lt0', '_TZE200_qyss8gjy'

"""Tuya dimmable led controller."""
from zigpy.profiles import zgp, zha
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.zcl.clusters.general import (
    Basic,
    GreenPowerProxy,
    Groups,
    Identify,
    LevelControl,
    OnOff,
    Ota,
    Scenes,
    Time,
)

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya import NoManufacturerCluster, TuyaDimmerSwitch
from zhaquirks.tuya.mcu import (
    TuyaInWallLevelControl,
    TuyaLevelControlManufCluster,
    TuyaOnOff,
    TuyaOnOffNM,
    TuyaLevelControl,
    TuyaOnOffManufCluster,
    DPToAttributeMapping
)

class TuyaInWallLevelControlNM(NoManufacturerCluster, TuyaInWallLevelControl):
    """Tuya Level cluster for inwall dimmable device with NoManufacturerID."""

class TuyaLevelControlManufClusterLifud(TuyaLevelControlManufCluster):
     """Tuya with Level Control data points for Lifud led driver."""
     
     dp_to_attribute: dict[int, DPToAttributeMapping] = {
        1: DPToAttributeMapping(
            TuyaOnOff.ep_attribute,
            "on_off",
        ),
        3: DPToAttributeMapping(
            TuyaLevelControl.ep_attribute,
            "current_level",
            converter=lambda x: (x * 255) // 1000,
            dp_converter=lambda x: (x * 1000) // 255,
        )
        }

class TuyaDimmableLedController(TuyaDimmerSwitch):
    """Tuya dimmable led controller."""

    signature = {
        MODELS_INFO: [("_TZE200_drs6j6m5", "TS0601")],
        ENDPOINTS: {
            1: {
                PROFILE_ID: 260,
                DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
                INPUT_CLUSTERS: [
                    4, 5, 61184, 0
                ],
                OUTPUT_CLUSTERS: [25, 10],
            },
            242: {

                PROFILE_ID: 41440,
                DEVICE_TYPE: 97,
                INPUT_CLUSTERS: [],
                OUTPUT_CLUSTERS: [33],
            },
        },
    }
    replacement = {
        ENDPOINTS: {
             1: {
                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                INPUT_CLUSTERS: [
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    Basic.cluster_id,
                    TuyaLevelControlManufClusterLifud,
                    TuyaOnOffNM,
                    TuyaInWallLevelControlNM,
                ],
                OUTPUT_CLUSTERS: [25, 10],
            },
        }
    }
    
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant