logo elektroda
logo elektroda
X
logo elektroda

OpenBeken Script: Interrupt timer in loop and keep channel active

2greatsecret 297 0
ADVERTISEMENT
Treść została przetłumaczona german » english Zobacz oryginalną wersję tematu
  • #1 21330336
    2greatsecret
    Level 1  
    Is there a way to interrupt a loop started in the script?

    I have found the following script in the examples on git, which fulfils part of my intention with a bit of trimming:

    // display seconds timer
    setChannelType 5 TimerSeconds
    // set start values as "remember in flash"
    SetStartValue 4 -1
    SetStartValue 5 -1
    
    // channel 5 is timer
    // channel 4 is relay
    
    // here is countdown value in seconds - 300
    alias turn_off_after_time backlog setChannel 5 300
    alias on_turned_off setChannel 5 0
    alias turn_off_relay setChannel 4 0
    alias do_check if $CH5==0 then turn_off_relay
    alias do_tick backlog addChannel 5 -1; do_check
    
    // this will run the turn off command every time that CH4 becomes 1
    //addChangeHandler Channel4 == 1 turn_off_after_time
    // this will run the turn off command every time that CH4 becomes 0
    addChangeHandler Channel4 == 0 on_turned_off
    
    
    again:
    
    if $CH5!=0 then do_tick
    delay_s 1
    goto again
    

    If I now call the alias "turn_off_after_time" in the browser, the timer counts down the 5 minutes and switches off channel 4.
    But now I want to cancel the timer if necessary so that channel 4 stays on.
    Would be very grateful for any helpful suggestions.
    AI: On which platform or in which environment does the script run?
    OpenBeken

    Just found the solution to the problem myself.
    However, if this is an incorrect solution, please let me know:

    By calling the command "on_turned_off" the timer of channel 5 is set to 0 again and stops counting and channel 4 remains active.
  • ADVERTISEMENT
ADVERTISEMENT