doctor64 / tuyaZigbee

Replacement firmwares for TuYa zigbee devices
Apache License 2.0
136 stars 19 forks source link

What can I do to help add devices to this project? (Specifically TS0012 & TS0002) #13

Open roderik-maker opened 9 months ago

roderik-maker commented 9 months ago

Great project here, really glad I found it. I didn't expect it would be possible to install custom firmware on Tuya devices. What can I do to help add support for the TS0012 & TS0002?

I have 5 modules of the TS0012 and 5 on the way of the TS0002. I would like to bind these devices to various smart lights (primarily TRADFRI & LIVARNO) and stumbled across this project. I don't mind sacrificing 1 or 2 modules (of both types) to this project if this helps to develop firmware that supports binding (and maybe a decoupled mode for the TS0012? There seems to be some demand for that ) I'm hoping a lot of the firmware for the TS0041 can be reused for this project as I would expect the PCB's to be setup in a very similar manner.

I've played around with ESPHome for a while and a little with the Arduino IDE (so not a complete beginner) but am well aware that I still have A LOT to learn about micro controllers (I also suck at soldering so would prefer to avoid that as much as possible haha). Anyway, I would like to contribute and was wondering what I can do to help out? Can I just connect a UART <-> TTL adapter to the ZT3L using this pinout and start recording logs? Is that even useful/helpful? I'm not asking for a step by step guide (unless it already exists and I missed it haha) but some links/tips/other forms of help or guidance would be really appreciated!

Here are some pictures of the TS0012 PCB: (I can make and share similar pictures of the TS0002 once they arrive, if desired) IMG_8447 2 IMG_8448 2 IMG_8449 2 IMG_8450 2

PS. I get into these projects on a sporadic basis (life gets in the way) so sorry in advance if it takes a while for me to respond.

EDIT: Added links to the Zigbee2MQTT pages of the TS0012 & TS0002, and rewrote 1 sentence for clarity.

doctor64 commented 9 months ago

Hello and thank you for interest in my project. Technically speaking, it is possible, but will be some difficulties :) First, I need to understand schematics of device, at least of some parts, to understand on which GPIO pins external hardware like buttons.switches, relay, leds (if present) connected. Second, unfortunately, code for relay-class devices not implemented yet. Once it will be implemented, all devices with similar functionality and hardware can share same code with minimal changes, unfortunately, it need to wait some time. Third, please, provide links where i can buy such device for development (aliexpress is good)

According to your question about logs - yes, it is completely possible, but need to be very careful with such mains powered devices. Often they not galvanic isolated from mains and you can easily fry your PC, serial port, USB_SERIAL converter etc. I already have programmer fried :) And currently it's not have much sense - i don't see any Tuya firmware with any kind of diagnostics log. It will be useful during debugging of new firmware.

roderik-maker commented 9 months ago

Thank you for your quick response :)

Point 1. I don't mind grabbing a multimeter and seeing if I can Identify the pins related to s1,s2,o1,o2. There are 8 pins going to the controller, I would imagine those are 3V3,GND,s1,s2,o1,o2, reset button and I think it has a status led, so that would make sense. (Should also be easy to identify). Hopefully they're not using any serial internally but I doubt it.

Point 2. Not sure what I can contribute to this but if I can help let me know.

Point 3. Purchase links: TS0012 (The 2gang no Neutral variant) TS0001 (The 2CH variant) Let me just double check that this module does indeed also use the ZT3L processor before you invest any time in making this module work. My order should be here at the end of next week... Hopefully haha

Point 4. Okay, if I understood you correctly, I will wait with trying to connect to serial until you have some basic firmware.

Anything more I can do short term?

doctor64 commented 9 months ago
  1. Yes, this can help. Ideally, i need to know also active level of signal, but just basic info will be good for start.
  2. Unfortunately, i'm low on free time for project, but i try my best.
  3. Ok, waiting for your report on second variant.
  4. Yeah, right now it is not needed
roderik-maker commented 9 months ago

Came back from vacation and the second variant (TS0001) has been delivered, unfortunately it uses the ZS2S and not the ZT3L so that's a no go I fear. I'll have a look at the pinout of the TS0012 (the one with the ZT3L) tonight.

anishp55 commented 8 months ago

I have a few of the temp/humidity sensors - 0xa4c1381b4aef5473. they are using the ZTU module. What are the steps needed to add a new device?

indevor commented 8 months ago

Great project here, really glad I found it. I didn't expect it would be possible to install custom firmware on Tuya devices. What can I do to help add support for the TS0012 & TS0002?

I have 5 modules of the TS0012 and 5 on the way of the TS0002. I would like to bind these devices to various smart lights (primarily TRADFRI & LIVARNO) and stumbled across this project. I don't mind sacrificing 1 or 2 modules (of both types) to this project if this helps to develop firmware that supports binding (and maybe a decoupled mode for the TS0012? There seems to be some demand for that ) I'm hoping a lot of the firmware for the TS0041 can be reused for this project as I would expect the PCB's to be setup in a very similar manner.

I've played around with ESPHome for a while and a little with the Arduino IDE (so not a complete beginner) but am well aware that I still have A LOT to learn about micro controllers (I also suck at soldering so would prefer to avoid that as much as possible haha). Anyway, I would like to contribute and was wondering what I can do to help out? Can I just connect a UART <-> TTL adapter to the ZT3L using this pinout and start recording logs? Is that even useful/helpful? I'm not asking for a step by step guide (unless it already exists and I missed it haha) but some links/tips/other forms of help or guidance would be really appreciated!

Here are some pictures of the TS0012 PCB: (I can make and share similar pictures of the TS0002 once they arrive, if desired) IMG_8447 2 IMG_8448 2 IMG_8449 2 IMG_8450 2

PS. I get into these projects on a sporadic basis (life gets in the way) so sorry in advance if it takes a while for me to respond.

EDIT: Added links to the Zigbee2MQTT pages of the TS0012 & TS0002, and rewrote 1 sentence for clarity.

Also have these modules... and they suck =( . They have a significant BUG - you can not turn on/off two devices (channels) at the same time. Only one at a time!

I haven't figured out if it's a hardware or software bug yet. I'm using home assistant + z2m - and what's interesting is that if you switch both channels through GUI at the same time - everything works as intended. But not with the switch. It would be cool to change the firmware for these modules! I have a soldering iron and a multimeter. I can help if needed.

indevor commented 8 months ago

@doctor64 I'll try to draw a schematic of these modules during the week (TS0012). I think since it works through GUI it is not a physical limitation. Perhaps there is a software delay (contact bounce) that is too large.

indevor commented 8 months ago

@doctor64 measured with a multimeter: COM = GND (MCU), S1 = C3 (MCU), S2 = C2 (MCU) pins are measured at 0 ohm - i.e. direct connection. MCU = ZT3L

indevor commented 8 months ago

@doctor64 Schematic_zigbee-zt3L_2024-02-08

these are the main control and operation lines, EL3023 triac driver (https://www.tme.eu/Document/5adba596c5890819da41a99e3c312555/EL3023.pdf) TS0012_switch_module

indevor commented 8 months ago

the contact bounce theory needs to be tested. I think it's not only that, it's just some software limitation (flaw), poor implementation. From a hardware point of view, judging by the schematic diagram, there are no limitations. This is a terrible bug that has been confirmed by various users. I also created a thread on Z2M and it was confirmed there. As for the popularity of the problem - they were sold tens of thousands of pieces :( on aliexpress alone.

roderik-maker commented 8 months ago

the contact bounce theory needs to be tested. I think it's not only that, it's just some software limitation (flaw), poor implementation. From a hardware point of view, judging by the schematic diagram, there are no limitations. This is a terrible bug that has been confirmed by various users. I also created a thread on Z2M and it was confirmed there. As for the popularity of the problem - they were sold tens of thousands of pieces :( on aliexpress alone.

With how popular these devices are I am also really surprised that they havn't bothered to fix this in later models.

Maybe the perceived added value of keeping consumers in the Tuya walled garden outweighs the extra sales they expect to gain from opening up their devices? But I really think they could sell so many more units if they played a little nicer with other Zigbee modules (support binding?) and facilitated OTA updates to fix bugs like this. Really hoping this project can become a solution to this shortcoming :)

Not really sure how much I can contribute to the project at this point (with my current skillset), but I'll keep an eye on this thread (and repo) to see if I can be useful somehow :)

indevor commented 8 months ago

the contact bounce theory needs to be tested. I think it's not only that, it's just some software limitation (flaw), poor implementation. From a hardware point of view, judging by the schematic diagram, there are no limitations. This is a terrible bug that has been confirmed by various users. I also created a thread on Z2M and it was confirmed there. As for the popularity of the problem - they were sold tens of thousands of pieces :( on aliexpress alone.

With how popular these devices are I am also really surprised that they havn't bothered to fix this in later models.

Maybe the perceived added value of keeping consumers in the Tuya walled garden outweighs the extra sales they expect to gain from opening up their devices? But I really think they could sell so many more units if they played a little nicer with other Zigbee modules (support binding?) and facilitated OTA updates to fix bugs like this. Really hoping this project can become a solution to this shortcoming :)

Not really sure how much I can contribute to the project at this point (with my current skillset), but I'll keep an eye on this thread (and repo) to see if I can be useful somehow :)

Oh, I hope @doctor64 has time to do this too. I can be a beta tester like you. I can also do measurements if needed. As for the modules - some sellers (aliexpress) explicitly state that simultaneous inclusion is not possible - most likely they have experienced huge returns and are being over-insured. Also I think people don't notice it first before ordering and then it's too late. Others just use them in different light groups/places. And the big sales are due to the fact that A) they are extremely cheap. B) they fit in a standard electrical box (European, that's right) behind the switch - and you don't have to redo all the wiring in the house.

doctor64 commented 8 months ago

Thank you for your work! From software point of view i don't see anything which can be source of unable to operate both relays in same time. May be some software problem in Tuya sdk - I recently got it but not yet have a time to look in details? but key detection code looks a little, let's say, strange :) I'm sorry, I don't have enough time to investigate in details. I will order both relays in near time, but unfortunately, can't provide any expected schedule for firmware - i need to write full firmware for relay-class device. May be i can reuse light device firmware, but I need to think.

IgnasGi commented 8 months ago

I bought a dozen MINI-Z1 2gang and 3gang switches with ZT2S modules for home automation. But they proved useless with standard firmware. They appear analogous to the TS0003 and TS0012 modules. How good that this project is - maybe we will be able to do something! I will make diagrams of the modules, I will be able to test and adjust. In my preferences.. single, long and double click recognition. It is possible, I hope? https://www.aliexpress.com/item/1005005748125397.html

doctor64 commented 8 months ago

@IgnasGi Thank you for your proposition. Please, put all relevant information in separate ticket, it will be easier to track.

roderik-maker commented 8 months ago

Thank you for your work! From software point of view i don't see anything which can be source of unable to operate both relays in same time. May be some software problem in Tuya sdk - I recently got it but not yet have a time to look in details? but key detection code looks a little, let's say, strange :) I'm sorry, I don't have enough time to investigate in details. I will order both relays in near time, but unfortunately, can't provide any expected schedule for firmware - i need to write full firmware for relay-class device. May be i can reuse light device firmware, but I need to think.

You state that you have to write the firmware for relay, but for the time being I am just using these devices as wall switch sensors. Any chance you can jerry rig something together that would support binding the input switch states directly to another Zigbee device like a lightbulb? currently the only equivalent device that would do this is the first gen aqara which is not sold anymore (so hard to get) and if you can still find them they are 3-4x as expensive as the tuya relays. (Ideally for both TS0012 & TS0011. )

I saw you have some basic support for TS0041, what is a worst case scenario if I flash a TS0012 or TS0002 with TS0041 firmware?

Anyway, sorry to bother you, totally understand if you are busy, no pressure, and again let us know if/when we can be useful!

doctor64 commented 8 months ago

Hmm, it is possible, but I see two problems here. First, I'm still need hardware details to know on which pins connected buttons, leds, etc. I don't think what flasing TS0041 will help, chances what hardware configuration for TS0041 match configuration of TS0011/TS0012 is pretty small, especially because TS0041 have unusual switches configuration. Action buttons on TS0041 active low, pressing button connect GPIO pin to GND, but net join button on this device is active high, pressing it connect pin to +3.3. So I not recommend this. Ordered 2 gang no neutral version.

monsterkali666 commented 1 month ago

@doctor64 Hello I have a bunch of zslc5 zigbee boards,from led bulbs. i have a jlink v12 dumped the mainflash.hex is there any chance to convert them to contact sensor? (i need around 15 door /windows sensors,and i was thinking maybe we can repurpose them) chip is efr32mg21a020f768 simplicity studio fails everytime i try to build project. i need help i will pay also i will provide what you ask for also if you need the hex,i will upload it thank you waiting for your answer

indevor commented 1 month ago

@doctor64 Hello I have a bunch of zslc5 zigbee boards,from led bulbs. i have a jlink v12 dumped the mainflash.hex is there any chance to convert them to contact sensor? (i need around 15 door /windows sensors,and i was thinking maybe we can repurpose them) chip is efr32mg21a020f768 simplicity studio fails everytime i try to build project. i need help i will pay also i will provide what you ask for also if you need the hex,i will upload it thank you waiting for your answer

study this post: https://mysku.club/blog/misc/95848.html and the comments at the bottom