ESPHome on Tuya CBU based Milfra dimmer

Looking to get ESPHome working on a Tuya CBU module that is used in an inexpensive Milfra smart dimmer switch. Amazon link - Milfra Smart Dimmer Switch. I’m not seeing much documented for this particular Tuya module, and nothing for this module as used in a dimmer switch with a secondary 51 series MCU hanging off of the RX2/TX2 pins. I’ve already got the dimmer torn down, which was simple, just a fair number of screws, and wires attached for programming. I’d prefer not to brick the unit, so I’d like to get a backup of the flash contents before I proceed with any testing, and I’m not clear on how to do that since this is my first attempt at working with a Tuya based device. So far I’ve only worked with setting up custom ESP8266 and ESP32 devices I’ve designed & built where I have full knowledge of the design and and no existing firmware to worry about being able to flash back to the device.

I’ve inspected the main control board of the device (it uses two boards linked by a 2x4 pin header, one for low voltage logic, one for high voltage control) and as best as I can tell visually, the little 51 series MCU controls the dimmer circuitry on the secondary board, as well as the single digit LED display. There are a couple of the GPIO pins on the CBU module connected, and I believe these are for the two buttons. I’ll hopefully have at least a few minutes this evening to probe the buttons and verify which MCU they are connected to and will update once I’m certain.

So far, from the information I’ve managed to piece together, the CBU module is not significantly different from the rest of the BK7231N based modules, so the general information for using Tuya dimmers I would expect should be fairly accurate. My concern would be if there have been any changes to the serial protocol for communicating with the additional MCU versus older units. What I haven’t found much information on is the best way of sniffing this traffic. I do have an old digistump based 16 channel logic analyzer that might still be functional, if low level sniffing the serial data is the only option. I’m experienced and comfortable with working on line level powered devices in the open, but would need to order or build a USB protection board just to be safe. Don’t want to accidentally fry a computer because line voltage accidentally got onto the USB bus

I’d also be happy to collaborate on this if any of the people working on the Tuya firmware wants to. I also have a couple of LED flood light panels I’ll be converting, but I haven’t had a chance to open one of them up yet to see what’s going on inside. As I’m building out my smart home infrastructure, I’m also willing to pick up and teardown new or oddball devices to help increase the range of supported equipment in ESPHome.

If anyone has any information or resources you think might be helpful, or would like to collaborate on this or other devices I have or will have access to, please feel free to reach out. Otherwise, I’ll update here as I make progress in case the information is useful for anyone else.

I’ve used a few Tuya-based dimmers and converted them to Tasmota, but my experience is admittedly limited so perhaps someone with more knowledge can clarify further. That said, typically Tuya-based dimmers use the MCU for everything — controlling the dimmer output as well as handling indicator lights and button controls — hence you see template after template on blakadder with just the Tx and Rx pins in use. You typically cannot “re-program” the buttons on a dimmer because of this. This Zemismart template looks a lot like your Milfra switch so there is a good chance it has the same configuration.

In these cases, your goal is just to get ESPhome to send commands to the MCU, and receive dimming updates (datapoints) from the MCU, to keep HA in sync. It is unlikely the serial protocol has changed, as it’s basically Tuya’s core business to write software interfaces for different companies’ hardware. Here are some examples of dimmers that use the Tuya platform to define a light using just the UART (Tx/Rx) connection to the MCU.

Your first step though it to figure out what kind of WiFi chip is being used. The LibreTiny project has a good list of supported modules that have been incorporated into ESPhome so hopefully your board is on that list. That project also has good resources for reading and writing to backup/flash those boards, which are a little different from the ESP-based chips. Another good resource is Digiblur’s blog post describing flashing a BK-based Treatlife dimmer switch.

Ahh, much appreciated on the additional information! I’d been having difficulty finding reliable information the Tuya based devices. This unit happens to be a CBU module with a BK7231N chip inside. There seems to be more information for older BK7231N based modules, but from what I can tell, the main difference is just the physical format and antenna supported.

I’m running ESPHome natively inside of HA, and do not intend to switch to Tasmota or OpenBeken. Is anyone aware of a device configuration database site similar to blackadder for ESPHome? I found a template for the Sonoff S31 plugs I converted on a forum, which I then heavily modified to add a bunch of extra functionality. I haven’t found a site like blackadder for ESPHome device templates though, and I’m a bit surprised by that.

Note that several BK7231N-based boards are unsupported in LibreTiny / ESPhome, so be sure to make sure to reference the module series/number. If your board is on the list, you should be able to compile ESPhome firmware using the BK72xx as the module type.

The links I included above have ESPhome templates hosted at https://devices.esphome.io but that list is much shorter than blakadder’s.

Edited to add: The ESPhome project page for LibreTiny also links to this registry to check to see if your board is supported by ESPhome. Looks like the CBU module is on both lists.

So, I was able to get ESPHome flashed onto the board, still having some trouble with it though. First and foremost, it never shows up as connected in ESPHome. It does connect to WIFI ok though, and I can access the webpage and logs output. Secondly, once I finally got the Tuya: command working properly, I started getting an “invalid command 0x34” error, so I’m not sure what that is about and I’ve only found a single reference to that error in my searches, but it was for a thermostat requesting weather data from the Tuya cloud, which I’m pretty confident is not what a dimmer switch is doing.

Anyone have any ideas on how to troubleshoot these issues?

Ahh, got it working! Still no idea what the invalid command error is, but it doesn’t appear to affect functionality. Will post the relevant information on the ESPHome devices list.