Continuing the Tuya device hacking series, this post describes how to flash the Tuya Mini Smart Switch with ESPHome firmware. I picked up a few of these switches on sale for only a few dollars each, found that each of them are slightly different internally, despite looking almost exactly the same on the outside. This post covers the first of the three different versions I have, but I’m sure there are more out there.
Smart Switch Version 1
I looked up the pinout of the BK7231N qfn32 chip, and found that the pins are labeled on the chip itself. I was able to identify the following pins:
1 | # Read firmware from device three times to ensure we have a good copy |
The firmware was confirmed good, I wanted to try flashing it with ESPHome, as they have recently added support for the BK7231N chip. We will need configuration for the ESPHome firmware, which thankfully can be done by analyzing the firmware we just read from the device. Our new friend ltchiputil can do this, thanks to the “UPK2ESPHome” plugin. This can be done through the GUI, or from the command line:
1 | ltchiptool plugin upk2esphome firmware mini-smart-switch-num1.bin |
Which results in the following ESPHome configuration:
1 | esphome: |
With some minor adjustments, I compiled a new firmware using ESPHome, and flashed it to the device. The device booted up, and I was able to control the relay using the switch in Home Assistant without any issues. The physical switch also worked as expected, and the LED on the device was also functional. The device acts exactly as it did before, but now we have full control over it.
Smart Switch Version 2
Repeating steps…
1 | # Read firmware from device until I had two good copies |
1 | esphome: |
Smart Switch Version 3
On inspection, I found it to have the ZT2S Tuya module, which, unfortunately is a Zigbee module, and not a WiFi module. Unfortunately, this means that this device cannot be flashed with ESPHome, and will not be covered in this post. I could replace the module with a small ESP8266 module, but that’s currently not worth the effort for me.
https://developer.tuya.com/en/docs/iot/zt2s-module-datasheet?id=Kas9gdtath9p0
Ref: