logo elektroda
logo elektroda
X
logo elektroda

Open-TuyaMCU for Nuvoton MCU

no2chem 
Hi all,

Many of you are probably familiar with the TuyaMCU setup: devices which have two MCUs - one for WiFi, and another for handling device functions that speaks a protocol known as "TuyaMCU". TuyaMCU devices advertise datapoints to the WiFi MCU. This means that even with OpenBk we can't fully customize the functionality of the device.

Fortunately, one of the devices I got a hold of, the Treatlife DS02S switch contains easy to connect programming headers for the nuvoton (SWD/SWCLK):




I also found Tuya released some version of their TuyaMCU SDK. So I was able to use that with some tricks to build a custom firmware that exposed all the IO to OpenBK, and ultimately pipe it to homeassistant over MQTT.



This works well now and I can use the switch as a scene controller, for US$10 it is very cheap compared to fancy scene controllers, and has several lights I can use to show which scene is selected. Moreover, I can centrally configure all the automations in home assistant.

You can find the repository here:
https://github.com/no2chem/open-tuyamcu

Maybe one day, when OpenBK supports OTA update of TuyaMCU we will be able to flash this firmware without opening the device when combined with CCtr!

About Author
no2chem wrote 3 posts with rating 2 , helped 1 times. Been with us since 2023 year.

Comments

p.kaczmarek2 10 Mar 2023 22:32

Hello, very good work. How are Nuvoton MCUs programmed? I think we can add MCU firmware update very quickly. The protocol is documented, isn't it? I think I saw the docs somewhere on Tuya site. Btw,... [Read more]

no2chem 10 Mar 2023 22:52

No, unfortunately they are not - I have another treatlife switch (DS01C) which is a completely undocumented BYD microcontroller. You can use an ARM CMSIS adapter. A $6 raspi pico will do it: https://github.com/raspberrypi/picoprobe... [Read more]

p.kaczmarek2 10 Mar 2023 22:56

Another great improvement would be to allow MCU configuration via OBK web panel. Add our packet types to TuyaMCU protocol and just let users select MCU pins and roles from dropdown menu. [Read more]

%}