Elektroda.com
Elektroda.com
X
  • 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):
    Open-TuyaMCU for Nuvoton MCU

    Open-TuyaMCU for Nuvoton MCU

    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.

    Open-TuyaMCU for Nuvoton MCU

    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!

    Cool? Ranking DIY
    About Author
    no2chem
    Level 2  
    Offline 
    no2chem wrote 3 posts with rating 1, helped 1 times. Been with us since 2023 year.
  • #2
    p.kaczmarek2
    Moderator Smart Home
    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, are all TuyaMCU microcontroller Nuvotron? I am asking because there are many devices where TuyaMCU microcontroller has no marking.
  • #3
    no2chem
    Level 2  
    p.kaczmarek2 wrote:
    Btw, are all TuyaMCU microcontroller Nuvoton? I am asking because there are many devices where TuyaMCU microcontroller has no marking.


    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 - pretty handy thing to have around.

    I think the MCU firmware update is documented. My open TuyaMCU firmware does not handle the updates yet though.
  • #4
    p.kaczmarek2
    Moderator Smart Home
    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.