Relay toggle
Good morning everyone,
I have an issue writing a script that I can't figure out on my own, I have a feeling that the answer is stupid but I can't figure out what is going wrong.
I have a BK7231N running the latest 1.17.601 OpenBeken. the device is a simple relay switch with a button.
I am trying to create a script that runs on startup, turns on the relay for 1 minute and then turns it off for 30 minutes, and then loops again, and I tried running the scripts from github and they run perfectly for running and turning off the script using event handlers, but whenever I try to modify those scripts to get it to what I need it to, the device crashes and restarts.
Here's the original script that runs fine unmodified:
// advanced delay script
// See: https://www.elektroda.com/rtvforum/topic4032982.html
// When user toggles relay on, relay will turn off after delay
// The current delay value is displayed on www gui
// The constant delay value is displayed on www gui and fully adjustable and remembered between reboots
// Used channels:
// Channel 1 - relay
// Channel 2 - current countdown value
// Channel 3 - constant time for countdown
// this will make channel 3 save in memory
setStartValue 3 -1
// if channel 3 is not set (default first case), set it to 15 seconds11
if $CH3==0 then setChannel 3 15
// display text field for channel 3 on www page
setChannelType 3 TextField
// set label
setChannelLabel 3 TurnOffTime
// display timer seconds (read only) for channel 2 on www page
setChannelType 2 TimerSeconds
// shorthand for setting channel 2 to value of channel 3
alias turn_off_after_time backlog setChannel 2 $CH3
// shorthand for clearing current timer value
alias on_turned_off setChannel 2 0
// shorthand to set relay off
alias turn_off_relay setChannel 1 0
// check used to turn off relay when countdown value reaches 0
alias do_check if $CH2==0 then turn_off_relay
// an update command; it decreases current countdown by 1 and checks for 0
alias do_tick backlog addChannel 2 -1; do_check
// event triggers for channel 1 changing to 0 and 1
addChangeHandler Channel1 == 1 turn_off_after_time
addChangeHandler Channel1 == 0 on_turned_off
// main loop - infinite
again:
if $CH2!=0 then do_tick
delay_s 1
goto again
I can't figure out what is going wrong or debug it properly, for example, the script crashes when I run something like:
// check used to turn off relay when countdown value reaches 0
alias do_check if $CH2==0 then "backlog turn_off_relay; echo "we are done""
I appreciate the help of anyone who can test this and see if it's a common theme or if it's something wrong I'm doing