logo elektroda
logo elektroda
X
logo elektroda

ONENUO WiFi Tuya Water Leak Sensor Flood Leakage Detector with Sound Alarm (898DT)

carlig833 2841 16
ADVERTISEMENT
  • #1 21087509
    carlig833
    Level 7  
    Hello,

    I have bought this water leak, branded Tuya. Here are the pictures. Attached is the original firmware.
    I would like to make it free from the cloud and use it at home with my Wi-Fi.
    I'm not sure what to do next? I could not find a template for this device.

    Close-up of a Tuya water leak sensor circuit board showing electronic components. Image of the interior of a Tuya water leak sensor showing the circuit board and battery compartment. Photo of a Tuya brand Wi-Fi water leak sensor with its case removed and user manuals. White, round Tuya water leak sensor on a gray surface. Close-up of a white, circular Tuya water leak sensor on a dark surface.

    [Edit: added pictures of board after removing batteri case]
    Attachments:
    • ONENUO WiFi Tuya Water Leak Sensor Flood Leakage Detector with Sound Alarm (898DT) IMG20240524214729.jpg (264.82 KB) You must be logged in to download this attachment.
    • ONENUO WiFi Tuya Water Leak Sensor Flood Leakage Detector with Sound Alarm (898DT) IMG20240524214755.jpg (225.48 KB) You must be logged in to download this attachment.
    • readResult_BK7231N_QIO_tuya_water_sens_2024-18-5-23-43-42.zip (997.95 KB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #2 21087609
    p.kaczmarek2
    Moderator Smart Home
    Well, it seems that our tool is not able to extract the config at this time. So now you need to either investigate the PCB or play around with GPIO doctor (in the web app). Find out the role of each pin. We are looking for at least a LED Pin, water sensor pin (input), button pin, maybe more...
    Helpful post? Buy me a coffee.
  • #3 21088711
    carlig833
    Level 7  
    Hello,

    I could easily find a basic configuration of this device that works for the purpose, thanks to the following post about a similar device:
    https://www.elektroda.com/rtvforum/topic4054445.html

    Here is the device template in json format:

    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "ONENUO WiFi Tuya Water Leak Sensor",
      "model": " Flood Leakage Detector with Sound Alarm (898DT)",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "0",
      "keywords": [
        "water sensor",
        "ONENUO WiFi",
        "898DT"
      ],
      "pins": {
        "14": "Btn;2",
        "15": "WifiLED;0",
        "20": "BAT_Relay;4",
        "22": "dInput;1",
        "23": "BAT_ADC;5"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/1039201300_1716148730.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic4055031.html"
    }
    


    Here is the autoexec.bat

    
    Battery_Setup 2000 3000 2 2400 4096
    //measure batt every 2s
    Battery_cycle 2
    //mqtt_broadcastInterval 1
    //mqtt_broadcastItemsPerSec 5
    addEventHandler OnHold 10 SafeMode 5
    
    setChannelLabel 1 Water
    
    // now wait for MQTT
    waitFor MQTTState 1
    // extra delay, to be sure
    delay_s 1
    // publish water state at least once after boot
    publish 1 $CH1
    
    // if water detected, keep cycling (drains battery)
    // also useful for configuring the device or doing OTA
    again:
    delay_s 1
    if $CH1!=1 then goto again
    delay_s 5 // was 5
    
    // All good, sleep for 1 day
    PinDeepSleep 86400
    


    General flags:
    
    Flag 37 - [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)
    



    Water detection works, deep sleep and periodic wake-up works, battery reports work.

    This device also features 80db alarm, but couldn't find how to make it work. Suggestions?
  • #4 21088776
    p.kaczmarek2
    Moderator Smart Home
    Very good progress. Thanks for sharing!

    I think you can get buzzer working with PWM and PWMFrequency command. We've been actually talking about it in other topic few days ago:
    https://www.elektroda.com/rtvforum/find.php?q=PWMFrequency
    Here is one related link: https://www.elektroda.com/rtvforum/topic4052199-30.html#21077854

    Please try it out and let me know how it goes.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21092652
    carlig833
    Level 7  
    Ok, I had a look at the "related link" to learn how to test the buzzer.

    Unfortunately I don't know which PIN drives the buzzer.
    There is no meaningful information in json config extracted from original firmware backup.

    Thinking about the options, a brute force approach would be to test each and every pin, right?
    Given that this is a CBS module, and having read datasheet I deduce there are possibly 5 PINs for PWM:

    8 P8 I/O Support hardware PWM (Correspond to Pin 24 of the IC)
    9 P7 I/O Support hardware PWM (Correspond to Pin 23 of the IC)
    10 P6 I/O Support hardware PWM (Correspond to Pin 22 of the IC)
    11 P26 I/O Support hardware PWM (Correspond to Pin 15 of the IC)
    12 P24 I/O Support hardware PWM (Correspond to Pin 16 of the IC)

    (source: https://developer.tuya.com/en/docs/iot/cbu-module-datasheet?id=Ka07pykl5dk4u)

    Then I have:
    1) Enabled the "show raw pwm controllers" flag and rebooted the device
    2) Set "PWM" for PINs 8 to 12 in the PIN configuration page and common channel 6 in WebApps > Config > PinSettings
    3) exec command "PWMFrequency 1000" in the WebApp > Logs > Command
    4) exec command "setChannel 6 50" in the WebApp > Logs > Command

    I could not ear any sound from the device.

    Am I doing the correct steps?
  • ADVERTISEMENT
  • #6 21094648
    p.kaczmarek2
    Moderator Smart Home
    If done correctly, the following should be ok. You can check it with a, for example, LED and resistor connected to PWM pin. Changing the channel value should adjust the brightness of the LED.

    Maybe we need to investigate the PCB itself? How is the buzzer connected?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21095189
    divadiow
    Level 38  
    I am playing with pwm for LED/buzzer for a door contact sensor at the moment. Maybe that needs its own thread though.

    Electronic circuit with a sensor and other components on a breadboard.
  • #8 21095221
    p.kaczmarek2
    Moderator Smart Home
    Sure, please open thread for buzzer (or your device)

    Added after 44 [minutes]:

    >>21092652there are 6 PWMs I think, not 5. Did you check them all
    Helpful post? Buy me a coffee.
  • Helpful post
    #9 21096228
    carlig833
    Level 7  

    Buzzer of my water sensor is controlled by pin number 6 in WebApp > Config > Pin Settings. Here is the obk json config template:
    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "ONENUO WiFi Tuya Water Leak Sensor",
      "model": "Flood Leakage Detector with Sound Alarm (898DT)",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "0",
      "keywords": [
        "water sensor",
        "ONENUO WiFi",
        "898DT"
      ],
      "pins": {
        "6": "PWM;6",
        "14": "Btn;2",
        "15": "WifiLED;0",
        "20": "BAT_Relay;4",
        "22": "dInput;1",
        "23": "BAT_ADC;5"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/1039201300_1716148730.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic4055031.html"
    }
    


    I could manage to drive the buzzer to emulate a modulated bi-frequency siren. Here is the autoexec.bat:
    
    Battery_Setup 2000 3000 2 2400 4096
    //measure batt every 2s
    Battery_cycle 2
    //mqtt_broadcastInterval 1
    //mqtt_broadcastItemsPerSec 5
    addEventHandler OnHold 10 SafeMode 5
    setChannelLabel 1 Water
    // now wait for MQTT
    waitFor MQTTState 1
    // extra delay, to be sure
    delay_s 1
    // publish water state at least once after boot
    publish 1 $CH1
    // if water detected, keep cycling (drains battery)
    // also useful for configuring the device or doing OTA
    mainLoop:
    delay_s 1
    if $CH1!=1 then "goto sirenOn" else "goto sleep"
    // turn on the siren and goes into siren loop
    sirenOn:
    setChannel 6 10
    // siren loop repeats while water is detected
    sirenLoop:
    backlog PWMfrequency 460;delay_ms 50
    backlog PWMfrequency 491;delay_ms 50
    backlog PWMfrequency 521;delay_ms 50
    backlog PWMfrequency 550;delay_ms 50
    backlog PWMfrequency 577;delay_ms 50
    backlog PWMfrequency 601;delay_ms 50
    backlog PWMfrequency 621;delay_ms 50
    backlog PWMfrequency 638;delay_ms 50
    backlog PWMfrequency 650;delay_ms 50
    backlog PWMfrequency 657;delay_ms 50
    backlog PWMfrequency 660;delay_ms 50
    backlog PWMfrequency 657;delay_ms 50
    backlog PWMfrequency 650;delay_ms 50
    backlog PWMfrequency 638;delay_ms 50
    backlog PWMfrequency 621;delay_ms 50
    backlog PWMfrequency 601;delay_ms 50
    backlog PWMfrequency 577;delay_ms 50
    backlog PWMfrequency 550;delay_ms 50
    backlog PWMfrequency 521;delay_ms 50
    backlog PWMfrequency 491;delay_ms 50
    if $CH1!=1 then "goto sirenLoop" else "goto sirenOff"
    // turn off the siren and go into main loop
    sirenOff:
    setChannel 6 0
    goto mainLoop
    sleep:
    delay_s 5
    // All good, sleep for 1 day or next water event
    PinDeepSleep 86400
    


    I have removed all the "general flags" and I am currently running any of them.

    Lesson learned:
    1) Pin numbers in Tuya CBU datasheet does not match pin numbers in WebApp
    2) WebApp > Gpio Finder was very useful to guess where the buzzer was
    3) A little bit tricky to implement the buzzer tone. Here is a link to helper worksheet to build the code:
    https://docs.google.com/spreadsheets/d/1TK9gSiA_PeJN_Ib2-lEu-KJxAQaQPhOLzvdFuCchP-U/copy
  • #11 21096389
    p.kaczmarek2
    Moderator Smart Home
    Good job, I've also added your autoexec.bat to our samples:
    https://github.com/openshwprojects/OpenBK7231...mmit/5009cff8aa1e3c456f2a2595495366cd5f175fc7
    I didn't refresh docs yet, tough.

    Btw, @divadiow , if you have some time, you may consider adding some comments to existing autoexec samples. Just make sure to modify the source .bat file, and not the generated automatically MD document...
    Helpful post? Buy me a coffee.
  • #12 21096400
    divadiow
    Level 38  
    sure. as in, as I see some good ones around, like if I find a device not in devicelist?
  • #13 21096419
    p.kaczmarek2
    Moderator Smart Home
    There are two things that can be done to help:
    - adding comments to existing autoexec samples
    - adding new autoexec samples
    Helpful post? Buy me a coffee.
  • #15 21522747
    mariuszkowa
    Level 4  
    I have exactly the same device. I've used the provided pin configuration and uploaded the autoexec.bat. Thank you guys for providing those!
    It works great (detects water and produces audio signal) except for the fact that the device shows 4800mV which seems invalid for 2xAAA battery.
    @carlig833 do you see proper voltage?

    Water leak sensor control panel interface showing battery, voltage, temperature, and WiFi status.

    I don't think the LED Dimmer actually works (I don't see any difference on the LED) and not sure what is the "Toggle Light" control doing, but I don't really need those.
    Battery level on the other hand is a useful information to know when the batteries should be changed, so this one I'd like to fix, not sure how though.

    EDIT: The best configuration I've found that is showing "somewhat reasonable" voltage and percentage is to set pins this way (note pin BAT_ADC on the pin 24):
    
    "pins": {
        "6": "PWM;6",
        "15": "WifiLED;0",
        "20": "BAT_Relay;0",
        "22": "dInput;1",
        "24": "BAT_ADC;0"
      },
    

    And Battery Setup in the autoexec.bat like this:
    Battery_Setup 2200 2800 1.25 2400 4096


    Let me know if anyone got a better setup. This above shows low percentage when battery is getting low but I think there may be a better approach, just couldn't find it.
  • #16 21840979
    afaik4711
    Level 3  
    Hey,
    Sorry to hijack this thread, but I'm really lost.
    I tinker around with this water leak sensor with buzzer (see images below)
    My config is (never mind the missing buzzer):
    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "0",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "8": "DoorSnsrWSleep_pd;2",
        "14": "BAT_Relay;3",
        "23": "BAT_ADC;1",
        "24": "dInput;3",
        "26": "WifiLED_n;0"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }
    


    My problem is that the device won't wake up when the sensor is in water. When it is awake and my sensor pin is "dinput_noPullup", I can see if it is dry or wet, but not on doorsensor. I have no autoexec.bat so far; I always test with the custom command "pindeepsleep 120" or the default countdown of "doorSnsWSleep_pd"
    The only time the sensor wakes is if it is set to "DoorSnsrWSleep_pd" and I short the pins on the sensor directly. The water obviously can't conduct enough energy for the sensor to wake up.
    Any thoughts on that?


    Blue PCB with CB3S module and printed antenna; solder pads and plastic housing visible. Close-up of a circuit board inside a white plastic case with a push button and a battery spring contact
  • #17 21840983
    p.kaczmarek2
    Moderator Smart Home
    DSEdge setting. It has 3 options and you need to try them all to see which one works. Make sure to have also button configured first, so you can emergency- wakeup device.
    https://www.elektroda.com/rtvforum/find.php?q=DSEdge
    Helpful post? Buy me a coffee.

Topic summary

✨ The discussion focuses on configuring the ONENUO WiFi Tuya Water Leak Sensor Flood Leakage Detector (model 898DT) to operate independently from the Tuya cloud, using local Wi-Fi control. Initial attempts to extract the device configuration from the original firmware were unsuccessful, prompting manual investigation of the PCB and pin functions using GPIO diagnostics. A basic JSON device template was shared, identifying key pins such as button (pin 14), WiFi LED (pin 15), battery relay (pin 20), digital input (pin 22), and ADC for battery voltage (pin 23). The buzzer control was determined to be on pin 6, configured for PWM output, enabling emulation of modulated siren sounds via custom autoexec.bat scripts. Users experimented with PWM settings to drive the buzzer and LED, confirming hardware capabilities and pin assignments. Battery voltage readings initially appeared inaccurate, leading to adjustments in pin assignments, particularly for the battery ADC input (pin 24), to improve measurement reliability. The community contributed improvements to configuration samples and firmware scripts, facilitating cloud-free operation and enhanced device control. Documentation and code samples were shared on GitHub and forum links for further development and testing.
Generated by the language model.

FAQ

TL;DR: Six PWM channels are available — "there are 6 PWMs, not 5." This guide maps GPIOs, siren control, battery readout, and MQTT for the ONENUO 898DT. [Elektroda, p.kaczmarek2, post #21095221]

Why it matters: It helps DIY users quickly get leak alerts, buzzer, and battery reporting working without guesswork.

Quick Facts

How do I set up the ONENUO 898DT to work with OpenBeken and MQTT?

Flash OpenBeken, load the shared template, and use autoexec to label Channel 1 as Water, wait for MQTT, then publish. The shared config reports water state, sleeps, and wakes periodically. Add SafeMode handling and Battery_* commands as in the example. Users reported water detection, deep sleep, and battery reporting working. [Elektroda, carlig833, post #21088711]

Which GPIO drives the buzzer, and how do I enable it?

Map the buzzer to GPIO 6 as PWM;6. Set a PWMFrequency and drive it by setting Channel 6 to a non-zero duty, for example setChannel 6 10. A modulated siren can be created by stepping frequencies between 460 and 660 Hz with short delays. [Elektroda, carlig833, post #21096228]

How do I find the buzzer pin if I don’t know it? (3‑step how‑to)

  1. Enable the “show raw PWM controllers” flag in the WebApp.
  2. In Pin Settings, assign PWM to candidate pins and give them a common channel (e.g., 6).
  3. Run PWMFrequency 1000, then setChannel 6 50 to listen for tone output. Iterate candidates until it sounds. [Elektroda, carlig833, post #21092652]

How can I verify PWM output without risking the buzzer?

Use an LED and resistor on the suspected PWM pin. Increase or decrease the channel value to see brightness change. “You can check it with a LED and resistor connected to PWM pin.” This validates PWM control before driving the buzzer directly. [Elektroda, p.kaczmarek2, post #21094648]

What are the working OpenBeken pin mappings for this sensor?

Example mapping: 6 = PWM;6 (buzzer), 14 = Btn;2 (button), 15 = WifiLED;0 (status LED), 20 = BAT_Relay;4, 22 = dInput;1 (water), 23 = BAT_ADC;5. This template also includes an autoexec that labels Channel 1 as Water and manages sleep and siren behavior. [Elektroda, carlig833, post #21096228]

How do I make a modulated “siren” tone?

Enable the buzzer (setChannel 6 10), then loop PWMFrequency steps such as 460, 491, … up to 660 Hz with ~50 ms delays, then back down. This creates a bi‑frequency siren. Keep the loop active only while water is detected to avoid battery drain. [Elektroda, carlig833, post #21096228]

My battery shows 4800 mV on 2×AAA. How do I fix it?

Move BAT_ADC to GPIO 24 and adjust Battery_Setup, for example Battery_Setup 2200 2800 1.25 2400 4096. A user reported 4800 mV initially and achieved more realistic voltage and percentage with that pin and setup. This edge case suggests ADC routing varies by unit. [Elektroda, mariuszkowa, post #21522747]

What Battery_Setup values should I start with?

Use the shared working example to calibrate: Battery_Setup 2200 2800 1.25 2400 4096. It improved percentage tracking as cells discharged. Fine‑tune thresholds and multiplier until the reported mV aligns with a multimeter. Recheck after sleep/wake cycles to confirm stability. [Elektroda, mariuszkowa, post #21522747]

Why don’t LED Dimmer or Toggle Light seem to work here?

A user noted no visible effect from LED Dimmer and uncertainty about Toggle Light, yet core functions (water, siren, battery) worked. The template uses WifiLED;0 for status, which is not a dimmable light output. It’s safe to ignore these controls for this device. [Elektroda, mariuszkowa, post #21522747]

How do I reduce battery drain but still get alerts?

Use deep sleep with PinDeepSleep 86400 to sleep for a day, and wake periodically. Only run the siren loop while water is detected, because the continuous tone “drains battery.” Keep Battery_cycle short for timely voltage reporting during active periods. [Elektroda, carlig833, post #21096228]

Do Tuya CBU datasheet pin numbers match OpenBeken’s numbering?

No. One user’s lesson learned: Tuya CBU datasheet pin numbers do not match WebApp pin numbers. Use the WebApp Gpio Finder to identify functions. Validate by testing inputs (water probe, button) and outputs (LED, buzzer) in software. [Elektroda, carlig833, post #21096228]

How many PWM channels are available on this module?

Expect six PWM controllers. As one expert put it, “there are 6 PWMs I think, not 5.” Check them all when hunting the buzzer or dimmable outputs. This also explains why some initial guesses miss the correct pin. [Elektroda, p.kaczmarek2, post #21095221]

What’s the simplest way to publish water state to MQTT after boot?

In autoexec, wait for MQTT, then publish Channel 1. Example: waitFor MQTTState 1; delay_s 1; publish 1 $CH1. Label Channel 1 as Water so the topic clearly reflects the sensor state. This guarantees an initial status message. [Elektroda, carlig833, post #21096228]

The tool can’t extract the config—what should I do next?

Investigate the PCB or use the WebApp’s GPIO tools. Identify the LED, water sensor input, and button first. Then test remaining pins methodically. Mapping these essentials lets the device function while you refine optional features like the buzzer. [Elektroda, p.kaczmarek2, post #21087609]

Where can I find a known‑good autoexec for this sensor?

A working autoexec with siren loop, battery setup, MQTT publish, and deep sleep was added to the project’s sample set. Use it as a starting point and adjust Battery_Setup and BAT_ADC pin for your unit if needed. [Elektroda, p.kaczmarek2, post #21096389]
Generated by the language model.
ADVERTISEMENT