Thought I would take a few minutes to document the process I went through along with pulling together various sources of information to flash a “Smart Wi-Fi Light Dimmer Switch” available in various outlets. I purchased mine from Amazon. Picture of the device below:
Anyone finding this will likely already know what ESPHome is, and quite possibly this device so will not go into what and why I use these in this post, rather than focus on the steps.
This device is an exciting addition to my smart home, as it replaces a recently failed 433Mhz Nexa dimmable socket, which I am using for a my terrarium halogen heat lamp automation, so it’s not something I can replace with a dimmable LED bulb as I need the heat source! Have been waiting with anticipation for someone to bring a Wi-Fi dimmer to the market, and this fits perfectly into my terrarium solution.
With all these smart home devices, I never even configure the Wi-Fi on them, or connect them to the Tuya / Smartlife cloud, the first thing I do is flash them to ESPHome so I have full local control over them. This one was surprisingly straightforward given recent innovations, so I applaud the teams at ESPHome and Tasmota / VTRUST for their hard work in getting this all working in an open and easy to use manner.
Onto the steps!
The process I used for this, was to not flash directly on the ESP module, but to deliver my custom firmware from ESPHome over-the-air (OTA). I was mainly being lazy so I did not have to trace or solder connections. My laziness paid off this time fortunately!
Create ESPHome Base Firmware Package
First step, was to create the base firmware file to flash over-the-air to the dimmer switch. I initially just started with my network information so I could then go back and update the config directly from ESPHome later. The config file looked like this:
upper_devicename: Smart Dimmer
# Enable logging
# Enable Home Assistant API
I then did a “Compile” from ESPHome context menu, then downloaded the binary file so I could upload this using the conversion step below.
Convert device to ESPHome using Tuya Convert
This step will detail how I went about flashing the switch using Tuya Convert to flash my initial firmware file over-the-air. Makes flashing these devices simple as it saves opening up the device and using a serial adapter to flash the ESP module over serial.
To do this in the simplest of manners, I used a spare Raspberry Pi 4 to perform the firmware upload. All the details on how to setup and flash the ESPHome firmware is on the Tuya Convert site.
Once you have performed the installation step. Transfer your firmware binary file you saved earlier to your device you are using to perform the flashing function. I used SCP from my laptop to the Raspberry Pi, placing the .bin file in ~/tuya-convert/files
Once that’s done continue with the flashing process per the Tuya Convert instructions and all being well you should have your base ESPHome firmware loaded onto the Smart Dimmer ready to configure!
Build out ESPHome Tuya Configuration
Now we have the base firmware on, we can enhance this to configure ESPHome to interact with the dimmer functions. There was a couple of sites I’ll link below which helped me get to this working configuration – Thanks to those authors for their analysis in this!
Onto the actual configuration – The ESPHome documentation has most of the information, but the second link provided the vital information around the GPIO pins used for the serial communication with the MCU that controls the dimmer.
The final part of the YAML configuration provided above is:
- platform: "tuya"
From the documentation for Tasmota, I had to flip the RX/TX in ESPHome. The debug logs on the ESPHome page showed the datapoints that was detected by the firmware – which I entered here.
Once I uploaded this firmware, and added to Home-Assistant, it worked perfectly! Now want to look at getting some more Wi-Fi switch modules where I can then finally be rid of my remaining two 433Mhz Modules, and the very unreliable Telldus Live service that controls them. I’ll finally be free of any cloud services.