logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Door/window sensor without TuyaMCU - deep sleep and energy saving, OpenBeken

p.kaczmarek2 17124 69

TL;DR

  • OpenBeken configures a TuyaMCU-free door/window sensor that uses the WiFi module’s deep sleep for battery saving.
  • Set the sensor pin to DoorSensorWithDeepSleep and the configuration button to button; pin-state changes wake the module to report MQTT updates.
  • The sleep countdown after reboot is 11 seconds, and WiFi operation draws about 50mA to 150mA.
  • The sensor wakes for both open and closed states, and Home Assistant discovery adds it automatically once MQTT is connected.
  • A limitation is startup latency: it must reconnect to WiFi and MQTT before sending status, and missing MQTT blocks sleep for up to 300 seconds.
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • #61 20996514
    p.kaczmarek2
    Moderator Smart Home
    @Mad_Maxs here is a topic about it: https://www.elektroda.com/rtvforum/topic3959103.html
    You need to change the Battery_Setup arguments.

    By the way, do you still need hybrid wake-up (timer + GPIO)? You could try to connect them to the command and you can test whether it works.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #62 20998108
    Mad_Maxs
    Level 12  
    p.kaczmarek2 wrote:
    By the way, do you still need hybrid wake-up (timer + GPIO)? You could try to connect them to the command and you can test whether it works.
    Sure, I have one sensor on the table, I can test :)
  • ADVERTISEMENT
  • #63 20998151
    p.kaczmarek2
    Moderator Smart Home
    We posted an update yesterday, there is no article about it on Elektroda yet (it will be posted within 48 hours) but from now on PinDeepSleep has an optional argument - timer wake-up time. Then they wake up both the pins and the timer after a certain time.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #64 21000119
    Mad_Maxs
    Level 12  
    p.kaczmarek2 wrote:
    from now on, PinDeepSleep has an optional argument - timer wake-up time

    PinDeepSleep 60 should it wake up after 60 seconds?
  • #65 21000124
    p.kaczmarek2
    Moderator Smart Home
    This works on the N platform. This command will either wake up the GPIO immediately or wake up the timer after 60 seconds.
    Helpful post? Buy me a coffee.
  • #66 21000213
    Mad_Maxs
    Level 12  
    p.kaczmarek2 wrote:
    This command will either wake up the GPIO immediately or wake up the timer after 60 seconds.

    It seems to work as intended. After 60 seconds, the sensor wakes up, does its job and goes to sleep.
    On the main screen we have:
    Reboot reason: 4 - Sleep Timer

    If I stimulate it with a magnet, it also wakes up and does its job, and on the screen we have:
    Reboot reason: 3 - Pin Interrupt


    Is it possible to somehow log this parameter into a variable? It can be a value of 3 or 4, at the server level I want to distinguish between wake-up by a magnet and a sleep timer
  • #67 21000290
    p.kaczmarek2
    Moderator Smart Home
    Yes, this will be discussed in the upcoming article, which I will post on elektroda.com by midnight today. But in short:
    
    $rebootReason
    Helpful post? Buy me a coffee.
  • #68 21000464
    Mad_Maxs
    Level 12  
    p.kaczmarek2 wrote:
    Yes, this will be discussed in the upcoming article, which I will post on elektroda.com by midnight today. But in short:
    $rebootReason

    Checked :) works
  • #69 21000533
    p.kaczmarek2
    Moderator Smart Home
    Will you share your finished script? If you want to describe it in full, this can be a separate topic.

    Here is my PinDeepSleep tutorial (English version):
    https://www.elektroda.com/rtvforum/topic4041971.html
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #70 21001192
    Mad_Maxs
    Level 12  
    p.kaczmarek2 wrote:
    Will you share your finished script? If you want to describe it in full, this can be a separate topic.

    There`s nothing much to share, I just added another variable sent via GET to the server. The rest is done on the server
📢 Listen (AI):

Topic summary

✨ The discussion focuses on configuring a door/window sensor using OpenBeken without TuyaMCU, emphasizing deep sleep functionality for energy efficiency. The sensor connects to WiFi only to send state changes to an MQTT server, minimizing power consumption. Users inquire about HTTP event notifications, firmware updates, and the impact of static IP on battery life. Various responses address configuration issues, connection times, and the importance of using the correct firmware version. The conversation also covers the calibration of battery readings, the implementation of GET requests upon waking, and troubleshooting connection delays. Key solutions include using the DSEdge command for wake-up configuration and ensuring proper pin assignments for functionality.
Generated by the language model.

FAQ

TL;DR: Deep-sleep BK7231N door sensors can run >16 years on a CR2032 (“600 notifications vs 5 years at 2 s wake”, [Elektroda, krzbor, post #20458745]) and reconnect to MQTT in “about 4 s” with Fast-Connect enabled [Elektroda, p.kaczmarek2, post #20465020] Why it matters: matching sleep time, static IP and battery calibration maximises life and avoids missed door events.

Quick Facts

• Sleep current: ~50–80 µA (image, [Elektroda, p.kaczmarek2, post #20457191])
• Wake current: 50–150 mA burst, 7 s Wi-Fi join typical [Elektroda, miroww1, post #20464951]
• Fast-Connect flag + static IP cuts latency to 4–5 s [Elektroda, p.kaczmarek2, post #20465020]
• Default DSTime 60 s; configurable 1-3600 s via DSTime cmd [Elektroda, p.kaczmarek2, post #20671018]
• RF-cal partition loss sets MAC to 00:00:00 and halves range [Elektroda, p.kaczmarek2, post #20467352]

How do I flash OpenBeken on a BK7231N window sensor?

  1. Solder TX/RX/GND/3V3 to the rear pads or use OTA if Tuya firmware still active [Elektroda, Mad_Maxs, post #20972327]
  2. In BK7231 GUI Flash Tool choose correct RBL file, tick “Erase all”, then “Restore RF partition” to keep calibration [Elektroda, p.kaczmarek2, post #20463304]
  3. After reboot, connect to the AP, set Wi-Fi and MQTT.

Which pin roles must be set for a deep-sleep door sensor?

• Door reed: DoorSnsrWSleep (or nPUP/PD variant) on Channel 0. • Button: Btn (or Btn_ScriptOnly) on Channel 2. • Battery ADC: BAT_ADC on Channel 1. • Battery relay (if fitted): BAT_Relay on Channel 1. • Wi-Fi LED: WifiLED or WifiLED_n. [Elektroda, p.kaczmarek2, #20457191; Mad_Maxs, #20973013]

What does PinDeepSleep with an argument do?

Since v1.17.5xx PinDeepSleep accepts an optional wake timer. PinDeepSleep 600 sleeps until door/button interrupt OR 10 min timer fires—ideal for health pings [Elektroda, p.kaczmarek2, post #21000124]

Can I use HTTP instead of MQTT?

Yes. Use SendGET in autoexec, e.g. SendGET http://server/ip?door=$CH0&bat=$batteryLevel. OBK supports variable substitution for any channel or $rebootReason [Elektroda, p.kaczmarek2, post #20951901]

Why does my MAC show 00:00:00 and Wi-Fi range is poor?

The RF-cal partition was erased during flashing. Re-flash original Tuya image or use “Restore RF partition” in the flasher; otherwise TX power drops and range halves [Elektroda, p.kaczmarek2, post #20467352]

Battery shows 120 %. How do I calibrate it?

Execute Battery_Setup <max_mV> <min_mV> <coeff>; typical CR2032 values are 3000 2200 1.0. Adjust until $batteryLevel reads 100 % at 3.0 V and 0 % near 2.2 V [Elektroda, p.kaczmarek2, post #20996514]

Edge case: opening and closing within 2 s isn’t reported—how to fix?

Store the first pin state at boot, then compare after Wi-Fi up. Example snippet:

setChannel 5 $CH0
waitFor WiFiState 4
if $CH5!=$CH0 then backlog SendGET ...; delay_s 2
This ensures both transitions publish even during fast toggles [Elektroda, p.kaczmarek2, post #20953662]

How can I recover if a buggy script locks the sensor in deep sleep?

Add a safety button check at script start:

if $CH2==1 then goto safe
...
PinDeepSleep
safe:
Pressing the button skips deep sleep, keeping the device online for OTA fixes [Elektroda, p.kaczmarek2, post #20953786]

Will 10+ sensors overload my mesh Wi-Fi?

No. Each sensor sends ≈0.5 kB per event; even 50 sensors total <25 kB/day. Ensure ≤10 m distance or add AP; lost RF-cal increases retries [Elektroda, Mad_Maxs, post #20973013]

How to restore a wiped device quickly?

3-step How-To:
  1. Hold button, power cycle → enters OpenBeken recovery.
  2. From WebApp choose OTA → select latest release.
  3. Reboot, run resetConfiguration to load template, then startDriver DoorSensor.
Generated by the language model.
ADVERTISEMENT