logo elektroda
logo elektroda
X
logo elektroda

Preventing DeepSleep with button press on TH08 (BK7231N) for autoexec.bat Updates

tahunasky 345 6
ADVERTISEMENT
  • #1 21826680
    tahunasky
    Level 4  
    I have a TH08 / 1? WiFi sensor https://openbekeniot.github.io/webapp/devices/Tuya_TH08.html. I have got it working; however, I want to be able to stop it from going into DeepSleep so I can update autoexec.bat or whatever - pressing the button stops autoexec from starting the DeepSleep command.

    Firmware version: Built on Jan 27, 2026 23:02:13, version 1.18.250

    Config
    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "CBU",
      "flags": "0",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "7": "dInput;5;0",
        "8": "BAT_Relay;3;0",
        "14": "Btn;4;0",
        "16": "WifiLED_n;0;0",
        "20": "CHT83XX_SCK;0;0",
        "22": "CHT83XX_SDA;0;1",
        "23": "BAT_ADC;2"
      },
      "command": "backlog PowerSave 1; startDriver battery; addEventHandler OnHold 14 stopAllscripts; startDriver CHT83XX; CHT_Calibrate 0 6",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }
    


    autoexec.bat
    
    CHT_Calibrate 0 6
    
    setChannelType 0 Temperature_div10
    setChannelType 1 Humidity
    waitFor MQTTState 1
    delay_s 1
    publish temp-humdity/device_1 "{"temp":$CH0,"humdity":$CH1,"bat_voltage":$batteryVoltage,"bat_percent":$batteryLevel}" 1
    delay_s 30
    DeepSleep 180
    


    The button is attached to P14 on the WiFi module.
    If I add "addEventHandler OnHold 14 stopAllscripts" to configuration, it doesn't execute autoexec.bat.
    If I put "addEventHandler OnHold 14 stopAllscripts" at the beginning of autoexec.bat, it doesn't work.

    The log shows it is registering the button press when I don't press it if added to configuration/template, but stops autoexec from running.
    
    Info:SENSOR:DRV_CHT83XX_ReadEnv: Temperature:32.968750C Humidity:72.519165%
    Info:MAIN:Time 454, idle 63163/s, free 71656, MQTT 1(1), bWifi 1, secondsWithNoPing 383, socks 2/38 POWERSAVE
    Info:GEN:14 Button_OnLongPressHold
    Info:EVENT:EventHandlers_FireEvent: executing command stopAllscripts
    Info:GEN:14 Button_OnLongPressHold
    Info:EVENT:EventHandlers_FireEvent: executing command stopAllscripts
    Info:GEN:No change in channel 0 (still set to 329) - ignoring
    
    Info:GEN:No change in channel 1 (still set to 72) - ignoring
    


    At the moment, I have delay_s 30 in autoexec.bat to give me time to do updates, etc.

    How can I get this to work, or is there something else I can do to stop the device from going into DeepSleep until I reboot?

    Thanks
    AI: Just to clarify, when you press and hold the button on P14, do you want the device to completely skip entering DeepSleep for that cycle, or should it stay awake until you manually trigger DeepSleep again?
    stay awake until I reboot
    AI: After the stopAllscripts command is executed (as shown in your logs), does the device still go into DeepSleep, or does something else happen? Are there any error messages or unexpected behaviors in the logs after this point?
    No, it does not run autoexec.bat, so it doesn't go into DeepSleep
  • ADVERTISEMENT
  • #2 21829397
    p.kaczmarek2
    Moderator Smart Home
    Hey, can you check if this "ghost click" is fixed by this PR?
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1922

    Or maybe this button is active-high? And you need Btn_n or something?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #4 21829494
    meaverick
    Level 27  
    The so called "sleep" is to switch off the power supply but it still runs 5VDC standbay. The problem is with SSD's no 12VDC at 5VDC will not fire. Most computers have this problem. The only option is to switch off hard, and resume ON.
  • #5 21831440
    tahunasky
    Level 4  
    >>21829397 I don't think it is the same thing, as PIN 14 is 1 if it wakes from sleep or boots after the battery is put in. It's the default state of the pin. I tied Btn_n, Btn_pd, and Btn_pd_n — all the same result. Only way I could get it to work was to set pin "14": "dInput;4;0", then check channel 4 in autoexec.bat. addEventHandler OnHold 14 never worked.
    Not sure how other templates that had addEventHandler OnHold 14 in them worked — unless there are variations in the board, even though my board looked identical.
  • #6 21831442
    insmod
    Level 31  
    >>21831440
    There was a bug with btn since 1.18.248, but it was fixed yesterday.
    Try last release.
  • ADVERTISEMENT
  • #7 21831443
    tahunasky
    Level 4  
    >>21831442 OK, thanks for the info. Will try tomorrow and post back here if I get it to work.

Topic summary

The discussion focuses on preventing the TH08 WiFi sensor (based on the BK7231N chip) from entering DeepSleep mode to allow updates to the autoexec.bat script. The device runs firmware version 1.18.250 built on January 27, 2026. The user seeks a method to interrupt or disable DeepSleep via a button press, which currently stops autoexec from initiating the DeepSleep command. The device configuration includes pin assignments for input, button, relay, and sensors, with commands set to enable power saving, battery driver, and event handlers for button hold actions. The goal is to modify or control the DeepSleep behavior programmatically or through hardware input to facilitate firmware or script updates without the device entering low-power sleep prematurely.
Summary generated by the language model.
ADVERTISEMENT