Custom firmware ESPHome-Xiaomi_bslamp2

Thank you to @mmakaay for the amazing work on this project. It was very satisfying to get the lamp to work with ESPHome. In case this is useful to others, I am sharing my experience in getting it to work based on the specific tools I used and it also seems some things have changed since the original instructions were written.

  1. The instructions for connecting the serial adaptor to the lamp are great. Being the first time I have done this, I found it easiest to put a small blob of solder on the end of the exposed wire, hold that end of the wire over the connection point on the lamp and touch the solder blob on the wire with the soldering iron (thereby not requiring a third arm).

  2. I could not use the ESPHome Flasher software as my Mac gave a security error when trying to run it. I also could not use the ESPHome browser in directly in HA as I do not have a local HTTPS connection (this does not seem that simple to set up). I therefore downloaded the ESPHome firmware and uploaded it using ESPHome Web directly from my computer over the serial adaptor.

  3. After installing the ESPHome Add On in Home Assistant, create a new ESPHome device, give it a name, next, select ESP32, skip, download the YAML config file for this new device (so you can refer to it). Edit the YAML file in HA replacing the contents with the example.yaml changing some of the values based on the initial device YAML file downloaded e.g. api (you now have to use the encryption option instead of a password), ota, add the ap option and I also added the webserver option. Save.

  4. Click on the 3 dots next to the ESPHome device in HA and select “Install”. Select the Manual download option. Once compiled (this this can take a while the first time), select the factory format to download the firmware.

  5. Add external power to the lamp with the GPIO0 pin connected to ground (to put it in flashing mode). Connect to the lamp from your computer over the serial adaptor and upload the firmware.factory.bin downloaded above.

  6. Remove external power from the lamp, disconnect the GPIO0 pin from ground (to prevent the ESP32 from going back into flashing mode) and add back external power to the lamp. Check the log files on the ESPHome Web interface.

Some additional notes:

  • I initially followed the instructions provided on the ESPHome devices website which for example references a main branch example.yaml from September 2021. Be sure to use the latest example.yaml from the dev branch.

  • The serial adaptor I used: USB to Serial Adapter CH340G - 5V/3.3V. With the supplied jumper you can configure the module for 5V or 3.3V. Without the jumper, the module is automatically powered with 3.3V. As we want 3.3V, I removed the yellow jumper.

  • As I needed to connect both GND and GPIO0 on the lamp to the ground on the serial adaptor, I used a breadboard to connect the 3 wires together.

Nice write-up and a cool picture of the setup @AndyHiggins !! Always fun to see in how many ways the PCB can be hooked up for flashing :smiley:

Good point about the encryption key, which is now mandatory. Based on a problem report, I found that the fast random light effect can result in a lamp reset after a while (which worked flawlessly in earlier releases of ESPHome with the same firmware, so suspecting some memory leak or so in the more recent ESPHome code). when I start working on cracking that issue, I will also give the configuration files some love and attention to be up-to-date with ESPHome.

Enjoy the lamp!

1 Like