Thank you.... Changed as suggested by you. Working now as needed.
Please guide me on the following:-
I have set CH15 as the inching timer. Can I update this text field value from Home Assistant?
Kindly guide
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam
setChannelType 2 TimerSeconds
alias turn_off_after_time backlog setChannel 2 $CH15
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
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
again:
if $CH2!=0 then do_tick
delay_s 1
goto againciknururko wrote:
1. In addition to my current autoexec.bat, how can I set a time function so that at a specified time the switch gets TURN ON or TURN OFF?
e.g. if current_time == 17:00, turn off switch.
ciknururko wrote:
2. How to make the switch turn on after 5 seconds when the main power to the switch is turned on?
// your current autoexec.bat here
// now delay
delay_s 5
// now power ON
POWER ON
// your current autoexec.bat here
// now delay
delay_s 5
// now power ON
setChannel 1 1
// This command will turn on relay on CH1 after 10 seconds
// addRepeatingEvent [IntervalSeconds][RepeatsOr-1][CommandToRun]
addRepeatingEvent 10 1 setChannel 1 1
p.kaczmarek2 wrote:// your current autoexec.bat here
// now delay
delay_s 5
// now power ON
POWER ON
p.kaczmarek2 wrote:This can be done with addClockEvent function.
setChannelType 2 TimerSeconds
alias turn_off_after_time backlog setChannel 2 $CH15
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
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
startDriver ntp
ntp_timeZoneOfs +05:30
alias plug_on backlog POWER ON
waitFor NTPState 1
if $hour>=14&&$hour<21 then plug_on
again:
if $CH2!=0 then do_tick
delay_s 1
goto again//autoexec.bat
//some commands in autoexec.bat
function.bat
//function.bat (this is another file created)
startDriver ntp
ntp_timeZoneOfs +05:30
delay_s 5
POWER ON
alias plug_on backlog POWER ON
alias plug_on backlog setChannel 1 1
addChangeHandler Channel1 == 1 turn_off_after_time
startScript [FileName] [Label] [UniqueID]
startScript myBat.bat * 12345
p.kaczmarek2 wrote:startScript myBat.bat * 12345
p.kaczmarek2 wrote:alias plug_on backlog setChannel 1 1
setChannelType 2 TimerSeconds
alias turn_off_after_time backlog setChannel 2 $CH15
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
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
startDriver ntp
ntp_timeZoneOfs +05:30
alias plug_on backlog setChannel 1 1
waitFor NTPState 1
if $hour>=14&&$hour<21 then plug_on
again:
if $CH2!=0 then do_tick
delay_s 1
goto again
alias plug_on backlog setChannel 1 1
alias plug_on backlog setChannel 1 1; turn_off_after_time
// TODO: adjust second 15 here
setChannel 15 15
setChannelType 15 TextField
setChannelLabel 15 TurnOffTime
setChannelType 2 TimerSeconds
alias turn_off_after_time backlog setChannel 2 $CH15
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
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
startDriver ntp
ntp_timeZoneOfs 1
alias plug_on backlog setChannel 1 1
waitFor NTPState 1
if $hour>=14&&$hour<21 then plug_on
again:
if $CH2!=0 then do_tick
delay_s 1
goto again
setStartValue 5 -1
setChannelType 5 TextField
setChannelLabel 5 TurnOffTime
setChannelType 2 TimerSeconds
alias turn_off_after_time backlog setChannel 2 $CH5
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
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
startDriver ntp
ntp_timeZoneOfs 1
alias plug_on backlog setChannel 1 1
waitFor NTPState 1
if $hour>=14&&$hour<21 then plug_on
again:
if $CH2!=0 then do_tick
delay_s 1
goto again
ciknururko wrote:
No, nothing like that... I was just curious if it can be used in that manner.
ciknururko wrote:
Is there a way to check from HA if an update is available for the plug?
e.g. For Chipset: BK7231N Build: Build on Nov 13 2023 14:23:53 version 1.17.308 is the latest.
ciknururko wrote:
Secondly, I am having a very peculiar issue. If the plug is powered ON and is detected by HA. After some time, if I restart HA, after the restart the plug is shown as unavailable in HA until I manually toggle it. Any idea why this is happening?
p.kaczmarek2 wrote:It is a bit problematic because GitHub is now HTTPS-only and the current version of OBK can't make HTTPS requests, only HTTP. Still, why do you want to update that often?
p.kaczmarek2 wrote:I would fix it just by enabling "broadcast self state every N seconds" in flags
p.kaczmarek2 wrote:However, I don't think that we can run JavaScript in HA. I haven't tried doing that kind of thing yet. Do you know how we could do an HTTPS GET on the HA side?
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.batfor 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,
-1relay startup, and a retained low-numbered channel for timers solved LED control, power-loss behavior, and Home Assistant automation.
delay_s 5 before POWER ON or setChannel 1 1. [#20819243]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]-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]-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]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]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]-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]configuration.yaml for integrating that value into Home Assistant behavior. [#20802077]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]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]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]