Jump to content

Long Running WAIT Commands


skisteep

Recommended Posts

Posted (edited)

I've researched several threads on the how-to's of using the WAIT Command, but still can't find a definitive answer on the use of long running timers, ie. in the order to 10 to 60 plus minutes, where the probablity of a retrigger of the IF statement may occur prior to the WAIT command running its full time.

 

I would like feedback on this approach so that a proper approach to Long WAIT commands can be used without unexpected results

 

My apologizes if this already has been posted, I haven't been able to find it, and please do post me a link

 

When Definitive Solution is agreed upon, then I'll publish the final version in this starter thread

 

Here is the code I think might work. I'm trying to create a WAIT that works without being prematurely stopped, and callable from other programs.  I would then create Wait 10, Wait 20, etc

 

Wayne

 

>>Edited to combine user input

 

There are two techniques to use WAIT Commands

 

Technique 1 - using Integer Variables as semaphores

 

Program 1 -ENABLED

If
        From    Sunrise +  1 hour
        To      12:00:00PM (same day)
    And $sLuxCurrent_South >= 1500
    And $sLuxAverage_South > 1000
    And $sLuxAverage_South is not 0
    And $ShadesMorningUpDown is 0
    And $ShadesMorningPaused is not 1   Note: this and the first line on the THEN work to stop a rerun of the THEN, this is an Integer variable,     thus doesn't trigger the IF
 
Then
        $ShadesMorningPaused  = 1
        Resource 'Kitchen All Down'
        Resource 'Dining South Awning Open'
        Resource 'Dining West All Up'
        Resource 'Living Room All Up'
        Wait  30 seconds        Note: DO NOT use WAIT commands in the primary program, always call/run a secondary program
        Resource 'Kitchen All Down'
        Resource 'Dining South Awning Open'
        Resource 'Dining West All Up'
        Resource 'Living Room All Up'
        Run Program 'Wait 30' (Then Path)  Note: this runs the program below
 
Else
   - No Actions - (To add one, press 'Action')

 

------------------------------------------------------------------------------------------------

 

Program (WAIT 30) -ENABLED  - Note: Since this program has no IF Command then the THEN can't be rerun, except thru a RUN THEN command

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        Wait  30 minutes
        $ShadesMorningUpDown  = 1
        $ShadesMidDayUpDown  = 0
        $ShadesMorningPaused  = 0  Note: the IF statement in Program 1 above can now be trigger after 30 minutes, and the WAIT used again
 
Else
   - No Actions - (To add one, press 'Action')

 

 

Technique 2 - Using Program DISABLE/ENABLE to block re-evaluation of IF logic - Complements of Larryllix

 

Use the "don't trigger me until I let you" approach.

 

Program 1 [enabled]

If whatever

Then

    Run Program 2 (If)

Else

  --

 

Program 2 [disabled]

If

      non-triggerable conditions

Then

   Disable program 1

   Do something

   WAIT a long time,   <---Program 1 can't touch us

   Do something else

   Enable Program 1

Else

   Do the negative conditions

 

Conclusions:

 

 

 

>>>>>

RULES OF ENGAGEMENT - Long Running WAIT Commands(NON Interruptible)

 

1 - Use a separate Program that contains the WAIT Command, NEVER use WAIT Commands in the Primary Program, per Jerlands comments No matter how tempting it is, the WAIT command can be re-evaluated thus causing your program to exit prematurely.

2 - Use an INTEGER Variable as a semaphore to stop the re-execution of the primary program's THEN
    (see my example above)

3 - Or use a DISABLE command in the program containing the WAIT Command to DISABLE then ENABLE the primary program after the WAIT completes.
    (See larryllix posting)

4 - If you have logic in the WAIT program's IF section, then DISABLE this WAIT Program so that it is only executable via a
    'RUN IF' from a primary program.

5 - If there is NO logic in the IF Section of the WAIT Program, then DISABLE'ing it is not necessary

 

<<<<<<<

 

Also see 'jerlands' posting in this thread on Feb 27, 2016 for a proof of concept with primary program embedded WAIT Commands, still best to use separate program for WAIT commands to eliminate all accidental re-evaluations

Edited by skisteep
Posted

Couple things... your redundancy of  $sLuxAverage_South isn't necessary..  $sLuxCurrent_South >= 1500 should suffice but the problem is $ShadesMorningPaused  = 1 in the Then statement.  This turns the program false and halts everything.  You might put this at the end of the Then actions after another wait of 5 sec or so...

 

Easy way to test programs is to watch them operate :)  Turn Status Icons to Detailed and play with the time and other conditions so you can watch the program operate.

 

 

 

Jon...

Posted

Jon, thanks for the reply,

 

I'm using an integer variable for '$ShadesMorningPaused' so that the IF statement isn't retrigger, so I think that part is ok.  But the two state variables could also async'ly cause a retrigger, but since the '$ShadesMorningPaused' is now equal to '1', then the ELSE triggers, which does nothing.

 

Wayne

Posted (edited)

I apologise if this is not exactly what you are asking for without fully understanding your code.

 

Use the "don't trigger me until I let you" approach.

 

Program 1 [enabled]

If whatever

Then

    Run Program 2 (If)

Else

  --

 

Program 2 [disabled]

If

      non-triggerable conditions

Then

   Disable program 1

   Do something

   WAIT a long time,   <---Program 1 can't touch us

   Do something else

   Enable Program 1

Else

   Do the negative conditions

....

I would like feedback on this approach so that a proper approach to Long WAIT commands can be used without unexpected results

 

.....

Edited by larryllix
Posted (edited)

Jon, thanks for the reply,

 

I'm using an integer variable for '$ShadesMorningPaused' so that the IF statement isn't retrigger, so I think that part is ok.  But the two state variables could also async'ly cause a retrigger, but since the '$ShadesMorningPaused' is now equal to '1', then the ELSE triggers, which does nothing.

 

Wayne

 

I'm using an integer variable for '$ShadesMorningPaused' so that the IF statement isn't retrigger, so I think that part is ok.  <<-- as it is, nothing after that action ($ShadesMorningPaused  = 1) in Then will execute or at least up to the wait.. it should be your last action.

 

Edit: Ok.. I can't read :)

 

Jon...

Edited by jerlands
Posted

HI Larry, thanks for you response,

 

I like your approach, but a couple of issues I've had. 

 

First,  If I DISABLE program 2, then I haven't been able to start it via RUN THEN, haven't tried RUN IF, does that make a difference??

 

Second, I'm using an integer variable to cause Program 1's IF to fail to ELSE, much like your DISABLE on program 1, does that sound like it should work??

 

Wayne

Posted

You can run a disabled program by calling it from another program, that is, run Then or run Else. OTOH, if there are no conditions (i.e, no If statements), than it doesn't matter if the program is disabled or not. The program will run only if it's called from another program.

Posted (edited)

As per Stu above and another way to look at is.

 

Disable/Enable applies to triggers only, not the execution.

 

Program 2 doesn't have any triggers and a disabled program is the place to use conditions  when trigger interference is not desired in that program. This is commonly used for time frames and State variables when the trigger could upset a running program and they are only wanted for their filter condition value.

 

 

Having said all that, if you disable a program while it is running it will stop it at the next Wait or Repeat line.

 

 

Making sense?

Edited by larryllix
Posted

Thanks for all your input, I'll check my programs and retest to make sure I'm not missing something, just seem to not call a DISABLED program, but as stated above, since I'm using an INTEGER VARIABLE as semaphore and I have no IF statements, then I shouldn't need to set it to DISABLED

 

Another questions, do WAIT Commands have there own threads, or do they share a thread, ie. if one WAIT is stopped/interpreted then only that one stops(own thread) or do they all stop(shared thread)??

 

Wayne

Posted (edited)

A Program in a Wait does not stop other Programs in a Wait.  Program 1 could be in a 30 minute Wait.  That will not stop Program 2 in a 5 minute Wait.

Edited by LeeG
Posted (edited)

I would like to thank all these responders for their inputs, they all are some of the most experienced ISY users on this forum and I trust their input.

 

I have written this brief synopsis of their remarks, please feel free to comment or edit, wording can sometimes be inaccurate when stating rules

 

>>>>>

RULES OF ENGAGEMENT - Long Running WAIT Commands(NON Interruptible)

1 - Use a separate Program that contains the WAIT Command

2 - Use an INTEGER Variable as a semaphore to stop the re-execution of the primary program's THEN
    (see my example in the starter posting)

3 - Or use a DISABLE command in the program containing the WAIT Command to DISABLE then ENABLE the primary program after the WAIT completes.
    (See larryllix posting)

4 - If you have logic in the WAIT program's IF section, then DISABLE this WAIT Program so that it is only executable via a
    'RUN IF' from a primary program.

5 - If there is NO logic in the IF Section of the WAIT Program, then DISABLE'ing it is not necessary

Edited by skisteep
Posted

I'm using an integer variable for '$ShadesMorningPaused' so that the IF statement isn't retrigger, so I think that part is ok.  <<-- as it is, nothing after that action ($ShadesMorningPaused  = 1) in Then will execute or at least up to the wait.. it should be your last action.

 

Edit: Ok.. I can't read :)

 

Jon...

Hi Jon,

 

Your response tweaked my interest, at first I thought can't be, because I'm using a INTEGER Variable(non-triggering) as a semaphore to stop the IF logic from running. So I tried a few tests on my code to see, surprise, surprise, you were correct.  The first WAIT in my program above, was causing the remainder of my program to be exited(SOMETIMES).

 

My question is, why??? Shouldn't the semaphore construct work?? Maybe I should put the semaphore at the top of the IF logic, I don't like this approach because it is a workaround(haven't tried this yet)

 

Wayne

Posted

Jon....The Lux variables are updated every 5 min from an external computer via REST commands, so not likely, it just hits the first WAIT 30 sec and exits

 

Wayne

Posted

Your program basically has three triggers...

        From    Sunrise +  1 hour                <<-- This will trigger the program twice, once at Sunrise + 1 hour and again at 12pm  however, the program will remain true within that time frame if all other conditions are met.
        To      12:00:00PM (same day)      

    And $sLuxCurrent_South >= 1500     <<-- This is the only other triggering condition. 

 

 

The rule for wait is it will complete if conditions are not re-evaluated... so either it is completing and the actions are fulfilled or there are problems in their construct.

 

You can test Then actions by right clicking on the program and selecting "Run Then" and with Event Viewer open to level 3 see if the resources are properly called then check your error log to see if problems exist in the resource.

 

You can also test resources individually in Network Resources.

 

 

Jon...

Posted

Jon,

 

Thanks for the info, I've run your suggested test without much success, the Event Viewer doesn't seem to show much, I'm running our of energy on this one, I currently feel the WAIT feature might have a bug or is just not implemented correctly(unexplained re-evaluations).  I've seen several post where others have encountered unexplained issues with WAIT and in the end had to find a workaround such as using a separate program and a clever use of DISABLE/ENABLE programs.

 

I've currently removed all IN THEN 'WAITS', and replaced them with  separate programs and all seems to working

 

Again, thanks for your help

 

Wayne

Posted

For future reference and clarification of Wait..  I have programs that run Wait 26 hours successfully.  The only thing that halts wait from completion is re-evaluation of the conditions.  What was happening in your original program is as there was a change in $sLuxCurrent_South >= 1500 and even though it was greater than 1500 (say 1550) there was a change in that value and the conditions were re-evaluated.  Since the integer variable $ShadesMorningPaused was changed to =1 the conditions were no longer true and Wait terminated.

 

I created a simple program you can observe this happen with.  $s.Test is a state variable, $i.Test is an integer variable  If you start the program off by changing $i.Test to 1 then change $s.Test to 5 the program will turn true and start to run Then.  During the wait period if you change $i.Test to 0 then change $s.Test to 6 you can see the program turn false and wait terminates. 

If
        $s.Test >= 5
    And $i.Test is 1
 
Then
        Wait  60 seconds
        Set 'Light' On
 
Else
        Set 'Light' Off

I hope this clarifies the issue you were having and puts a little light on usage of Wait.

 

Glad to see you got it operating.

 

 

 

Jon...

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...