Smart fan

I bought an Arlec smart fan. It has a WR4 wifi module inside, based on an RTL8710BN. These are now supported by esphome.

https://docs.libretiny.eu/docs/platform/realtek-ambz/#flashing

https://community.home-assistant.io/t/arlec-grid-connect-ceiling-fans/261127/67

https://esphome.io/components/libretiny.html

https://developer.tuya.com/en/docs/iot/wifiwr4module?id=K9605tvu78p3e

20231030-112019.jpeg

20231030-033719.jpeg

esphome:
  name: fan-1
  friendly_name: Sam's Room Fan

rtl87xx:
  board: generic-rtl8710bn-2mb-788k

# Enable Home Assistant API
api:
  encryption:
    key: "<snip>"

ota:
  password: "<snip>"

wifi:
  ssid: !secret wifi_ssid_2
  password: !secret wifi_password_2

uart:
  rx_pin: GPIO18
  tx_pin: GPIO23
  baud_rate: 9600
tuya:

fan:
  - platform: "tuya"
    name: "Speed"
    switch_datapoint: 1
    speed_datapoint: 3
    direction_datapoint: 4
    speed_count: 6


light:
  - platform: "tuya"
    name: "Light"
    switch_datapoint: 9
    dimmer_datapoint: 10
    min_value: 0
    max_value: 100
    color_temperature_datapoint: 11
    color_temperature_max_value: 100
    cold_white_color_temperature: 150 mireds
    warm_white_color_temperature: 400 mireds

Initial flashing done with a USB-TTL serial adaptor using the wiring diagram shown above and ltchiptool. I took a backup of the stock firmware with

ltchiptool flash read ambz stock.bin

then I used esphome to generate the uf2 file and flashed it using

ltchiptool flash write <filename>.uf2

Works mostly perfectly. OTA updates via wifi only work occasionally, perhaps inside a 30-60 second window after the RTL chip powers on. It takes a fair bit of bouncing the power and retrying the connection to get it to stick.