Zry.IO

Back

Background

Since it’s not that safe in Barcelona and the fact that students with regular schedules are prone to become targets of break-in, so I wanted to install a magnetic door sensor in my apartment. After searching through the Tasmota supported device list, I found a suitable model called “TY01” and purchased it from AliExpress for €5.76 with free shipping.

Hardware

After I disassembled the sensor, I found that the Wi-Fi module was labeled “CB3S” and discovered that it was a Tuya module based on the Beken BK7231 series ARM SoC, I stepped on a landmine from Tuya again.

before

Luckily, the PCB was small and easy to take out, and I was able to easily desolder the module by heating it over an electric stove:

wifi-module-removed

After cleaning the solder pads, I replaced it with an ESP-12F module and soldered a few wires as follows:

  1. Black: GND, to PIN9 or the negative terminal of battery compartment
  2. White: Vcc (+3.3 V), to PIN8
  3. Gray: UART RxD, to PIN15
  4. Purple: UART TxD, to PIN16

Also short PIN12 (GPIO0) and PIN9 or the EMI shielding (GND), then short PIN1 (RST) and the EMI shielding with tweezers and release, to reset the ESP module and enter flashing mode.

testing

At first, I used the original GPIO7 as the input pin, but because this pin is connected to the internal flash on the ESP8266 module, it prevented me from flashing the device. Therefore, I had to fly-wire the reed switch to an unused GPIO (such as GPIO5) and cut the trace to GPIO7.

In addition, the Tuya CB3S module does not require to pull up the ENABLE pin to run, and there is no circuit for that on the PCB, so I had to solder an external pull-up resistor to Vcc. Finally, the modified sensor looked like this:

done

Software

ESPHome configuration example:

After testing the sensor, I found that it was not working properly. Upon analyzing the circuit, I found that the pull-down resistor for the reed switch was too large (10 MΩ), so I replaced it with a 10 kΩ resistor, and now the sensor is working properly.

reed-pulldown-resistor

Tuya TY01 Door & Window Contact Sensor
https://zry.io/smart-home/tuya-ty01-door-window-contact-sensor
Author zry98
Published at January 31, 2022
Copyright CC BY-NC-SA 4.0