logo elektroda
logo elektroda
X
logo elektroda

Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

khafif 5322 10
Best answers

How do I flash a TUYA-BK7231N/CBU Wi‑Fi door sensor and configure deep sleep and MQTT for Home Assistant?

Flash it with OpenBeken using the BK7231GUIFlashTool, then follow the dedicated step-by-step door-sensor guide for this BK7231N/CBU device, which uses deep sleep and has no TuyaMCU [#20611082] [#20684028] Configure the correct DoorSensor GPIO role (pull-up or pull-down depending on the board) and set the DSEdge wake edge correctly, because a wrong IO or edge setting can prevent the sensor from waking [#20612363] [#20639762] If the sensor still will not wake, re-check the chosen pin and DSEdge value, since they can differ between devices [#20612363] [#20639762] Keep the Button role assigned for pairing so you have an emergency wake-up method if the door sensor GPIO is misconfigured [#20612363] Home Assistant can auto-discover MQTT, but when the device enters sleep it may appear disconnected or stop reporting until it wakes again [#20611389]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
  • Deep sleep flashing guide for BK7231N door sensor

    #1 20611044
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    TUYA-BK7231N/CBU-Wi-Fi-door sensor-Home assistant MQTT setup

    Need detailed setup for flashing the TUYA-BK7231N/CBU-Wi-Fi-door sensor and Home assistant MQTT setup please. Thank you.

    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

    2023-08-06 UPDATE:
    Here is a nice step by step guide for flashing it and deep sleep setup:

    [BK7231N/CBU] Door sensor without TuyaMCU - easy flashing and configuration guide
    NOTE: The following sensor is using BK7231 deep sleep, it has no TuyaMCU.
  • ADVERTISEMENT
  • Helpful post
    #2 20611082
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14717
    Help: 659
    Rate: 12794
    Hello, this device is already supported by OpenBeken:
    https://github.com/openshwprojects/OpenBK7231T_App
    You can find our flasher here:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    I think the setup approach from here could work:
    https://www.elektroda.com/rtvforum/topic3972898.html
    Helpful post? Buy me a coffee.
  • Missing deep sleep option in firmware dropdown

    #3 20611389
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

    - mqtt was discovered by HA. door sensor goes sleep but the deep sleep and push button are not working when sensor goes sleep. I have to manually turn it off and on every time it goes to sleep.

    - I do not have deep sleep in the drop down list (attached photo).

    Thank you.

    Added after 24 [minutes]:

    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

    in this post (firmware) you have displayed sensor battery at HO, but now it is not showing.
    https://www.elektroda.com/rtvforum/topic3914412.html is the new version missing this option or it is me. Thanks.

    Added after 11 [hours] 27 [minutes]:

    I know you need my tuya back, copy attached original tuya firmware.
    Attachments:
    • door sensore readResult_BK7231N_QIO_2023-08-6--14-29-34.bin (2 MB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • Testing deep sleep and push-button wakeup

    #4 20611799
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

    weblog
    Info:MQTT:Channel has changed! Publishing 1 to channel 43
    Info:MQTT:Publishing val 1 to BK_DS1/43/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BK_DS1/43/get
    Info:MQTT:Channel has changed! Publishing 1 to channel 47
    Info:MQTT:Publishing val 1 to BK_DS1/47/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BK_DS1/47/get

    am going to try the deep sleep and the push button.
  • Wrong IO or DSEdge setting prevents wakeup

    #5 20612363
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14717
    Help: 659
    Rate: 12794
    Hello again, if the sensor does not wake up, it can mean that:
    - you have chosen wrong IO for sensor role
    - you have incorrect DSEdge setting (DSEdge 2 is default, there is also DSEdge 1 or DSEdge 0)

    khafif wrote:
    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT
    - I do not have deep sleep in the drop down list ( attached photo).

    For which role are you looking for? It seems you have all required roles here. I can see one role for DoorSensor (the PD role, input with PullDown). If you want a pull-up input door sensor role, scroll up, it's a bit earlier on the list.

    Don't forget that if you set a Button role for pairing Button, it will also be able to wake up the device in the time of emergency. That way you can play around with settings and choose the ones that suits you best.
    Helpful post? Buy me a coffee.
  • Questions on channel mapping, sleep mode, and LED control

    #6 20612399
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT Flashing and Deep Sleep Setup Guide for TUYA-BK7231N/CBU Wi-Fi Door Sensor with Home Assistant MQTT

    1- I managed (don't ask how) to get these results.
    2- I cannot remove/find channel 1 in any setup?
    3- I had to use dInput_n to reverse HO sensor action.
    4- Door sensor sleep mode in HO not displaying ON or OFF?
    5- MQTT state not displaying disconnected when in sleep mode?
    6- How can I control the sleep mode duration (to reduce the time frame)?
    7- How to turn OFF LED, it is always on.
    8- Can we blink the LED (in Bright light) when awake mode triggered by Button or Door Sensor?





    Added after 4 [minutes]:

    One more clarification, can we display battery state in HO as voltage and capacity percentage so we can enable an alarm triggered at battery percentage to be replaced!

    Thank you for the great achievement, keep it going and regards to all the team.
  • #7 20638378
    simovicsava
    Level 8  
    Posts: 11
    Help: 2
    Rate: 4
    Guys, I found the correct settings. :-))))

    Link
  • ADVERTISEMENT
  • #8 20639725
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    Thanks, I’ll check it and give feed back.
  • #9 20639762
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14717
    Help: 659
    Rate: 12794

    DSEdge (the wake up edge of deep sleep, either "opposite of current", "rising" or "falling") and the exact Door Sensor pin type (pull up, no pull up, etc) can change between devices. Please always remember to set the Button role for your button so you can do an emergency wake up of the device if the door sensor GPIO is configured incorrectly.
    Helpful post? Buy me a coffee.
  • Need to diagnose AP mode and flash access issue

    #10 20646748
    khafif
    Level 5  
    Posts: 16
    Rate: 1
    now the door sensor is not connected to my wifi router, I cannot reset to access AP mode, I did flash it more than 5 times using the UART flasher, still cannot access the access point web site to enter my WiFi pass-code. The BK flasher always writing file data to chip is success.

    is there any other methods/ways to follow to diagnose the board.

    
    Starting flash new (no backup)!
    Now is: 08 July 2023 18:35:40.
    Flasher mode: BK7231N
    Going to open port: COM5.
    Serial port open!
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus failed, will try again - 0/100!
    Getting bus failed, will try again - 1/100!
    Getting bus failed, will try again - 2/100!
    Getting bus success!
    Going to set baud rate setting (921600)!
    Will try to read device flash MID (for unprotect N):
    Flash MID loaded: 1560EB
    Will now search for Flash def in out database...
    Flash def found! For: 1560EB
    Flash information: mid: 1560EB, icName: TH25Q_16HB, manufacturer: TH, szMem: 1000000, szSR: 2, cwUnp: 0, cwEnp: 7, cwMsk: 407C, sb: 2, lb: 5, cwdRd: 05-35-FF-FF, cwdWr: 01-FF-FF-FF
    Entering SetProtectState(True)...
    sr: 80
    sr: 680
    final sr: 680
    msk: 407c
    cw: 0, sb: 2, lb: 5
    bfd: 0
    SetProtectState(True) success!
    Reading file firmwares/OpenBK7231N_QIO_1.17.104.bin...
    Loaded 1220464 bytes from firmwares/OpenBK7231N_QIO_1.17.104.bin...
    Preparing to write data file to chip - resetting bus and baud...
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (921600)!
    Will try to read device flash MID (for unprotect N):
    Flash MID loaded: 1560EB
    Will now search for Flash def in out database...
    Flash def found! For: 1560EB
    Flash information: mid: 1560EB, icName: TH25Q_16HB, manufacturer: TH, szMem: 1000000, szSR: 2, cwUnp: 0, cwEnp: 7, cwMsk: 407C, sb: 2, lb: 5, cwdRd: 05-35-FF-FF, cwdWr: 01-FF-FF-FF
    Entering SetProtectState(True)...
    sr: 80
    sr: 680
    final sr: 680
    msk: 407c
    cw: 0, sb: 2, lb: 5
    bfd: 0
    SetProtectState(True) success!
    Going to do erase, start 0, sec count 298!
    Erasing sector 0... ..........
    Writing file data to chip successs.
  • ADVERTISEMENT
  • Full 2 MB erase with RF partition backup recommended

    #11 20684028
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14717
    Help: 659
    Rate: 12794
    @khafif in worst case, you can try doing full 2MB erase but maybe backup RF partition first so you can restore it later... I will look into adding a dedicated option for that to our flasher.

    2023-08-06 UPDATE:
    Here is a nice step by step guide for flashing it and deep sleep setup:

    [BK7231N/CBU] Door sensor without TuyaMCU - easy flashing and configuration guide
    NOTE: The following sensor is using BK7231 deep sleep, it has no TuyaMCU.
    Helpful post? Buy me a coffee.

Topic summary

✨ The discussion focuses on the setup and flashing of the TUYA-BK7231N/CBU Wi-Fi door sensor for integration with Home Assistant using MQTT. Users share resources for flashing the device, including links to OpenBeken support and the BK7231 GUI Flash Tool. Issues arise with deep sleep functionality, MQTT state visibility, and battery status display. Users report problems with the sensor not waking from deep sleep, incorrect settings for input/output roles, and difficulties in accessing the device's access point mode after flashing. Solutions involve adjusting DSEdge settings, ensuring correct GPIO configurations, and troubleshooting connection issues. A step-by-step guide for flashing and deep sleep setup is also referenced.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT