Contents
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.
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:
After cleaning the solder pads, I replaced it with an ESP-12F module and soldered a few wires as follows:
- Black: GND, to PIN9 or the negative terminal of battery compartment
- White: Vcc (+3.3 V), to PIN8
- Gray: UART RxD, to PIN15
- 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.
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:
Software
ESPHome configuration example:
substitutions:
device_name: 'Door Sensor'
esphome:
name: door-sensor
comment: 'Living room door sensor'
esp8266:
board: esp12e
restore_from_flash: false
preferences:
flash_write_interval: 24h
logger:
level: WARN
# baud_rate: 115200
wifi:
fast_connect: true
networks:
- ssid: !secret wifi_ssid
bssid: !secret wifi_bssid
password: !secret wifi_password
domain: !secret domain_name
api:
ota:
password: !secret ota_password
button:
# for hard restart
- platform: restart
id: restart_button
name: 'Restart ${device_name}'
entity_category: diagnostic
light:
- platform: status_led # use the onboard LED as status indicator
id: led
pin: 13
internal: true
binary_sensor:
- platform: gpio
id: living_room_door
name: 'Living Room Door'
pin:
number: 5 # connected to the reed switch
inverted: true # invert the state in HASS (door closed is OFF, open is ON)
device_class: door # specify HASS device class (make OFF/ON => Closed/Open)
on_state:
then:
- light.turn_on: # blink the status LED once when opening/closing the door
id: led
flash_length: 500ms
publish_initial_state: true
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.
0 Comments