Help adding a variation of Tuya TS0044, TS004F to ZHA

Got my hopes up then it fell off, haha. Anyone have anything to add?

Mattwestb offered help on the zha handlers ticket.
I have updated the quirk based on what he said (I think :wink: )

I’ve had to add following to the import section:

  • COMMAND_STOP
  • LONG_RELEASE

logs on key presses:

top left single:

log:

2021-07-14 09:55:56 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=49 command_id=1>
2021-07-14 09:55:56 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] ZCL request 0x0001: []
2021-07-14 09:55:56 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] No handler for cluster command 1
2021-07-14 09:55:56 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x5247:1:0x0006]: received 'on' command with [] args on cluster_id '6' tsn '49'

---
bottom left single:

log:

2021-07-14 09:56:41 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=50 command_id=0>
2021-07-14 09:56:41 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] ZCL request 0x0000: []
2021-07-14 09:56:41 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0006] No handler for cluster command 0
2021-07-14 09:56:41 DEBUG (MainThread) [homeassistant.components.zha.core.channels.base] [0x5247:1:0x0006]: received 'off' command with [] args on cluster_id '6' tsn '50'

---
top right short:

log:

2021-07-14 09:57:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=51 command_id=2>
2021-07-14 09:57:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0002: [0, 51, 10]
2021-07-14 09:57:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 2

---
top right long:

log:

 - pressed (3s):

2021-07-14 09:57:20 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=52 command_id=1>
2021-07-14 09:57:20 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0001: [0, 51]
2021-07-14 09:57:20 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 1
 
 - on release:

2021-07-14 09:57:21 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=53 command_id=3>
2021-07-14 09:57:21 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0003: []
2021-07-14 09:57:21 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 3

---
bottom right short:

log:

2021-07-14 09:57:43 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=54 command_id=2>
2021-07-14 09:57:43 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0002: [1, 51, 10]
2021-07-14 09:57:43 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 2

---
bottom right long:

log:

 - pressed (3s):

2021-07-14 09:58:01 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=55 command_id=1>
2021-07-14 09:58:01 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0001: [1, 51]
2021-07-14 09:58:01 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 1

 - on release:

2021-07-14 09:58:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL deserialize: <ZCLHeader frame_control=<FrameControl frame_type=CLUSTER_COMMAND manufacturer_specific=False is_reply=False disable_default_response=False> manufacturer=None tsn=56 command_id=3>
2021-07-14 09:58:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] ZCL request 0x0003: []
2021-07-14 09:58:02 DEBUG (MainThread) [zigpy.zcl] [0x5247:1:0x0008] No handler for cluster command 3

events:

top left single:

event:
 nothing

---

bottom left single:

event:
 nothing


---

top right short:

event:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "step",
        "args": [
            0,
            51,
            10
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:58:45.448513+00:00",
    "context": {
        "id": "7c6454a3af3de0a17db9c511561ad167",
        "parent_id": null,
        "user_id": null
    }
}

---

top right long:

event:

 - pressed:
 
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "move",
        "args": [
            0,
            51
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:59:14.288949+00:00",
    "context": {
        "id": "f06a8f144fa9f46ef52d708d210b11de",
        "parent_id": null,
        "user_id": null
    }
}
 
 - on release:
 
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "stop",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:59:14.971646+00:00",
    "context": {
        "id": "ce4ecc65443f8120ad09e24ec100f241",
        "parent_id": null,
        "user_id": null
    }
}

---

bottom right short:

event:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "step",
        "args": [
            1,
            51,
            10
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:58:57.610832+00:00",
    "context": {
        "id": "fa56d288b5e8e875ab63192770fbb007",
        "parent_id": null,
        "user_id": null
    }
}

---

bottom right long:

event:

 - pressed:
 
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "move",
        "args": [
            1,
            51
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:59:40.675123+00:00",
    "context": {
        "id": "150041ab3d110ab5f4c8cc1b57ef672b",
        "parent_id": null,
        "user_id": null
    }
}
 
 - on release:
 
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "60:a4:23:ff:fe:db:2f:27",
        "unique_id": "60:a4:23:ff:fe:db:2f:27:1:0x0008",
        "device_id": "6553e1c231f756fc4ddeb1b181013424",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "stop",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-07-14T07:59:41.438951+00:00",
    "context": {
        "id": "09ecbecca5cc249fb8ba7c4c7e32263b",
        "parent_id": null,
        "user_id": null
    }
}

Maybe stupid question, but one of the earlier post suggested that a switch was created associated with the zigbee device. You don’ have such a switch?

Furthermore, what do you see as triggers when trying to define an automation on the device?
Are they working?

(sample from a Hue remote)

I had the opportunity to sell my switch without losses and since I need a working 12 way switch anyways I sold it.

I’ll try to answer your questions anyways.

Without any custom quirks, there was one switch which was switched by the top-left and bottom-left buttons.

With the latest custom quirk this also worked.

At last I have tried the switch with a zigbee2mqtt setup. There I got an action entity with 6 options like in your screenshot. I have not seen this with the zha integration, but I might have missed it. But also with zigbee2mqtt there were only 6 actions.

Hello

I have added custom path for custom quirks .

zha:
  custom_quirks_path: /config/custom_zha_quirks/

After that I have created a file in side custom_zha_quirks folder named ts004f.py

But after the HA restart Zigbee integration will not load.

Here is the log

Logger: homeassistant.config_entries
Source: custom_zha_quirks/ts004f.py:63
First occurred: 4:10:01 PM (1 occurrences)
Last logged: 4:10:01 PM

Error setting up entry socket://192.168.0.105:8888 for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 293, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 99, in async_setup_entry
    setup_quirks(config)
  File "/usr/local/lib/python3.8/site-packages/zhaquirks/__init__.py", line 403, in setup
    importer.find_module(modname).load_module(modname)
  File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 962, in load_module
  File "<frozen importlib._bootstrap_external>", line 787, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_zha_quirks/ts004f.py", line 33, in <module>
    class Tuya4NewButtonTriggers:
  File "/config/custom_zha_quirks/ts004f.py", line 63, in Tuya4NewButtonTriggers
    (LONG_RELEASE, BUTTON_4): {COMMAND: COMMAND_STOP, ENDPOINT_ID: 1},
NameError: name 'LONG_RELEASE' is not defined

I’ve updated the post.
I also created a gist: TS004F custom quirk · GitHub

@koying Thanks for the quick response

I got the HA to load the custom quirk by installing the custom deps addon , after that added the ts004f.py in /usr/local/lib/python3.9/site-packages/zhaquirks/tuya reloaded the pycache

2021-07-17 15:14:58 DEBUG (MainThread) [zigpy.quirks.registry] Checking quirks for _TZ3000_xabckq1v TS004F (60:a4:23:ff:fe:95:22:d7)
2021-07-17 15:14:58 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'zhaquirks.tuya.ts004f.TuyaSmartRemote004F'>
2021-07-17 15:14:58 DEBUG (MainThread) [zigpy.quirks.registry] Found custom device replacement for 60:a4:23:ff:fe:95:22:d7: <class 'zhaquirks.tuya.ts004f.TuyaSmartRemote004F'>

it also showing up in device page now

but zha_event still not able to see any event by any button press.

A dedicated PR has been created for those willing to help getting this right

3 Likes

To pull all the information together and make sure there is something for new users to directly follow, I’ve added the post:

To this thread.

Thanks all or the help
Too bad all the functions advertised are not available, damn tuya…

Hi Chris and others with a TS004F,

I have 4 of the Tuya 4 button switch TS004F. They come from a vendor claiming they were model TS0044 (12 scene switch), however they were TS004F and behave the same as I can read on all the posts here.
I called the vendor, and they tell me the TS004F is a 12 scene switch if it is configured to be. This is done using the Tuya gateway and their app. On first discovery of the device, the app will ask asked about the “mode”, and set it on the switch. I have looked into this and it seem correct. Even mentioned on the description-paper slips.
I have looked around and this problem is well known on different platforms, and the solution seems quite straight forward.
On initial setup the switch need to be configured, by setting a switch to “1”. Like in this example from another platform
cmd += zigbee.writeAttribute(0x0006, 0x8004, 0x30, 0x01, dummy, delay=50)
Look in this link: https://raw.githubusercontent.com/kkossev/Hubitat/main/Drivers/Tuya%20TS004F/TS004F.groovy
where the 0x01 initiates a “12 buttom switch mode”

It is also mentioned on this link TS004F (instead of TS0044) buttons has only single tap · Discussion #7158 · Koenkk/zigbee2mqtt · GitHub. Search for “Enum8 = 1” and you will find the right article.

I do not have any clue how to use this information. How to send the “mode setting” to the switch during setup.

Anyone knows?

If someone needs a switch for testing, I will send you one. Your welcome to keep it if successful). I will be happy to help testing also.

3 Likes

I too thought I was getting a TS0044 but turned out to be a TS004F. So, I’m trying to get it to work with ZHA. In my research today, I see that the Zigbee2MQTT folks made some progress just today on it. As @khvej8 mentioned above, there’s a way to switch it to the 12 scene switch mode. I’m too new to any of this to know how that could be done in the quirks. Or if it even can. Maybe someone more knowledgeable could take a look her and see if it makes sense to them?

Found more info on how to change the switch mode.

image

https://www.zigbee2mqtt.io/devices/TS004F.html#device-modes

5 Likes

Can anyone confirm this is working?

1 Like

EL_Duderino, I can not make it work using ZHA. It shows up as a the dimmer version, not the 12scene.

Holding button 2+4 will make button 3 flash 3 times, as described. However adding the button to ZHA afterwards will ends with the dimmer version.

I’m using ZHA and not Z2M. When I put the switch in switch mode 2 by holding buttons 2+4, light 3 flashes once as described. After this I no longer receive any ZHA events at all. The same procedure puts the switch back into mode 1

1 Like

Agree, after holding button 2+4 the events will stop. I beleive it is because it changes to a “new device”. I tried to add it to ZHA again, it adds as a dimmer version. Can not make it add as a 12 scene button.

Yup, can confirm it. device doesn’t work in ZHA as the 12 scene button. ZHA quirk needs to be updated I guess. Z2M works with both device modes.

My device for some reason, now have this entity button.tz3000_xabckq1v_ts004f_5194fcfe_identify and it’s the only one that have an action. There is a PRESS text next to it so I can make a automation based on it, but only by the UI. No button works at all on the physical switch, no zha_event, not even repairing, pressing 2+4 buttons, etc. Should I return this device or it might work one day?