May 2023 update
I’m all out of boards. For new Arlec fan owners, I’d recommend checking out:
- LocalTuya, local control of the fans without any hardware/firmware modification.
- Flashing LibreTiny ESPHome firmware onto the WR4 module (RTL8710BN based).
- Hopefully also compatible with my patch to correct the colour temp / brightness curve
- Others in this thread who have made their own boards
Original post
Hey all,
I’ve recently spent some time trying to integrate my Arlec ceiling fan with Home Assistant. The original Tuya WiFi module isn’t ESP based, so Home Assistant integration via ESPHome was achieved by designing a simple replacement WiFi module. I introduced this project with some more background over in the Australian electrically certified thread: Australia - Electrically Certified Hardware - #2707 by rymo Others have expressed interest, so I think it’s time to start a dedicated thread to keep track of things.
Compatible fans
All of this was tested with the DCF5242HA “Smart Boston” - which includes a dimmable CCT light. The cheaper fan-only models reportedly have the same WiFi module, so I hope that this procedure also applies to those.
Disassembly and reverse engineering
The controller is easy to open after disconnecting external cables - 2 screws on the bottom and 2 plastic clips on the sides. The original WiFi module pops right out. Note that the mainboard has a 10 pin header while the WiFi module only has 9 pins - the module should be installed closer to the buzzer.
The pinout of the original WiFi module is helpfully marked on the reverse side - unfortunately I only discovered this after tediously buzzing out each pin and cross-referencing with the Tuya WR4 datasheet. I’m unsure when RST is brought low by the MCU, so I’ve just ignored it. UART TX from the MCU is surprisingly 5V, which is an issue as the ESP8266 is not 5V tolerant. This caused stability issues in my original testing until I narrowed it down with the oscilloscope. The ESP8266 UART RX pin has an always-on 3.3V pull-up, so the simple solution here is to use a diode. When fan TX is low, the diode is forward biased and ESP RX is pulled down to ~0.7V through the diode - low enough to be considered logic low by the ESP. When fan TX is high, the diode is reverse biased so no current flows and the ESP’s internal resistor pulls up to a safe 3.3V.
Now’s probably a good time to mention an IMPORTANT SAFETY NOTE, which is that the fan controller electronics are not electrically isolated and thus always referenced to MAINS VOLTAGE. You should NEVER TOUCH OR INTERFACE WITH THE FAN CONTROLER WHILE CONNECTED TO MAINS POWER, and you should also SAFELY DISCHARGE CAPACITORS before touching anything on the control board. Oh, and test your RCDs - they could save your life.
In order to probe the board with an oscilloscope to figure out the stability issues I had to use a dodgy un-earthed travel adaptor to isolate the scope. Never do this without knowing exactly what you’re doing, as this meant that the exposed metal parts of the scope were at mains voltage while I was working!
Replacement board design
In the end, I came up with the following dead simple schematic for the replacement board, based on my prototype consisting of an ESP-01 and a breadboard. I don’t know how many decoupling capacitors are really needed - I’ve modelled this aspect on the original module. In practice I’ve left the ceramic caps unpopulated because I’m bad at manipulating tiny surface mount parts and it seems to work anyway
Mechanically, the board mimics the original - using an ESP-07S module in place of the Tuya WR4. Everything was designed in KiCad, which was a straightforward and pleasant experience as someone who hasn’t designed a board since using Altium at uni years ago. Project files here: GitHub - rmounce/ArlecFanESP-PCB
I got the boards fabricated by PCBWay based on a couple of recommendations from professional EEs. The total cost for 5 panels of 10 boards each was 49 USD, most of which went towards shipping and paying them to panelise the boards. To my untrained eye I think they did a nice job, and even threw in a cute little xmas tree board with colour changing LEDs.
Unfortunately, I underestimated the extra length of the ESP-07S module and included an unnecessary margin between the pin header and the module - meaning the board only fits into the enclosure if it is on a slight angle resting on the 433MHz module. For the next next batch of boards I would swap to an 8 pin header and shorten the board by 3mm for the ESP-07S to fit snugly between the big cap and the 433MHz module. To get the current boards to fit more comfortably I’ve only soldered on the first 6 pins that are actually used, this way the overall connection is looser and easier to angle as necessary.
The above picture is after wedging everything into the enclosure, note how the WiFi module is pressing against the cap on the 433MHz board. I’m not keen on this… but it hasn’t caused any issues so far.
Assembling and flashing
The bill of materials for each board I assembled is nice and short
- 1x ESP-07S module: https://www.ebay.com.au/itm/ESP-07S-WiFi-Module-ESP8266-ESP-12-ESP12F-ESP12-UFL-U-FL-IPX-Arduino-SYDNEY-/152707561759
- 2.0mm pitch pin header (6 pins is sufficient): 1pc ~ 10pcs 2.0mm Spacing Straight Male Single Row 40 Pin Header Breakable 2mm | eBay
- 1x 1N4148 signal diode: 1N4148/1N914 Signal Diode - Pk.5 | Jaycar Electronics
- 1x 220uF 10V electrolytic cap: https://www.jaycar.com.au/220uf-10vdc-electrolytic-rb-capacitor/p/RE6157
After assembly, I flashed the board by tacking fine wires onto the pads. I used esptool.py to flash my pre-baked ESPHome image - however you may find it more convenient to use e.g. Tasmotizer to flash a generic Tasmota image and then flash ESPHome over the air.
GND - GND
VCC - 3.3V
IO0 - GND (for flashing)
ESP TXD0 - USB UART RX
ESP RXD0 - USB UART TX
Once flashed I just inserted the new module - connected the antenna and carefully snapped the plastic enclosure back together. Don’t use too much force or you could damage the 433MHz module.
ESPHome config
In conjunction with a couple of ESPHome patches to unlock the full functionality of these fans, the below config “just works” in conjunction with Home Assistant.
Updated May 2023
substitutions:
device_name: "arlecfan1"
friendly_name: "Arlec Fan 1"
esphome:
name: "${device_name}"
esp8266:
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: '${device_name}'
password: !secret fallback_password
captive_portal:
# Enable Home Assistant API
api:
ota:
logger:
# Disable UART logging as these pins are used for Tuya MCU comms
baud_rate: 0
uart:
rx_pin: GPIO03
tx_pin: GPIO01
baud_rate: 9600
tuya:
# DP1 Fan On/Off
# DP3 Fan speed 0=lowest, 5=highest
# DP4 Fan direction 0=summer, 1=winter
# DP9 Light On/Off
# DP10 Light brightness 0=min, 100=max
# DP11 Light temperature 0=cool, 100=warm
# DP102 ?
# DP103 ? Timer value, 0=off, 1=1h, (2=2h?), 3=4h, 4=8h
fan:
- platform: "tuya"
name: "${friendly_name}"
switch_datapoint: 1
speed_datapoint: 3
speed_count: 6
direction_datapoint: 4
# Optional patch to correct colour temperature / brightness curve
external_components:
- source: github://rmounce/esphome@tuya-temp-correct
components: [ tuya ]
light:
- platform: "tuya"
name: "${friendly_name}"
switch_datapoint: 9
dimmer_datapoint: 10
min_value: 2
max_value: 100
color_temperature_datapoint: 11
color_temperature_max_value: 100
# 1000000 / 5700 K = 175.43
cold_white_color_temperature: 175 mireds
# 1000000 / 3000 K = 333.33
warm_white_color_temperature: 333 mireds
Getting a board
I’m not fully across this whole eCommerce thing, nor business for that matter! If this becomes popular I’ll try listing on Tindie? In the meantime in exchange for each $10 AUD donated (plus $10 for postage) I’ll happily post you a board within Australia, and even throw in a cap (of the electrolytic variety), a length of pin header, and a diode! Strictly BYOESP. Send me a DM to arrange.
-Ryan