zha-device-handlers icon indicating copy to clipboard operation
zha-device-handlers copied to clipboard

[Device Support Request] Tuya Smart Plug TS011F _TZ3000_5f43h46b

Open jasonwragg opened this issue 3 years ago • 50 comments

Is your feature request related to a problem? Please describe. Plug has the following in zigbee2mqtt Screenshot 2022-03-23 at 12 42 23 Screenshot 2022-03-23 at 12 43 15

{ "child_lock": "UNLOCK", "indicator_mode": "off", "linkquality": 63, "power_outage_memory": "restore", "state": "ON" }

Describe the solution you'd like Add the missing option to ZHA

Device signature - this can be acquired by removing the device from ZHA and pairing it again from the add devices screen. Be sure to add the entire content of the log panel after pairing the device to a code block below this line. { "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)", "endpoints": { "1": { "profile_id": 260, "device_type": "0x010a", "in_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x0702", "0x0b04", "0xe000", "0xe001" ], "out_clusters": [ "0x000a", "0x0019" ] } }, "manufacturer": "_TZ3000_5f43h46b", "model": "TS011F", "class": "zhaquirks.tuya.ts011f_plug.Plug" } Additional context

jasonwragg avatar Mar 23 '22 12:03 jasonwragg

What functions is missing / not working in ZHA ? The only thing not implanted in ZHA is the children-lock (that looks not being implanted in Z2M 2 then its no trace of code in there system of it). Its looks like power, current, voltage and energy is not working as is shall in Z2M.

MattWestb avatar Mar 23 '22 16:03 MattWestb

The child lock, power restore (power_outage_memory), power button light control.

From: MattWestb @.> Reply to: zigpy/zha-device-handlers @.> Date: Wednesday, 23 March 2022 at 16:21 To: zigpy/zha-device-handlers @.> Cc: Jason Wragg @.>, Author @.***> Subject: Re: [zigpy/zha-device-handlers] [Device Support Request] Tuya Smart Plug TS011F _TZ3000_5f43h46b (Issue #1442)

What functions is missing / not working in ZHA ? The only thing not implanted in ZHA is the children-lock. Its looks like power, current, voltage and energy is not working as is shall in Z2M.

— Reply to this email directly, view it on GitHubhttps://github.com/zigpy/zha-device-handlers/issues/1442#issuecomment-1076535458, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMU7GI5GPNJ6MD5I2OQYKTLVBNATHANCNFSM5RN5OGCA. You are receiving this because you authored the thread.Message ID: @.***>

jasonwragg avatar Mar 23 '22 17:03 jasonwragg

You have all found functions on the TuyaZBOnOffAttributeCluster: https://github.com/zigpy/zha-device-handlers/blob/039a31f1ca15821e800bdb347eb47fdb02455f31/zhaquirks/tuya/init.py#L789-L819 And also switch type on the TuyaZBExternalSwitchTypeCluster: https://github.com/zigpy/zha-device-handlers/blob/039a31f1ca15821e800bdb347eb47fdb02455f31/zhaquirks/tuya/init.py#L913-L928 Child lock is not "found" and is not implanted in ZHA or Z2M.

MattWestb avatar Mar 23 '22 17:03 MattWestb

Should i be seeing it in Home Assistant? Screenshot 2022-03-23 at 17 57 35

jasonwragg avatar Mar 23 '22 17:03 jasonwragg

child lock work in Z2M as I've turn it on (On a different device) and now can't turn it off because I've changed to ZHA Screenshot 2022-03-23 at 17 59 28 A

jasonwragg avatar Mar 23 '22 18:03 jasonwragg

All power measuring looks working OK. The attributes you is finding in "manager cluster" > selecting cluster > selecting attribute you like get or sting.

If you like have switches for then use tamplets switches in HA and connecting them to the attribute you like changing from the GUI or implanting it in ZHA.

You can also looking in the Z2M code and implanting the child-lock if you can finding it there.

MattWestb avatar Mar 23 '22 18:03 MattWestb

I have founding the implementation in Z2M: https://github.com/Koenkk/zigbee-herdsman-converters/blob/92d4e6f50c4b600d631b4b6b139b997d1528e97e/converters/toZigbee.js#L6130-L6133 You can implanting the attribute in tuya INIT on the TuyaZBOnOffAttributeCluster i was showing before.

MattWestb avatar Mar 23 '22 18:03 MattWestb

Like this? [Text Description automatically generated] From: MattWestb @.> Reply to: zigpy/zha-device-handlers @.> Date: Wednesday, 23 March 2022 at 18:23 To: zigpy/zha-device-handlers @.> Cc: Jason Wragg @.>, Author @.***> Subject: Re: [zigpy/zha-device-handlers] [Device Support Request] Tuya Smart Plug TS011F _TZ3000_5f43h46b (Issue #1442)

I have founding the implementation in Z2M: https://github.com/Koenkk/zigbee-herdsman-converters/blob/92d4e6f50c4b600d631b4b6b139b997d1528e97e/converters/toZigbee.js#L6130-L6133 You can implanting the attribute in tuya INIT on the TuyaZBOnOffAttributeCluster i was showing before.

— Reply to this email directly, view it on GitHubhttps://github.com/zigpy/zha-device-handlers/issues/1442#issuecomment-1076675683, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMU7GI75AESURGVGVOHHAVLVBNO4BANCNFSM5RN5OGCA. You are receiving this because you authored the thread.Message ID: @.***>

jasonwragg avatar Mar 23 '22 18:03 jasonwragg

Screenshot 2022-03-23 at 18 47 55

jasonwragg avatar Mar 23 '22 19:03 jasonwragg

First the 0x8000 shall being first for not braking isort.

I have asking and very likely its one (t.Bool) so making it Locked and Unlocked for 0 and 1 (or 1 and 0) and testing if its working OK.

You need doing the changed in the HA docker container or the quirks cant "reading" it.

MattWestb avatar Mar 23 '22 19:03 MattWestb

If you is getting it working OK its one more attribute that we have "found" but not implanted that your device can having 0x8003. Look in our cluster matrix https://github.com/zigpy/zigpy/discussions/823#discussioncomment-1539469 and you finding it on the OnOff cluster for tuya Zigbee devices.

Some user of TS011F with power reading is having problems that its power of its self but i can being over current protection or hardware problem but can being good implanting it for the future.

MattWestb avatar Mar 23 '22 19:03 MattWestb

~~Maybe you can try with:~~ (no, you can't. see: https://github.com/zigpy/zha-device-handlers/issues/1442#issuecomment-1076863920)

class ChildLock(t.Bool):
    """Tuya child lock states."""

    LOCK = True  # maybe 1 or 0x01
    UNLOCK = False  # maybe 0 or 0x00


class TuyaZBOnOffAttributeCluster(CustomCluster, OnOff):
    """Tuya Zigbee On Off cluster with extra attributes."""

    attributes = OnOff.attributes.copy()
    attributes.update({0x8000: ("child_lock", ChildLock)})
    attributes.update({0x8001: ("backlight_mode", SwitchBackLight)})
    attributes.update({0x8002: ("power_on_state", PowerOnState)})
    attributes.update({0x8004: ("switch_mode", SwitchMode)})

Not sure how to wrap the t.Bool. You can try with diferent values. The ChildLock is more user friendly, but if give more truoble would be enough with:

    attributes.update({0x8000: ("child_lock", t.Bool)})

edit: fix class description & boolean values

javicalle avatar Mar 23 '22 20:03 javicalle

Its looks nicer in GUI if reading the state of the attribute if using "normal" writing that is done with the other attribute on the same cluster. ChildLock: Locked and ChildLock: Unlocked

I think """Tuya power on state enum.""" is the proposed looking better ;-)) (Corrupted clipboard buffer bug ?)

I think for testing is attributes.update({0x8000: ("child_lock", t.Bool)}) added in the local quirk its easiest way see if its working OK or not with the device. Setting and getting 0 or 1 from the attribute its working then moving it to INIT.

MattWestb avatar Mar 23 '22 20:03 MattWestb

If tuya have doing it little standard it shall being 0 and 1 in the reading the attribute and also writing it.

Was testing reading one bool from one IKEA CWS3 lights color cluster:

Attributes of the selected cluster
color_loop_active (id: 0x4002)

Value
0

And active:

Attributes of the selected cluster
color_loop_active (id: 0x4002)
 
Value
1

MattWestb avatar Mar 23 '22 20:03 MattWestb

It seems that Bool can't be extended.

You can keep the definition without the auxiliar class or try with something like:

class ChildLock(t.uint8_t):
    """Tuya power on state enum."""

    LOCK = 1
    UNLOCK = 0


class TuyaZBOnOffAttributeCluster(CustomCluster, OnOff):
    """Tuya Zigbee On Off cluster with extra attributes."""

    attributes = OnOff.attributes.copy()
    attributes.update({0x8000: ("child_lock", ChildLock)})
    attributes.update({0x8001: ("backlight_mode", SwitchBackLight)})
    attributes.update({0x8002: ("power_on_state", PowerOnState)})
    attributes.update({0x8004: ("switch_mode", SwitchMode)})

Refs:

  • https://stackoverflow.com/questions/2172189/why-i-cant-extend-bool-in-python

javicalle avatar Mar 23 '22 22:03 javicalle

I seem to be able to get the attribute value for child lock but not set it.

If I wanted to add a switch for an attribute in Home Assistant what would I use as the value_template for any of the above ?

jasonwragg avatar Mar 24 '22 10:03 jasonwragg

I seem to be able to get the attribute value for child lock but not set it.

Which value are you trying to set? I would try with 1/0 Any related traces in your logs?

javicalle avatar Mar 24 '22 11:03 javicalle

0/1 [homeassistant.components.zha.api] Set attribute for: cluster_id: [6] cluster_type: [in] endpoint_id: [1] attribute: [32768] value: [0] manufacturer: [None] response: [[[WriteAttributesStatusRecord(status=<Status.INVALID_DATA_TYPE: 141>, attrid=32768)]]]

[homeassistant.components.zha.core.device] 0x574F: set: 1 for attr: 32768 to cluster: 6 for ept: 1 - res: [[WriteAttributesStatusRecord(status=<Status.INVALID_DATA_TYPE: 141>, attrid=32768)]]

jasonwragg avatar Mar 24 '22 11:03 jasonwragg

Can you try with True/False?

If it's not working, change the declaration to:

    attributes.update({0x8000: ("child_lock", t.Bool)})

and try again with 0/1 and True/False

javicalle avatar Mar 24 '22 11:03 javicalle

Still getting

2022-03-24 11:38:32 DEBUG (MainThread) [homeassistant.components.zha.api] Read attribute for: cluster_id: [6] cluster_type: [in] endpoint_id: [1] attribute: [32768] manufacturer: [None] response: [0] failure: [{}],
2022-03-24 11:38:38 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=zha, service=set_zigbee_cluster_attribute, service_data=ieee=a4:c1:38:e0:b5:a5:bb:c6, endpoint_id=1, cluster_id=6, cluster_type=in, attribute=32768, value=True>
2022-03-24 11:38:38 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x574F](TS011F): set: True for attr: 32768 to cluster: 6 for ept: 1 - res: [[WriteAttributesStatusRecord(status=<Status.INVALID_DATA_TYPE: 141>, attrid=32768)]]
2022-03-24 11:38:38 DEBUG (MainThread) [homeassistant.components.zha.api] Set attribute for: cluster_id: [6] cluster_type: [in] endpoint_id: [1] attribute: [32768] value: [True] manufacturer: [None] response: [[[WriteAttributesStatusRecord(status=<Status.INVALID_DATA_TYPE: 141>, attrid=32768)]]]

jasonwragg avatar Mar 24 '22 11:03 jasonwragg

Also with the code changed? Have you deleted the python cache (__pycache__ folder)? Can you enable the zigpy.zcl debug logs?

javicalle avatar Mar 24 '22 11:03 javicalle

Still just get:

2022-03-27 19:21:58 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0xCB93](TS011F): failed to set attribute: value: 0 attribute: 32768 cluster_id: 6 endpoint_id: 1 [0xcb93:1:0x0006]: Message send failure
2022-03-27 19:21:58 DEBUG (MainThread) [homeassistant.components.zha.api] Set attribute for: cluster_id: [6] cluster_type: [in] endpoint_id: [1] attribute: [32768] value: [0] manufacturer: [None] response: [None]

jasonwragg avatar Mar 27 '22 18:03 jasonwragg

These logs are diferent. Good. Have you tried with True and False values?

Can you enable the zigpy.zcl debug logs?

Any of these logs in your traces?

javicalle avatar Mar 27 '22 19:03 javicalle

This is the code I'm using

`class TuyaZBOnOffAttributeCluster(CustomCluster, OnOff): """Tuya Zigbee On Off cluster with extra attributes."""

attributes = OnOff.attributes.copy()
attributes.update({0x8000: ("child_lock", ChildLock)})
attributes.update({0x8001: ("backlight_mode", SwitchBackLight)})
attributes.update({0x8002: ("power_on_state", PowerOnState)})
attributes.update({0x8004: ("switch_mode", t.Bool)})`

I've tried 1/0 and True/False, Its seems to 'get' ok but the set doesn't work.

Is there a way of getting the value in to home assistant, in a sensor or lock entity?

jasonwragg avatar Mar 27 '22 20:03 jasonwragg

Can you try with True/False?

If it's not working, change the declaration to:

    attributes.update({0x8000: ("child_lock", t.Bool)})

and try again with 0/1 and True/False

Can you test with the above suggested change for the child_lock attribute?

javicalle avatar Mar 27 '22 20:03 javicalle

That's working!

Would it be possible to add that in to home assistant as template lock or switch?

jasonwragg avatar Mar 27 '22 21:03 jasonwragg

I have reviewed it again and I believe that it must to work with a helper class.

Could you try again with this code:

class ChildLock(t.Bool):
    """Tuya child lock states."""

    LOCK = t.Bool.true
    UNLOCK = t.Bool.false


class TuyaZBOnOffAttributeCluster(CustomCluster, OnOff):
    """Tuya Zigbee On Off cluster with extra attributes."""

    attributes = OnOff.attributes.copy()
    attributes.update({0x8000: ("child_lock", ChildLock)})
    attributes.update({0x8001: ("backlight_mode", SwitchBackLight)})
    attributes.update({0x8002: ("power_on_state", PowerOnState)})
    attributes.update({0x8004: ("switch_mode", SwitchMode)})

javicalle avatar Mar 31 '22 22:03 javicalle

That doesn't work I get :

TypeError: ChildLock: cannot extend enumeration 'Bool'

jasonwragg avatar Apr 01 '22 09:04 jasonwragg

Thanks for testing again.

javicalle avatar Apr 01 '22 09:04 javicalle

@jasonwragg Try with this 2 versions:

class ChildLock(t.Bool):
    """Tuya child lock states enum."""

    Unlocked = False
    Locked = True

or

class ChildLock(t.Bool):
    """Tuya child lock states enum."""

    Unlocked = 0
    Locked = 1

Also then you can reading the attribute is it 0/1 or True / False the device / system is returning (i think 0/1 then my test color lope was doing that) ? I dont knowing if Python is case sensitive or not but all code is made with True/False what i have seen and it shall not being needing declaring the type 2 or more times in the function (its not German lang !!).

MattWestb avatar Apr 01 '22 11:04 MattWestb