logo elektroda
logo elektroda
X
logo elektroda

Door Sensor D06 (BK7231N/CB3S) with TuyaMCU (DeepSleep)

CMY 6213 49
ADVERTISEMENT
  • #31 21354464
    spin55
    Level 17  
    If you try to control Q1 from P26 it will never work, because if you set P26 to Low Q1 will interrupt GND and will never wake up until you remove and reinsert the batteries. Please note that the firmware is now on this CB3S module and needs to be permanently powered. That is why the PinDeepSleep command is used, which is already integrated into the autoexec drivers. It is this command that lowers consumption to the minimum in Sleep state.

    To be able to control GND with Q1 you could do it whit Gate is connected to the output of U3 (Hall effect transistor). This way you could send the alert via MQTT to Home Assistant, but when you close the door again you could not send the information because Q1 would cut off GND.

    And if you open the door and close it again quickly you wouldn't even have time to send the notification to HA.

    Electronic schematic showing connections between CB3S module, BK7231N chip, MOSFET transistor, and resistor.
  • ADVERTISEMENT
  • #32 21354680
    daherbst85
    Level 4  
    spin55 wrote:
    If you try to control Q1 from P26 it will never work, because if you set P26 to Low Q1 will interrupt GND and will never wake up until you remove and reinsert the batteries.


    Right, that was the idea, a suicide switch ;-)
    Once the battery is critically low the door sensor should commit suicide until the batteries are exchanged. Underpowered electronics tend to do weird things and should be cut from power permanently. Of course this requires that P26 would be high during deep sleep (not sure whether that's possible or how it behaves in deep sleep - that might be the crux, if it stays high during deep sleep Q1 would maintain the GND connection).

    Anyhow, you raised some valid points and I'll give it a shot.
  • #33 21357822
    ghanatracking
    Level 2  
    Hi,
    I'm relativly new to openbeken, so might be my question is answered somewhere.
    I have this sensor (ok, the water sensor version), flashed to openbeken. Set it up to connect to my mqtt & Homeassistant. It's working so far, but I don't get any sensors, so I don't get the information about open / close.
    Screenshot of an interface showing device information for BK7231N from Beken Corporation with firmware 1.17.739 and an MQTT icon.

    I have another door sensor, and another water sensor, where it's working as expected.
  • #34 21358109
    daherbst85
    Level 4  
    Have you configured mqtt in your HA configuration.yaml?

    This is what I use for the window/door sensor:
    
    mqtt: 
      - binary_sensor:
        # Window and Door Sensors using OpenBK
        - unique_id: "BK7231N_01_binary_sensor_1"
          name: "BK7231N_01_windoor"
          state_topic: "BKwindoors/BK7231N_01/1/get"
          qos: 1
          icon: "mdi:door"
          payload_on: "1"
          payload_off: "0"
          device_class: door
    

    I assume that in your case HA runs a regular mqtt broker (I am running a broker on a separate server, outside of HA).
    Of course you need to configure a user, password, and permissions for HA to access the topic.
    After adding this to your configuration.yaml, you have to reload the yaml. Then you should be able to find the sensor (binary_sensor.bk7231n_01_windoor).

    In the OpenBK web interface, you want to set the retain flag.
  • ADVERTISEMENT
  • #35 21361558
    plekke
    Level 4  
    Hand-drawn electronic circuit diagram with a module on a piece of paper.


    my 2 cent , i made this schematic , and the i dicovered this topic ( incl schematics already made )
    nevertheless , maye i can be added and also be usefull
  • ADVERTISEMENT
  • #36 21365781
    ghanatracking
    Level 2  
    >>21358109
    I have homeassistant with embedded mosquitto.
    View of water sensor temperature details in Home Assistant.

    I have never used config.yaml to edit devices. Do you have therefore an idea how to edit the already existing device? Would "watersensor2" be the unique id, when this is one othe the topics "sensor.watersensor2_temperature"?
  • #37 21370467
    meillagimeil
    Level 2  
    What do you think about replacing tuya mcu with attiny85? The vcc/gnd are not in the same place, but retracing 2-3 connection is nothing compared to all the wires needed for no tuya solution.
  • #38 21379680
    ssllaawweekk
    Level 20  
    I would like to replace the hall sensor in the sensor with the original software with a simple NO button/switch. Is there a ready solution for this? What signals does the hall sensor communicate with the MCU? I read that the sensor output is of the push-pull type.
  • #39 21392216
    ssllaawweekk
    Level 20  
    ssllaawweekk wrote:
    I would like to replace the hall sensor in the sensor with the original software with a simple NO button/switch. Is there a ready solution for this? What signals does the hall sensor communicate with the MCU? I read that the sensor output is of the push-pull type.

    I have broken the connection between the Hall sensor and the MCU. By now connecting the sensor input on the MCU to +3V or 0V via a 5kohm resistor I get the ability to set open/closed states.
    If this is not the best solution - please comment.
  • #40 21442587
    meillagimeil
    Level 2  
    So, is there a final working solution? That is the wiring solution? I'm confused.
  • ADVERTISEMENT
  • #41 21453622
    ssllaawweekk
    Level 20  
    I've been lacking the time to finish this project lately but I'll try this week.
  • #42 21474825
    ssllaawweekk
    Level 20  
    I currently have the circuit I needed assembled. I have an external NO button with which I force the state change from open to closed. In my circuit, the input for the hall sensor on the MCU is connected to the BAT+ pin via a 10kohm resistor. Of course, the signal from the hall sensor is interrupted and does not reach the MCU. A NO mono-stable contact is plugged in between the aforementioned input in the MCU and the BAT- pin. When I press the button I get the message: Door Sensor Close, and when I let go: Door Sensor Open. I am currently testing the battery life with this solution and in the future I still need to find a way to properly mount the contact in the lock because that is the goal.
  • #43 21476701
    p.kaczmarek2
    Moderator Smart Home
    @ssllaawweekk you've done rather well. From what I gather, the role of the DoorSensorWithDeepSleep pin, has an internal pull up resistor, so all you need is a contact shorting it to ground and then the whole thing should work properly.
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/ioRoles.md
    I didn't go that far into those Tuya sensors based on the Hall sensor, but there the DSEdge setting was still needed: https://www.elektroda.com/rtvforum/find.php?q=DSEdge

    Well, but that's in OBK, as long as you have the original software, it should work from the get go....
    Helpful post? Buy me a coffee.
  • #44 21477804
    ssllaawweekk
    Level 20  
    >>21476701 .
    I use the original software because its functionality is sufficient for me.
    I added a pull-up resistor just in case.
  • #45 21530581
    sta_rob
    Level 1  
    Hi,
    I'm new to this forum and to OpenBeken so please bare with me. I have a ZY-D02 door sensor and installed Openbeken on it. I can connect through WiFi and configure it but it does not work as expected. I followed this thread https://www.elektroda.com/rtvforum/topic3914412.html and created the autoexec.bat with the content below but I have issues:

    - The MCU does not wake the Wifi chip when using the magnet
    - There is no state change for channel 0 when attaching/detaching the magnet

    So I realized that there is a difference between a D06 and a D02 sensor. It seems that to make D02 work the MCU needs to be removed and some wires need to be added. Is this required or does OB also support this board with the MCU installed?

    Thanks, Robert

    autoexec.bat:

    startDriver TuyaMCU
    startDriver tmSensor

    // may be needed, depends on device
    //tuyaMcu_setBaudRate 115200

    // map dpID 1 to channel 1
    linkTuyaMCUOutputToChannel 1 val 1
    setChannelType 1 OpenClosed

    // map dpID 3 to channel 3
    linkTuyaMCUOutputToChannel 3 val 3
    setChannelType 3 Custom
  • #46 21591965
    GAAD
    Level 17  
    Hi.
    I removed the MCU from my sensor and made the connections as described. The sensor works very nice but HA does not detect it like all OBK devices in MQTT.

    On the sensor page this info:
    Screenshot showing the web interface of a sensor with a list of active MQTT and WiFi configuration flags. .

    Flags enabled:
    Flag 2 - [MQTT] Broadcast self state every N (def: 60) seconds (delay configurable by 'mqtt_broadcastInterval' and 'mqtt_broadcastItemsPerSec' commands)
    Flag 10 - [MQTT] Broadcast self state on MQTT connect
    Flag 27 - [HASS] Invoke HomeAssistant discovery on change to ip address, configuration
    Flag 37 - [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)
    Flag 51 - [WiFi] (RTL/BK) Enhanced fast connect by saving AP data to flash (preferable with Flag 37 & static ip). Quick reset 3 times to connect normally

    As I wrote earlier the sensor connects very fast, goes into deepsleep, when you move the magnet it wakes up the LED blinks once - the page refreshes there is a message that it has connected but you can't see it in the MQTT devices. Am I forgetting something? So far, always after clicking "Start Home Assistant Discovery" the device appeared in HA.
  • #47 21591992
    p.kaczmarek2
    Moderator Smart Home
    So the HA is not receiving Discovery? Maybe the sensor falls asleep before it has time to send it.
    Helpful post? Buy me a coffee.
  • #48 21592390
    GAAD
    Level 17  
    The logs show that it is sending:

    
    Info:MQTT:Channel has changed! Publishing 1 to channel 1 
    Info:MQTT:Publishing val 1 to obk535A5B2C/1/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/1/get
    Info:MQTT:Queued topic=obk535A5B2C/1/get, 1 items in queue
    Info:MQTT:Publishing val 1 to obk535A5B2C/1/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/1/get
    Info:MQTT:Publishing val 2400 to obk535A5B2C/voltage/get retain=0
    Info:MQTT:Publishing val 60 to obk535A5B2C/battery/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/voltage/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/battery/get
    :MQTT:MQTT_RegisterCallback called for bT bekens_n/ subT bekens_n/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/obk535A5B2C/ subT cmnd/obk535A5B2C/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/bekens_n/ subT cmnd/bekens_n/+
    Info:MQTT:MQTT_RegisterCallback called for bT obk535A5B2C/ subT obk535A5B2C/+/get
    Info:CMD:CMD_StartScript: started @startup at the beginning
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:CMD:Battery Setup : Min 1500.000000 Max 3000.000000 Vref 2400.000000 adcbits 4096.000000 vdivider 1.000000
    Info:CMD:Battery Cycle : Measurement will run every 4 seconds
    Info:EVENT:CMD_AddEventHandler: added OnHold with cmd DSTime 2400
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_DISCONNECTED - 2
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_DISCONNECTED - 2
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName mqtt
    mqtt_pass ********
    mqtt_clientID obk535A5B2C
    mqtt_host 192.168.1.253:1883
    Info:MQTT:Queued topic=obk535A5B2C/1/get, 1 items in queue
    Info:MAIN:Time 1, idle 196684/s, free 73040, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:HA discovery is scheduled, but MQTT connection is not present yet
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to obk535A5B2C/+/set
    Info:MQTT:mqtt_subscribed to bekens_n/+/set
    Info:MQTT:mqtt_subscribed to cmnd/obk535A5B2C/+
    Info:MQTT:mqtt_subscribed to cmnd/bekens_n/+
    Info:MQTT:mqtt_subscribed to obk535A5B2C/+/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/voltage/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/battery/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/1/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/4/get
    Info:MQTT:Publishing val Drzwi_garaż to obk535A5B2C/host retain=0
    Info:MQTT:Publishing val 0 to obk535A5B2C/1/get retain=0
    Info:DRV:DRV_BATTERY : Measure Battery volt en perc
    Info:MQTT:Publishing val 2400 to obk535A5B2C/voltage/get retain=0
    Info:MQTT:Publishing val 60 to obk535A5B2C/battery/get retain=0
    Info:DRV:DRV_BATTERY : battery voltage : 2400.000000 and percentage 60.000003%
    Info:MAIN:Time 2, idle 175933/s, free 72976, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Will do request HA discovery now.
    Info:HTTP:HASS counts: 0 rels, 0 pwms, 1 inps, 0 excluded
    I
    Info:MAIN:Time 3, idle 155163/s, free 57872, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val c0:f8:53:5a:5b:2c to obk535A5B2C/mac retain=0
    Info:MQTT:Publishing val (340 bytes) to homeassistant/sensor/Drzwi_garaż_temp/config retain=1
    Info:MQTT:Publishing val (337 bytes) to homeassistant/sensor/Drzwi_garaż_rssi/config retain=1
    Info:MQTT:Publishing val (339 bytes) to homeassistant/sensor/Drzwi_garaż_uptime/config retain=1
    Info:MAIN:Time 4, idle 176475/s, free 59152, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val (266 bytes) to homeassistant/sensor/Drzwi_garaż_build/config retain=1
    Info:MQTT:Publishing val (297 bytes) to homeassistant/sensor/Drzwi_garaż_ssid/config retain=1
    Info:MQTT:Publishing val (281 bytes) to homeassistant/sensor/Drzwi_garaż_ip/config retain=1
    Info:MAIN:Time 5, idle 177865/s, free 50016, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to obk535A5B2C/+/set
    Info:MQTT:mqtt_subscribed to bekens_n/+/set
    Info:MQTT:mqtt_subscribed to cmnd/obk535A5B2C/+
    Info:MQTT:mqtt_subscribed to cmnd/bekens_n/+
    Info:MQTT:mqtt_subscribed to obk535A5B2C/+/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/voltage/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/battery/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/1/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/4/get
    Info:MQTT:Publishing val Drzwi_garaż to obk535A5B2C/host retain=0
    Info:MQTT:Publishing val 1 to obk535A5B2C/1/get retain=0
    Info:DRV:DRV_BATTERY : Measure Battery volt en perc
    Info:MQTT:Publishing val 2400 to obk535A5B2C/voltage/get retain=0
    Info:MQTT:Publishing val 60 to obk535A5B2C/battery/get retain=0
    Info:DRV:DRV_BATTERY : battery voltage : 2400.000000 and percentage 60.000003%
    Info:MAIN:Time 2, idle 177884/s, free 72744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MAIN:Will do request HA discovery now.
    Info:HTTP:HASS counts: 0 rels, 0 pwms, 1 inps, 0 excluded
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/1/get
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_battery_0/config, 1 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_voltage_0/config, 2 items in queue
    Info:MQTT:Queued topic=homeassistant/binary_sensor/Drzwi_garaż_binary_sensor_1/config, 3 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_temp/config, 4 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_rssi/config, 5 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_uptime/config, 6 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_build/config, 7 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_ssid/config, 8 items in queue
    Info:MQTT:Queued topic=homeassistant/sensor/Drzwi_garaż_ip/config, 9 items in queue
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/voltage/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obk535A5B2C/battery/get
    Info:MQTT:Publishing val OpenBK7231N 1.18.127 Jun 26 2025 14:00:27 to obk535A5B2C/build retain=0
    Info:MQTT:Publishing val (311 bytes) to homeassistant/sensor/Drzwi_garaż_battery_0/config retain=1
    Info:MQTT:Publishing val (312 bytes) to homeassistant/sensor/Drzwi_garaż_voltage_0/config retain=1
    Info:MQTT:Publishing val (266 bytes) to homeassistant/binary_sensor/Drzwi_garaż_binary_sensor_1/config retain=1
    Info:MAIN:Time 3, idle 155986/s, free 57872, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val c0:f8:53:5a:5b:2c to obk535A5B2C/mac retain=0
    Info:MQTT:Publishing val (340 bytes) to homeassistant/sensor/Drzwi_garaż_temp/config retain=1
    Info:MQTT:Publishing val (337 bytes) to homeassistant/sensor/Drzwi_garaż_rssi/config retain=1
    Info:MQTT:Publishing val (339 bytes) to homeassistant/sensor/Drzwi_garaż_uptime/config retain=1
    Info:MAIN:Time 4, idle 180085/s, free 57776, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val (266 bytes) to homeassistant/sensor/Drzwi_garaż_build/config retain=1
    Info:MQTT:Publishing val (297 bytes) to homeassistant/sensor/Drzwi_garaż_ssid/config retain=1
    Info:MQTT:Publishing val (281 bytes) to homeassistant/sensor/Drzwi_garaż_ip/config retain=1
    
    .

    Maybe it is an HA poblem.
    If you can see it because there are errors and warnings in the log.
    It connects instantly and the sensor works very fast.
  • #49 21592394
    p.kaczmarek2
    Moderator Smart Home
    And HA can see the JSON as you give a listen in MQTT?
    
    
    Info:MQTT:Publishing val (266 bytes) to homeassistant/binary_sensor/Drzwi_garaż_binary_sensor_1/config retain=1
    
    .
    This indicates that it has sent Discovery data about the sensor.
    Helpful post? Buy me a coffee.
  • #50 21593286
    GAAD
    Level 17  
    I looked in the logs and all is clear I used Polish characters and these are not allowed in mqtt after removing the ¿ from the word garage the sensor was detected.

Topic summary

The discussion focuses on the Door Sensor D06 featuring the BK7231N WiFi chipset and a TuyaMCU (CB3S) module managing power and sensor inputs via serial interface. The TuyaMCU controls power to the WiFi module and handles the magnetic field sensor, with firmware updates requiring desoldering. Users explore the integration of tmSensor code with the TuyaMCU driver and the limitations of power control, noting that removing the TuyaMCU allows full BK7231N control and potentially improved deep sleep management. Several contributors share methods to bypass or remove the TuyaMCU, including soldering direct connections from the BK7231N to sensor components, reassigning GPIO pins for door sensor, button, LED, and battery ADC functions, and configuring OpenBeken firmware accordingly. The hall-effect sensor (P558K or 2063P) is identified as the magnetic sensor, with discussions on replacing it with a simple NO switch. Power management involves a transistor (Q1) controlled by the TuyaMCU or firmware to cut power to the WiFi module for deep sleep, with detailed schematics and wiring modifications to enable battery voltage measurement via ADC and to maintain proper ground connections. MQTT integration with Home Assistant is addressed, including configuration of MQTT topics, payloads, and discovery, with troubleshooting for sensor state reporting and battery voltage. The thread also covers challenges in wake-up reliability, firmware roles like DoorSensorWithDeepSleep, and the potential for a tutorial on converting TuyaMCU-based sensors to TuyaMCU-less operation with OpenBeken firmware for enhanced control and power efficiency.
Summary generated by the language model.
ADVERTISEMENT