logo elektroda
logo elektroda
X
logo elektroda

CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration

kyantobam 4884 17
ADVERTISEMENT
  • #1 20421822
    kyantobam
    Level 4  
    Hi,
    first of all, thanks for making this great firmware.
    I have a Water Leak sensor that is not equipped with a tuyaMCU, The module is CB3S(BK7231N) I have flashed this CB3S with OpenBK7231N_QIO_1.15.407, the device has connected to HA, but the problem is I don't know how to reduce battery consumption.
    the following is a picture of the Water Leak sensor :

    CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration

    This is the PINs :
    P8  Water Leak (dInput_NoPullUP) Channel 0 Readonly
    P14  Trig Q2 / Batt Monitor (Rel) Channel 1 Toggle
    ADC3  Analog input Batt Monitor(ADC) Channel 11
    P24  PushBttn Pairing (dInput) Channel 5 Readonly
    Dummy channel 3 humidity

    CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration
    CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration

    Use Scripts(BACA-484) to trigger Batt Monitor (Q2) only when water leak detected :

    again:
              if $CH0==1 then goto done
              if $CH1==1 then goto done
              if $CH5==0 then goto done
              setChannel 20 0
              goto again
    done:     // make sure  BATT monitor OFF
              setChannel 1 0
                  // make sure only one shot
              if $CH20==1 then goto again
              setChannel 1 1
              delay_s 3
    	  SetChannel 3 $CH11
    	  setChannel 1 0
              // make sure only one shot
              setChannel 20 1 
    	  delay_s 10
    	  goto again


    where and how to use DeepSleep feature?
  • ADVERTISEMENT
  • #2 20422757
    p.kaczmarek2
    Moderator Smart Home
    Well, DeepSleep is in early stage of development, but you basically have two options here. First option would be to use the GPIO wakeup from the sensor (it will wake up module when, for example, it detects water) and then module can report it's status, and the second option would be to just deep sleep for example, for 15 minutes, then wake up, check for water/report, and sleep again for fixed time of 15 minutes.
    The external GPIO deep sleep is not yet fully working on N, only on T, so I'll try to look into that for you, or you can for now settle with second solution.
    In general it depends on your use case. how quick reporting do you need.

    I also checked the last release and I see that you'll have to update your firmware before using anything related to deepsleep. But in general, DeepSleep [Time] command should turn off device for given time and then device will reboot from scratch.
    Helpful post? Buy me a coffee.
  • #3 20422868
    kyantobam
    Level 4  
    I have updated to ver 1.15.410

    CB3S (BK7231N) Water Leak Detector without TuyaMCU: Battery Saving Tips & Configuration

    i don't where to put DeepSleep Command, putting on scripts but no effect

    this autoexec :
    setChannelType 0 ReadOnly
    setChannelType 1 toggle
    SetChannel 1 0
    setChannelType 3 humidity
    setChannelType 5 ReadOnly
    startScript BACA * 507
    
    this --> BACA id 507 :
    +++++++++++++++++++++++++++
    again:
              if $CH0==1 then goto done
              if $CH1==1 then goto done
              if $CH5==0 then goto done
              setChannel 20 0
              goto again
    done:     // make sure  BATT monitor OFF
              setChannel 1 0
                  // make sure only one shot
              if $CH20==1 then goto again
              setChannel 1 1
              delay_s 3
    	  SetChannel 3 $CH11
    	  setChannel 1 0
              // make sure only one shot
              setChannel 20 1 
    	  delay_s 10
              DeepSleep 600 -------------------------------> no effect  :(  :(
    	  goto again
    +++++++++++++++++++++++++++
  • #4 20422920
    p.kaczmarek2
    Moderator Smart Home
    Please try if DeepSleep works at all, just from the console, execute "DeepSleep 600" and see if device goes offline (and comes back)
    Helpful post? Buy me a coffee.
  • #5 20422972
    kyantobam
    Level 4  
    I made a mistake on the scripts, thanks. Now just observe how long the battery life[/film]
  • #6 20486914
    Ipn00tic
    Level 8  
    It goes into deep sleep mode but does not wake up when the pins come into contact with water, it only wakes up if you make a direct contact with a wire between the two contact pins. but when not in deep sleep it works fine and detects water between the pins and also resets the 60 second count for deepsleep.

    I checked that when using DoorSnsrWSleep_nPup it loads the DoorSensor drivers, is this the problem? Is it necessary to load the specific drivers for the water leak?

    Added after 1 [minutes]:

    Added after 41 [seconds]:

    kyantobam wrote:
    I made a mistake on the scripts, thanks. now just observe how long the battery life[/film]


    friend, can you share the complete and correct script you are using?
  • ADVERTISEMENT
  • #7 20487417
    kyantobam
    Level 4  
    Have same problem, during deepsleep 100% can wake up use button (P24) only, with Water leak probe sometimes can sometimes can't.
    When already wake up, 100% Water leak can detect DRY or WET.

    My Script only for Batt monitor
    Channel 2 is (P14) turn on transistor, Channel 4 only LED

    setChannelType 2 toggle
    setChannelType 4 toggle
    setChannelType 3 humidity
    SetChannel 2 0
    startScript TEKTOK * 440

    restart:
    setChannel 12 0
    setChannel 2 0
    again:
    if $CH2>=1 then goto tmbah
    setChannel 2 1
    tmbah:
    delay_s 1
    setChannel 4 0
    addChannel 12 1
    if $CH12<=3 then goto again
    if $CH12>=5 then goto mati
    setChannel 3 $CH11
    setChannel 4 1
    mati:
    setChannel 2 0
    setChannel 4 0
    if $CH12<=20 then goto tmbah
    goto restart
  • #8 20487461
    p.kaczmarek2
    Moderator Smart Home
    Ipn00tic wrote:

    I checked that when using DoorSnsrWSleep_nPup it loads the DoorSensor drivers, is this the problem?
    Is it necessary to load the specific drivers for the water leak?

    The DoorSensor driver is working for both Pull Up (DoorSnsrWSleep) and no-pull-up inputs (DoorSnsrWSleep_nPup). If it's not working, then a sufficient voltage level was on reached on input pin.

    What is the connection of water sensor pin in your device? Does it have any external pull up or pull down resistors? Or maybe is there some kind of circuit before BK GPIO used for water sensor?

    The only thing I can suggest right now is that I can provide a DoorSnsrWSleep_pullDown pin, which has a programmable, internal, pull-down resistor (because there are 3 options in bk - gpio with pullup, with pulldown, or with no pulls).
    Helpful post? Buy me a coffee.
  • Helpful post
    #9 20616047
    TomTheGeek
    Level 4  

    I picked up one of these as it was cheap and seemed like a good platform to use for battery-powered projects. The problem is I fried something on the board when trying to get battery monitoring working. I got it to work, but when I put the command in the startup file, it would rapidly heat up as if there was a short somewhere.

    Here is my template and autoexe file. This boots and doesn't burn anything up, but no battery monitoring works.

    Quote:
    {
    "vendor": "Tuya",
    "bDetailed": "0",
    "name": "Wifi Water Leak Detector",
    "model": "obk5562782F",
    "chip": "BK7231N",
    "board": "CB3S",
    "flags": "1024",
    "keywords": [
    "Water leak",
    "battery"
    ],
    "pins": {
    "7": "WifiLED;7",
    "8": "dInput_NoPullUp;1",
    "14": "BAT_Relay;4",
    "23": "BAT_ADC;3",
    "24": "dInput_n;2"
    },
    "command": "",
    "image": "https://obrazki.elektroda.pl/2518490200_1675512178.jpg",
    "wiki": "https://www.elektroda.com/rtvforum/topic3954826.html"
    }




    Quote:
    SetChannelType 1 Toggle
    SetChannelLabel 1 "Water Input" 1
    SetChannelType 2 Toggle
    SetChannelLabel 2 "Button Input" 1


    //SetChannel 4 1 This should not be high until after the device boots or it will FRY!
    Battery_Setup 1500 3000 2 2400 4096

    PowerSave 1
    PinDeepSleep

  • #10 20741312
    eddie.t.h
    Level 12  

    It seems that the Pindeepsleep function engages an internal pull-down resistor. Therefore, the sensor does not wake up from the liquid, only from a metallic short circuit. The question is whether it is a hardware or software bug?
  • ADVERTISEMENT
  • #11 20741347
    p.kaczmarek2
    Moderator Smart Home
    This is configurable. You have multiple pin roles:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/ioRoles.md
    Namely:
    Screenshot of a table showing pin role configuration for OpenBK7231T application.
    There is also DSEdge setting:
    
    | DSEdge | [edgeCode] | DeepSleep (PinDeepSleep) wake configuration command. 0 means always wake up on rising edge, 1 means on falling, 2 means if state is high, use falling edge, if low, use rising. Default is 2.<br/><br/>See also [DSEdge on forum](https://www.elektroda.com/rtvforum/find.php?q=DSEdge). |
    
    Helpful post? Buy me a coffee.
  • #12 20741870
    eddie.t.h
    Level 12  
    I know about these settings but they don't seem to work. That is, they work until the Pindeepsleep command is executed. Therefore, when the sensor is awake, everything works properly, i.e. it detects moisture correctly. After sleep, the measurements showed that an additional resistance of several dozen kohm is attached to the pin, so the water resistance is too high to get a high state. I have the latest version of the software.

    EDIT:
    I checked again carefully and everything indicates that the PinDeepSleep function is bugged.
    Setting pin P8 as DoorSnsrWSleep_nPup makes it correctly detect the dampness on the probe in active mode. The input resistance of the pin of the order of Mohms.
    Enabling DoorSnsrWSleep_pd makes the input resistance drop to 18kohm and the probe no longer works. So here everything is ok, the functions work properly.
    That is, with the DoorSnsrWSleep_nPup option, the sensor theoretically should work properly but unfortunately it does not. Until sleep everything is ok, the input resistance is in Mohm, but after sleep it drops to 18kohm - so clearly the pulldown resistor is activated!
    The same thing happens when I set the inputs as ordinary DI without pull-up and issue the PinDeepSleep command.
  • Helpful post
    #13 20933817
    @GUTEK@
    Level 31  
    Hello,
    I also became the owner of this water sensor. Unfortunately, after downloading Open Beken, I couldn`t force it to wake up when the state changed. And even with the original software, it didn`t quite work properly in my opinion.

    Therefore, I soldered an NPN transistor (the first one found on the motherboard) and a 10kΩ pull-up resistor connected to 3.3V to the P8 input, where one of the electrodes goes.
    Something similar to the example in this diagram: https://www.instructables.com/Simple-Water-Sensor/

    It looks like:
    Close-up of a circuit board with electronic components and wires.

    Thanks to this, the system simply gets 1 or 0 (3.3V or 0V). Now all I had to do was set the sensor as DoorSnsrWSleep_nPup and after short tests I found that it works properly. I will add that selecting DoorSnsrWSleep, which should pull up itself, also did not want to wake up the system. Additionally, you also need to turn on flag 42 to reverse the readings.
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "1156",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "7": "WifiLED_n;0",
        "8": "DoorSnsrWSleep_nPup;0",
        "14": "BAT_Relay;1",
        "23": "BAT_ADC;1",
        "24": "Btn;2"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }
  • ADVERTISEMENT
  • #14 20952786
    Mad_Maxs
    Level 11  

    @GUTEK@ wrote:
    Hello,
    Therefore, I soldered an NPN transistor (the first one found on the motherboard) and a 10kΩ pull-up resistor connected to 3.3V to the P8 input, where one of the electrodes goes.
    Something similar to the example in this diagram: https://www.instructables.com/Simple-Water-Sensor/

    It looks like:
    Close-up of a circuit board with electronic components and wires.

    Thanks to this, the system simply gets 1 or 0 (3.3V or 0V). Now all I had to do was set the sensor as DoorSnsrWSleep_nPup and after short tests I found that it works properly. I will add that selecting DoorSnsrWSleep, which should pull up itself, also did not want to wake up the system. Additionally, you also need to turn on flag 42 to reverse the readings.

    Hello,
    Did it start to work properly after this modification? I've got the same device, and the same problem with waking up. Additionally, I've set WifiLED to wifiled_n to see when it's connected, but after it goes to sleep, the LED is still on.
  • #15 20955728
    belveder79
    Level 4  

    I can't confirm that it works for this particular version of the sensor, however I have another one which is very similar documented here and for this one I can confirm that it indeed works.

    Did not play around with the DeepSleep or anything yet, but it works like a door sensor now and comes back from deep sleep if you touch the sensor.
  • #16 20974957
    Mad_Maxs
    Level 11  
    By inserting the NPN BC547 transistor, with the emitter in place of the probe pad, the collector in the white wire from the probe, and the base through a 10kohm resistor in VCC, we obtain correct operation with pin 8 set as DoorSnsrWSleep_nPup, Flag 42 to OFF and DSEdge 2.
    Electronic module with NPN BC547 transistor installed Printed circuit board with NPN BC547 transistor and connected wires.

    I noticed that when the probe is immersed in water, the sensor wakes up, does its job, goes to sleep, immediately wakes up again, does its job, goes to sleep and won`t wake up again... Even if I take the probe out of the water and dry it, it gets wet again no longer agitates the module. Only btn wakes him from sleep, detects that he is dry and goes to sleep, again watching and waiting for the leak to be detected. So it has to be??

    BTW, how is work going on connecting PinDeepSlepp with DeepSleep so that you can periodically wake up the module to report the battery status?
  • #17 21014578
    p.kaczmarek2
    Moderator Smart Home
    Mad_Maxs wrote:

    BTW, how is work going on connecting PinDeepSlepp with DeepSleep so that you can periodically wake up the module to report the battery status?

    It is now working and released on N platform, please refer to the following guide:
    BK7231 deep sleep - how to enable wake up both on timer and on GPIO interrupt in OpenBeken?
    We still need to port that to T. If you know C and want to help, give it a go.
    Helpful post? Buy me a coffee.
  • Helpful post
    #18 21183262
    divadiow
    Level 35  
    Here's another variant I didn't think warranted its own thread. This one has a button and some test pads at the bottom of the PCB. FW ver 1.0.6 cloudcutterable.

    No soldering was performed as crocodile clips can easily be attached to all needed contacts for flashing.
    White leak sensor with a button and cable on a blue background. Tuya water leakage detector box with a drawing of the device on the front. Water leak detector packaging with barcodes and manufacturer information. WiFi flood detector instruction manual PCB with Wi-Fi module and wire, without device casing. PCB with electronic components on a blue background. PCB with CB3S module and cables on a blue background. Earykong Wi-Fi flood detector parts with an open case and instructions on a blue background. Open interior of a sensor with a circuit board and CB3S module. PCB with components and alligator clips.

    MC38-CB3S module with labels TXD1, RXD1, GND, and VCC.

    Code: JSON
    Log in, to see the code


    Code: Text
    Log in, to see the code


    autoexec.bat with pindeepsleep. button wakes sensor as does moisture probe status change in either direction (dry/asleep -> wet and wet/asleep -> dry)

    Code: Text
    Log in, to see the code


    OBK template
    Code: JSON
    Log in, to see the code


    https://github.com/OpenBekenIOT/webapp/pull/1...mits/efbc89f895def3b9794163e6b5fb84c8dfcef80c

Topic summary

The discussion revolves around optimizing battery consumption for the CB3S (BK7231N) water leak detector after flashing it with OpenBK7231N firmware. Users explore methods to implement DeepSleep functionality, with suggestions including GPIO wakeup from the water sensor and periodic deep sleep intervals. Issues arise with the sensor not waking from deep sleep upon water detection, requiring modifications such as adding an NPN transistor and pull-up resistors to improve functionality. Users share scripts and configurations, highlighting the importance of correct pin settings and driver compatibility for effective operation. The conversation also touches on firmware updates and the need for specific driver configurations to ensure reliable sensor performance.
Summary generated by the language model.
ADVERTISEMENT