logo elektroda
logo elektroda
X
logo elektroda

Turning Off LED on Tuya AU LSPA9 Smart Socket After Successful Openbeken Flash

ciknururko 6897 57
Best answers

How can I turn off the LED on a Tuya AU LSPA9 smart socket after flashing OpenBeken so it no longer stays on all the time?

Identify which GPIO drives the LED, then remap it in the template so it follows the socket state instead of staying always on. For this device, the template decode showed a CB2S/BK7231N module with the WiFi LED on P8 [#20796031] After changing the mapping from “WiFi LED on P8” to “LED_N on P8,” the LED started toggling correctly with the plug state [#20796043]
Generated by the language model.
ADVERTISEMENT
  • #1 20795936
    ciknururko
    Level 3  
    Posts: 44

    White smart plug with Ozone logo and blue LED, next to a smartphone.

    Flashed the above plug successfully with openbeken and with profile "Tuya AU LSPA9? Smart Socket: Energy Monitoring"

    Now the plug is getting turned on and off, energy, power figures are showing.

    How to turn off the LED on the plug when the plug is turned off? The LED on the power button on the switch always stays ON.

    Kindly guide.
  • ADVERTISEMENT
  • #2 20795962
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Hello, have you tried to do GPIO extraction to figure out which GPIO is used for LED?
    https://www.youtube.com/watch?v=WunlqIMAdgw&ab_channel=Elektrodacom
    Please post extracted JSON here.
    Helpful post? Buy me a coffee.
  • #3 20796024
    ciknururko
    Level 3  
    Posts: 44
    Code: JSON
    Log in, to see the code
  • #4 20796031
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Now you can use:
    https://openbekeniot.github.io/webapp/templateImporter.html
    I can see that it can decode following GPIOs:
    
    Device seems to be using CB2S module, which is BK7231N chip.
    - Relay (channel 1) on P26
    - WiFi LED on P8
    - Button (channel 1) on P10
    - BL0937 ELE on P7
    - BL0937 VI on P6
    - BL0937 SEL on P24
    

    Is the LED you are referring to on P8?
    Helpful post? Buy me a coffee.
  • #5 20796043
    ciknururko
    Level 3  
    Posts: 44

    Yes (Changed WiFi LED on P8 to LED_N on P8) which is now toggling the LED.

    Also, the device is not remembering the last state... Kindly help how to fix this?
  • ADVERTISEMENT
  • #6 20796260
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    You can configure "Remember last state" in startup options, set it to -1 to remember the state before reboot
    Helpful post? Buy me a coffee.
  • #7 20796323
    ciknururko
    Level 3  
    Posts: 44
    Where exactly is this option? Kindly share a screenshot.

    Also plz guide how to set "inching" time for the switch..
  • ADVERTISEMENT
  • #8 20796861
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Config -> Configure Startup - > enter -1 in field for relay channel

    What do you mean with inching, do you want it to open itself back when it's closed?
    Helpful post? Buy me a coffee.
  • #9 20797236
    ciknururko
    Level 3  
    Posts: 44
    Screenshot showing the Inching feature settings, allowing automatic device shutdown.

    Like shown in the screenshot. I have another WiFi plug (same model) which I haven't flashed with OpenBeken yet. So there is an option for inching as described in the screenshot. Can the same functionality be achieved with OpenBeken?

    Kindly guide.


    Added after 1 [hours] 27 [minutes]:

    >>20796861
    Please guide how to auto turn off the switch after N number of minutes.

    Eg if I turn on the switch, then it should automatically turn off after 20 minutes.

    How to do this via openbeken??

    Kindly guide
  • #10 20797359
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Here is a simplest script that will watch for the channel 1 change to state 1 (relay on) and turn it off back to 0 (relay open) after 10 seconds:
    
    
    // This aliased command will turn off relay on CH1 after 10 seconds
    // addRepeatingEvent	[IntervalSeconds][RepeatsOr-1][CommandToRun]
    alias turn_off_after_time addRepeatingEvent 10 1 setChannel 1 0
    // this will run the turn off command every time that CH1 becomes 1
    addChangeHandler Channel1 == 1 turn_off_after_time 
    

    Following script needs to be put in autoexec.bat in LittleFS. Make sure to check if you are using the correct channel, some people are using Channel 0 instead of 1.

    Also remember to change the time (value 10 in the script) to suit your needs. The following value is in seconds.
    Helpful post? Buy me a coffee.
  • #11 20797375
    ciknururko
    Level 3  
    Posts: 44

    It worked, but now the button is turning on automatically. It's not remembering the last state. How to fix this?

    Kindly guide.
  • #12 20797388
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    What do you mean by "turning on" automatically?

    The countdown timer is not kept after reboot. If you want countdown timer to be kept after reboot, you most likely need to use a channel as a variable.
    Helpful post? Buy me a coffee.
  • #13 20797399
    ciknururko
    Level 3  
    Posts: 44

    I mean if the switch is turned off by me and then the power goes. Now after power comes, the switch should be in the off state but now it's getting turned on.

    In startup options, I have already given -1.

    Before the script, it was working fine. After using the script, it's not remembering the last state.

    Also, now I have deleted the script, restarted the plug, but it's not remembering the last state.

    What do I do now so that the plug remembers the last state? (In startup options, I have already given -1)

    Also, if you are using a mobile, then there is no way to give -1 as it only shows a numeric keyboard.
  • #14 20797440
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    You must have a configuration error. Maybe wrong startup value. It worked for me.

    Still, here is a script that tries to remember the countdown value between reboots and displays timer on gui:
    Screenshot of the OpenBK7231T interface showing relay status and a timer countdown set to 27 seconds.
    
    
    // display seconds timer
    setChannelType 2 TimerSeconds
    // set start values as "remember in flash"
    SetStartValue 1 -1
    SetStartValue 2 -1
    
    // channel 2 is timer
    // channel 1 is relay
    
    // here is countdown value in seconds - 30
    alias turn_off_after_time backlog setChannel 2 30
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    
    // this will run the turn off command every time that CH1 becomes 1
    addChangeHandler Channel1 == 1 turn_off_after_time 
    // this will run the turn off command every time that CH1 becomes 0
    addChangeHandler Channel1 == 0 on_turned_off
    
    
    again:
    
    if $CH2!=0 then do_tick
    delay_s 1
    goto again
    

    It uses channel 1 as a relay and channel 2 as a timer variable
    Helpful post? Buy me a coffee.
  • #15 20797454
    ciknururko
    Level 3  
    Posts: 44

    Thank you for the script.

    How to fix the configuration error? The switch is still not remembering the last state? Do I have to reset the switch?
  • #16 20797488
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    If your switch is still not remembering the last state, then you have to show me your full device configuration, screenshots from the pages, from startup, etc, from pins, and your current script.

    I have a LSPA-like socket at hand and it remembers the relay state:
    Screenshot of the OpenBK7231T device control panel displaying OFF status.
    Helpful post? Buy me a coffee.
  • #17 20797512
    ciknururko
    Level 3  
    Posts: 44

    I have reset the switch, now it's remembering the last state.

    The next time, if it does not remember the last state, I will give you the screenshots you asked for.

    I think I am ready to flash my other plugs now. But before that, I have a few questions:

    1. Can I switch between Esphome and openbeken?
    2. Can I go back to the original tuya firmware if I ever want to?
    3. How do I take a backup of settings, etc., so that it can be restored if I ever want to reset the switch?

    Really, thank you for your patience and time. I really appreciate your help and cooperation.
  • #18 20797521
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    1. They have created some strange OTA format so going to BK is problematic, so I would not recommend that. It's possible, but problematic
    2. You can do that easily if you flash 2MB backup back with UART programmer wires
    3. In the Web App, you can either:
    - copy device template as text and autoexec as text
    - download full CFG partition (that will also contain your ssid, etc, much more info than just device template)
    Helpful post? Buy me a coffee.
  • #19 20797979
    ciknururko
    Level 3  
    Posts: 44
    Thank you
  • ADVERTISEMENT
  • #20 20797988
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Keep in mind that autoexec.bat is not in the CFG partition, so make sure to store it as well.
    Helpful post? Buy me a coffee.
  • #21 20798855
    ciknururko
    Level 3  
    Posts: 44

    Ok. Thank you again for your kind help and cooperation.
  • #22 20800122
    ciknururko
    Level 3  
    Posts: 44

    I flashed one more plug of the same model. But this time I chose "Cut from cloud". I can control the plug using tinytuya. Is there any Android app by which I can control the plug?

    Kindly reply.
  • #23 20800222
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    I think the Tasmota Control and similiar apps should work for you.

    See example here:


    Helpful post? Buy me a coffee.
  • #24 20800249
    ciknururko
    Level 3  
    Posts: 44
    If flashed with openbeken firmware then "Tasmota Control" app works.

    I was asking if we choose only to "Cut from Cloud" then is there any android app available that can control such plugs ?
  • #25 20800338
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Sorry, I don't know much about the "cut from cloud" option, I heard that it's possible to use Tuya Local HASS integration for that, but not many people are using that.
    Helpful post? Buy me a coffee.
  • #26 20800421
    ciknururko
    Level 3  
    Posts: 44
    Ok... thank you
  • #27 20801662
    ciknururko
    Level 3  
    Posts: 44

    Hello,

    Need a little guidance,

    This is the script that you posted

    // This aliased command will turn off relay on CH1 after 10 seconds
    // addRepeatingEvent [IntervalSeconds][RepeatsOr-1][CommandToRun]
    alias turn_off_after_time addRepeatingEvent 10 1 setChannel 1 0
    // this will run the turn off command every time that CH1 becomes 1
    addChangeHandler Channel1 == 1 turn_off_after_time


    Instead of hardcoding the time e.g. 10 seconds in the auto exec.bat file, can we have a TEXTFIELD on the main GUI page to enter the time in seconds and have a button like SET to save the entered time for inching.

    Something like in the screenshot.
    Screenshot showing a text field with the value 0 and a button labeled Set.

    If the value in the TEXTFIELD is zero, then inching is disabled and the plug will turn off when the user turns it off manually. If there is a value in the TEXTFIELD, then the plug will turn off after that many seconds which is entered in the TEXTFIELD.

    This will help many users like me.

    Kindly help.
  • #28 20801729
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Well, then you need to choose a channel, let's say $CH5, set it to TextField, and then, in the timer code, change the constant 10 to $CH5, which means "current value of channel 5".
    Helpful post? Buy me a coffee.
  • #29 20801795
    ciknururko
    Level 3  
    Posts: 44

    alias turn_off_after_time addRepeatingEvent $CH15 1 setChannel 1 0
    addChangeHandler Channel1 == 1 turn_off_after_time

    Don't like above. But what if the value in TEXTFIELD is zero, then the switch just turns on and then off. Yes because the value is zero. So how can I just disable the alias "turn_off_after_time" if the value in TEXTFIELD is zero and in such a case the switch has to be manually switched off.

    Kindly guide
  • #30 20801960
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14604
    Help: 654
    Rate: 12618
    Here are our examples:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    You can base your code on that line:
    
    alias do_check if $CH2==0 then turn_off_relay 
    

    Just change the variables and condition, use:

    instead of equality check.
    Helpful post? Buy me a coffee.

Topic summary

✨ The discussion revolves around the Tuya AU LSPA9 Smart Socket, which was successfully flashed with OpenBeken firmware. The main issue addressed is how to turn off the LED indicator on the device when it is powered off. Users explored GPIO extraction to identify the LED control pin and confirmed that the LED is connected to GPIO P8. Solutions were proposed to configure the device to remember its last state after reboot and to implement a countdown timer for automatic shutoff after a specified duration. Users also discussed integrating the device with Home Assistant for remote control and setting inching timers via a GUI. Additionally, there were inquiries about switching between firmware versions and backing up settings.
Generated by the language model.

FAQ

TL;DR: For BK7231N/CB2S LSPA9 plugs, 6 GPIOs were identified, and one fix solved the main issue: change P8 from WiFi LED to LED_N. As the expert said, "set it to -1" to restore last-state memory, then use autoexec.bat for auto-off timers, startup delays, and NTP-based schedules. [#20796861]

Why it matters: This FAQ gives OpenBeken users a fast, reusable path to fix LED behavior, restore state memory, add inching, and expose controls to Home Assistant.

Option What it does Main advantage Main limitation
Full OpenBeken flash Replaces Tuya firmware Web UI, scripts, MQTT, Tasmota Control support Moving to ESPHome is possible but problematic on BK devices
"Cut from cloud" Keeps local Tuya-style control without cloud Works with TinyTuya Android app path was unclear in the thread
Restore original Tuya Flash back a 2 MB backup over UART Returns stock behavior Requires prior backup and wired flashing

Key insight: Most problems in this thread were configuration issues, not hardware faults. Correct pin mapping, -1 relay startup, and a retained low-numbered channel for timers solved LED control, power-loss behavior, and Home Assistant automation.

Quick Facts

  • The decoded CB2S/BK7231N template exposed 6 key pins: relay P26, WiFi LED P8, button P10, BL0937 ELE P7, BL0937 VI P6, and BL0937 SEL P24. [#20796031]
  • The original device JSON showed power-monitoring protection values of 10,500 mA over-current, 275 V over-voltage, and 85 V low-voltage on the same LSPA9 plug family. [#20796024]
  • Auto-off examples in the thread used 10 s, 15 s, and 30 s timers, and one user target was 20 minutes after turn-on. [#20797359]
  • A startup automation example delayed relay activation by 5 seconds after mains power returned, using delay_s 5 before POWER ON or setChannel 1 1. [#20819243]
  • For retained user-set timers, only the first ~10 channels can be remembered in flash, so the working solution moved the delay value from CH15 to CH5. [#20823023]

How do I turn off the power button LED on a Tuya AU LSPA9 smart socket after flashing OpenBeken?

Change the LED pin role from the default WiFi LED to LED_N on P8. In the thread, that change made the button LED start toggling correctly instead of staying on when the relay was off. If your socket uses the same CB2S layout, P8 is the first pin to test for LED behavior after flashing. [#20796043]

What's the correct GPIO mapping for the LED, relay, button, and BL0937 on a CB2S-based Tuya AU LSPA9 smart plug?

The decoded mapping was relay P26, WiFi LED P8, button P10, BL0937 ELE P7, BL0937 VI P6, and BL0937 SEL P24. The module was identified as CB2S, which uses a BK7231N chip. That mapping came directly from the extracted Tuya JSON and the template importer decode. [#20796031]

How can I make an OpenBeken-flashed smart plug remember its last relay state after a power loss or reboot?

Set the relay startup value to -1 so OpenBeken restores the state from before reboot. In the thread, the plug remembered state correctly before a script change, then worked again after a reset and correct startup configuration. If it still powers on unexpectedly, check startup values, scripts, and pin configuration first. [#20796260]

Where do I set the OpenBeken startup option to use "Remember last state" with a value of -1?

Open Config -> Configure Startup and enter -1 for the relay channel. The expert answer was exact: "enter -1 in field for relay channel." One mobile limitation appeared in the thread: some phones show a numeric keyboard that makes typing a minus sign difficult. [#20796861]

What is GPIO extraction in OpenBeken, and how do I use the template importer to identify pins on a Tuya plug?

"GPIO extraction" is a device-analysis method that reads Tuya configuration data, identifies which MCU pins drive relay, LEDs, buttons, and sensors, and converts that data into a usable OpenBeken pin map. Use it in 3 steps: 1. Extract the device JSON. 2. Paste it into the web template importer. 3. Read the decoded pin assignments, such as P8, P10, and P26 on this plug. [#20796031]

How can I create an inching or auto-off timer in OpenBeken so the socket turns off after a set number of seconds or minutes?

Use autoexec.bat with a change handler that starts a countdown when the relay turns on. The simplest working example was: alias turn_off_after_time addRepeatingEvent 10 1 setChannel 1 0 plus addChangeHandler Channel1 == 1 turn_off_after_time. Change 10 to any delay in seconds, or build a channel-based countdown for longer periods. [#20797359]

What is autoexec.bat in OpenBeken, and how is it used for relay timers, startup behavior, and automation scripts?

"autoexec.bat" is an OpenBeken startup script file that runs commands automatically after boot, stores automation logic, and can control relays, timers, NTP actions, and channel behavior without manual clicks. In this thread it was used for auto-off countdowns, a 5-second delayed power-on, and clock-based control. It is stored separately, so backing up only the CFG partition is not enough. [#20797988]

How do I add a TextField channel in OpenBeken so the turn-off delay can be changed from the web UI instead of hardcoding the time in the script?

Create a channel as TextField, then reference that channel in the timer alias instead of a fixed number. The thread's working approach used a user-editable channel and replaced the hardcoded delay with $CHx, so the web UI value became the active turn-off delay. If the field is 0, add a condition so auto-off stays disabled. [#20801960]

Why does an OpenBeken timer script stop the plug from remembering the last state, and what configuration mistakes should I check?

A timer script usually breaks last-state behavior because of configuration errors, not because timers are unsupported. Check 3 items: 1. Relay startup is still -1. 2. Your current script does not force setChannel 1 1 on boot. 3. Pin and startup pages match the real hardware. In the thread, a reset restored correct behavior, which strongly pointed to a bad configuration state. [#20797512]

How can I update an OpenBeken channel value such as an inching timer from Home Assistant over MQTT?

Publish the new value to the channel's MQTT topic from Home Assistant. The expert explained that OpenBeken channels are fully scriptable variables, so a retained TextField channel such as CH5 can hold the delay and be changed externally. The thread specifically points to channel MQTT topics and configuration.yaml for integrating that value into Home Assistant behavior. [#20802077]

What is the difference between flashing full OpenBeken firmware and using the "Cut from cloud" option on a Tuya plug?

Full OpenBeken flashing gives you the OpenBeken web UI, scripts, and app compatibility such as Tasmota Control, while "Cut from cloud" only removed cloud dependence and still let the user control the plug with TinyTuya. The thread did not confirm a dedicated Android app for the "Cut from cloud" path, and even the expert marked that area as less commonly used. [#20800338]

OpenBeken vs ESPHome on BK7231N plugs: which is easier to switch to, and what are the limitations of moving between them?

OpenBeken was the easier path in this thread, and switching from ESPHome back to BK firmware was described as possible but problematic because of a "strange OTA format." Returning to original Tuya firmware was easier if you had a 2 MB backup and a UART programmer. So the safe rule is: experiment only after you save a wired restore image first. [#20797521]

How do I back up and restore an OpenBeken device, including the CFG partition, template, and autoexec.bat, before experimenting with settings or firmware changes?

Back up three things: the device template text, the autoexec.bat text, and the full CFG partition. The web app can export the template and download the CFG partition, which includes much more than the template, including SSID-related data. To restore stock Tuya later, flash back the 2 MB backup over UART. Do not forget that autoexec.bat is not inside the CFG partition. [#20797988]

What's the best way to schedule a Tuya/OpenBeken plug to turn on or off at a specific time using addClockEvent, NTP, or startup scripts?

Use addClockEvent for exact clock times and start NTP first. The working pattern is: 1. startDriver ntp 2. set ntp_timeZoneOfs such as +05:30 3. add a clock event or a boot-time delay script like delay_s 5 then POWER ON. The thread also confirmed that addClockEvent does not support combining if ... then as a time-range zone in one command. [#20823941]

How could Home Assistant check whether a newer OpenBeken OTA build is available for a BK7231N device, such as by using REST commands or another HTTPS-based method?

Do the update check on the Home Assistant side with an HTTPS-capable method such as rest_command. The thread ruled out a simple device-side check because the current OpenBeken build could make only HTTP requests, while GitHub releases are HTTPS-only. The suggested direction was to port the web app's release-check logic to Home Assistant instead of the plug itself. [#20830904]
Generated by the language model.
ADVERTISEMENT