Reflashing a tuya light to tasmota (and ESPHome)

I recently saw a quite nice looking lamp on amazon that was also very cheap and advertised Wi-Fi and even had addressable LEDs!

After a couple days I received my lamp. To be honest, I was not really impressed by the stupidly large IR remote and the housing of the controller which fell apart. Its just the kind of plastic housing we all know from cheap LED lamps / LED strips.

The awesome remote shipped with the lamp

Here are also some pictures of the LED controller:

Unfortunately, there was no information from the outside what chip it is, so I had to remove the shielding on the Wi-Fi chip.

Closeup of the Wi-Fi chip. It is a BK7231N

After a bit of searching, I found the datasheet including the pin definitions of the module.

This is a image of the module with all pins numbered and the required GPIOs labeled

The original firmware was configured like this:

  • Cold White (GPIO 26 -> Pin 11)
  • Warm White (GPIO 7 -> Pin 9)
  • Addressable LED Data (GPIO 24 -> Pin 12)

However, there was one problem with Openbeken is that it does not support WS2812. Another problem was that for some reason, the lamp did not light up, so I was thinking that maybe ESPHome would just work.

What ended up working is using libretiny together with ESPHome. While I still haven’t found a way to merge both the WS2812 and the CW/WW lights together into one homeassistant lamp, this still was way better than not having the WS2812 working.

Also, if you can remember, I said that Openbeken did not work. I think the reason lays in the export result above! It says „Control Pin (TODO) on P24“. And after looking on the PCB (and also before I got the ESPHome software working) I noticed, that there was a kind of enable circuit for the 20V. Previously I just tried to connect the 20V directly, but then the chip did not boot, not sure why tho.

The final result

Here is the config that I am running right now:

esphome:
  name: ledvance-firmware-hack
  friendly_name: Ledvance Firmware Hack
  on_boot: # this makes it boot correctly
    then:
      - delay: 
          seconds: 1
      - switch.turn_on: en_20v

bk72xx:
  board: cbu

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "foobar123"

ota:
  - platform: esphome
    password: "foobar123"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ledvance-Firmware-Hack"
    password: "foobar123"

captive_portal:

switch:
  - platform: gpio
    name: Enable 20V
    id: en_20v
    pin: P24
    restore_mode: ALWAYS_OFF
    
output:
  - platform: libretiny_pwm
    pin: P26
    frequency: 10000 Hz
    id: cold_white_pwm

  - platform: libretiny_pwm
    pin: P7
    frequency: 10000 Hz
    id: warm_white_pwm

e131:
  method: multicast

light:
  - platform: cwww
    cold_white: cold_white_pwm
    warm_white: warm_white_pwm
    name: "White Light"
    restore_mode: RESTORE_DEFAULT_OFF 
    cold_white_color_temperature: 6500 K
    warm_white_color_temperature: 2700 K

  - platform: beken_spi_led_strip
    rgb_order: RGB
    pin: P16
    num_leds: 10
    chipset: ws2812
    name: "RGB"
    id: rgb
    restore_mode: RESTORE_DEFAULT_OFF
    effects:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_twinkle:
      - addressable_random_twinkle:
      - addressable_fireworks:
      - addressable_flicker:
      - e131:
          universe: 256
          channels: RGB

debug:
  update_interval: 10s

text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version
  - platform: wifi_info
    ip_address:
      id: ip_address
      name: IP Address
  - platform: debug
    device:
      name: Device Info
    reset_reason:
      name: Reset Reason

button:
  - platform: restart
    name: Restart

sensor:
  - platform: debug
    free:
      name: Heap Free
    loop_time:
      name: Loop Time
  - platform: uptime
    name: Uptime