Jump to content

if then wait


vbPhil

Recommended Posts

Posted

The Wiki says when a program encounters a Wait statement it rechecks the program conditions and if they are False the program ends.

What about when the program is already in the Wait state and the the Conditions go False. Will the program end or stop?

This is what I'm seeing so it must be so. Just wanted to confirm that is correct. If so, the Wiki could be a little more clearer about this.

What I have is a program that is triggered by a State Variable changing from 0 to 1. It then turns a device on and Waits for 25 minutes, then turns the device Off. What I see is while the program is in the Wait state and the condition trigger goes False (returns to 0) the program never executes the device Off command.

 

If
        $WirelessWaterSensor is 1
Then
        Send Notification to 'Email' content 'Swamp Tank Full'
        Set 'OR-Xmas_Austrian' On
        Wait  25 minutes 
        Set 'OR-Xmas_Austrian' Off
Else
   - No Actions - (To add one, press 'Action')

 

Posted (edited)

I dont believe that a wait statement will force a re-evaluation of the conditions.  However, if a triggering event occurs during a wait statement, further execution will halt, and start at the beginning action based upon whether the new condition being true (runs THEN path) or false (runs ELSE path).  
 

in your case, if a triggering event (variable changing value is a triggering event) during the 25 minute wait, further execution will halt and, given that the new condition is now false, will run the ELSE path, which has nothing in it.

Edited by oberkc
Posted

A Wait line in any program releases the capture of it's time slice to the ISY engine so that the ISY engine can process other time slices, including evaluation of programs conditions and trigger events.

Wait does not cause conditions to be evaluated. It only allows triggers to be handled. If there is a new trigger in the same program's condition lines in it's If section, the program will stop and start in the section Then or Else depending on the If section's logic outcome.

Without a Wait or Repeat line in a program it will execute atomically without any interuption. I/O and other ISY events will not be processed during that time period.

Posted

Here's the Wiki's description.

Quote

 

The program's conditions are reevaluated each time a Wait or Repeat statement is encountered, and at the end of each iteration of a Repeat loop.

What this means is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or the Then clause).

 

https://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Scope,_Precedence_and_Execution_Order

I guess what has me wondering is what this statement means:  "current atomic statement group"  So what is meant by "atomic"? 

Posted (edited)
8 hours ago, vbphil said:

Here's the Wiki's description.

https://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Scope,_Precedence_and_Execution_Order

I guess what has me wondering is what this statement means:  "current atomic statement group"  So what is meant by "atomic"? 

Inseparable

The wiki states.

Quote

A series of statements within a Then clause (or within an Else clause), up to the next Wait or Repeat statement, are atomic. In other words, all such statements are executed before the conditions of the program are retested.

@Michel KohanimThat is incorrect and should read. "...all such statements are executed before the conditions of the program can may  be retested" The following wiki paragraphs are nonsense based on a false assumption.

Edited by larryllix
abilty changed to permission "may"
Posted (edited)

 

14 hours ago, vbphil said:

If

 

        $WirelessWaterSensor is 1
Then
        Send Notification to 'Email' content 'Swamp Tank Full'
        Set 'OR-Xmas_Austrian' On
        Wait  25 minutes 
        Set 'OR-Xmas_Austrian' Off
Else
   - No Actions - (To add one, press 'Action')

 

If you want to fix it so that the program will always finish it needs to be broken into two programs:

 

Program 1

If

        $WirelessWaterSensor is 1
Then
         Run Program 2 (then)
Else
   - No Actions - (To add one, press 'Action')

 

Program 2 (Disabled)

If

         (nothing)
Then

         Disable Program 1
        Send Notification to 'Email' content 'Swamp Tank Full'
        Set 'OR-Xmas_Austrian' On
        Wait  25 minutes 
        Set 'OR-Xmas_Austrian' Off

        Enable Program 1
Else
   - No Actions - (To add one, press 'Action')

 

Reminder Disabled means that a program won't run because of a change in the evaluation of the If statement.  A Disabled program will still run when called by another program.  (Disabled doesn't mean Never).  It should also be noted the second program must disable the first or the same issue will occur as when it was one program.

Edited by MrBill
Posted (edited)
29 minutes ago, MrBill said:

 

If you want to fix it so that the program will always finish it needs to be broken into two programs:

 

Program 1

If

        $WirelessWaterSensor is 1
Then
         Run Program 2 (then)
Else
   - No Actions - (To add one, press 'Action')

 

Program 2 (Disabled)

If

         (nothing)
Then

         Disable Program 1
        Send Notification to 'Email' content 'Swamp Tank Full'
        Set 'OR-Xmas_Austrian' On
        Wait  25 minutes 
        Set 'OR-Xmas_Austrian' Off

        Enable Program 1
Else
   - No Actions - (To add one, press 'Action')

 

Reminder Disabled means that a program won't run because of a change in the evaluation of the If statement.  A Disabled program will still run when called by another program.  (Disabled doesn't mean Never).  It should also be noted the second program must disable the first or the same issue will occur as when it was one program.

Thanks Mr. Bill.

I had the same thought as I've used this 2 program technique before but for different reasons. What got me caught up this time was my trigger was resetting to "0" after about a minute, thus I was seeing program operation I was unfamiliar with. I think I'm getting it now.

However, one more question. If a program like my example is in the Wait state and it gets triggered True again does it complete the Wait state it's currently in or will the Then clause start over again?

Edited by vbphil
misspelled
Posted
45 minutes ago, vbphil said:

Here's the Wiki's description.

https://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Scope,_Precedence_and_Execution_Order

I guess what has me wondering is what this statement means:  "current atomic statement group"  So what is meant by "atomic"? 

Guaranteed to fully complete or not at all. 

In essence, if your if statement changes during the wait, it will not complete. If things remain the same, it will. 

Using my living room lights for example, depending on how bright or dark the room is, they'll turn on/off automatically during the day if occupied. The program is written: if LR lights are off and it's too dark then wait 10 minutes and turn lights on (paraphrasing). The opposite will turn the lights off. 

What happens is if it stays dark long enough the lights will turn on. A passing cloud may make it dark temporarily but due to the wait (unless it hangs around), the lights do not turn on. The same with the off. If the lights are on and it becomes bright (assume a stormy day) due to a short break in the storm, the lights will stay on.

That's an example of atomic. It'll either complete or it wont

Posted
12 minutes ago, vbphil said:

However, one more question. If a program like my example is in the Wait state and it gets triggered True again does it complete the Wait state it's current in or will the Then clause start over again?

It starts over.

I wasn't sure, so I created this quick program:

AA testor - [ID 016B][Parent 0001]

If
        $stemp_test >= 1
 
Then
        Set 'LR Lamp 1' On
        Set 'LR Lamp 2' Off
        Wait  5 minutes 
        Set 'LR Lamp 1' Off
        Set 'LR Lamp 2' On
 
Else
   - No Actions - (To add one, press 'Action')
 

to start $stemp_test was 0, I turned on Lamp 2 manually, lamp 1 was off.

then I changed the value of $stemp_test to 1 and as expected lamp 1 came on lamp 2 went off

then I manually turned on lamp 2 again

then I changed $stemp_test value to 2 and lamp2 turned off again, lamp 1 stayed on.

Posted
1 hour ago, larryllix said:

That is incorrect and should read. "...all such statements are executed before the conditions of the program can be retested" The following wiki paragraphs are nonsense based on a false assumption

Why is it incorrect? The condition does not get retested before the next Wait or Repeat.

With kind regards,
Michel

Posted
1 hour ago, MrBill said:

It starts over.

I wasn't sure, so I created this quick program:

AA testor - [ID 016B][Parent 0001]

If
        $stemp_test >= 1
 
Then
        Set 'LR Lamp 1' On
        Set 'LR Lamp 2' Off
        Wait  5 minutes 
        Set 'LR Lamp 1' Off
        Set 'LR Lamp 2' On
 
Else
   - No Actions - (To add one, press 'Action')
 

to start $stemp_test was 0, I turned on Lamp 2 manually, lamp 1 was off.

then I changed the value of $stemp_test to 1 and as expected lamp 1 came on lamp 2 went off

then I manually turned on lamp 2 again

then I changed $stemp_test value to 2 and lamp2 turned off again, lamp 1 stayed on.

Ahh! That's good to know and easy to follow your example, thanks for that Mr. Bill.

I'm assuming then, had you set $stemp_test = 0 while it was Waiting it would have jumped to the Else clause and done nothing further.

Posted
1 minute ago, vbphil said:

I'm assuming then, had you set $stemp_test = 0 while it was Waiting it would have jumped to the Else clause and done nothing further.

Correct.

Posted (edited)
6 hours ago, Michel Kohanim said:

Why is it incorrect? The condition does not get retested before the next Wait or Repeat.

With kind regards,
Michel

As I understand it, ISY does not test or retest anything without a trigger or call from another program. The wiki statements are clear that the conditions are retested every occurrence of Wait or Repeat.  I don't believe this to be true, or ISY would be bogged down looping by restarting every program with a Wait line being executed.

Eg:

If
       condition1
Then
      then code
      Wait 1 second    <----------- this line is stated to have condition1 retested and Then or Else would restart each time.
      then code additional  <------- this line could/would never get run
Else
       else code

 

This wiki article has been causing a lot of confusion among newbies here. This thread is only one example of many. The error is implying  "does" vs. "gets permission" or "may".

Edited by larryllix
  • Like 1
Posted (edited)
On 6/24/2021 at 11:43 AM, vbphil said:

Ahh! That's good to know and easy to follow your example, thanks for that Mr. Bill.

I'm assuming then, had you set $stemp_test = 0 while it was Waiting it would have jumped to the Else clause and done nothing further.

Not exactly correct! If  had you set $stemp_test = 0 while or before it was Waiting it would have jumped to the Else clause during the Wait time and done nothing further.

The With/Repeat construct allows the ISY logic engine and system to have it's 'processing turn' (gives up the program's time slice for the Wait time)

Edited by larryllix
Posted
39 minutes ago, larryllix said:

Not exactly correct! If  had you set $stemp_test = 0 while or before it was Waiting it would have jumped to the Else clause during the Wait time and done nothing further.

The With/Repeat construct allows the ISY logic engine and system to have it's 'processing turn' (gives up the program's time slice for the Wait time)

True. It would be a race to retrigger before the Wait so it would probably hit during the Wait. 
 

 

Posted
1 hour ago, vbphil said:

True. It would be a race to retrigger before the Wait so it would probably hit during the Wait. 
 

 

Yeah. The event would get cached in a low level (O/S)  i/o buffer, until the ISY processing engine (high level processing) can process  the cached trigger.  This will only happen during a Wait or Repeat in any program (giving up it's time slice) or it is sitting idle, not processing any user programs.

Posted
On 6/24/2021 at 11:46 AM, larryllix said:

As I understand it, ISY does not test or retest anything without a trigger or call from another program. The wiki statements are clear that the conditions are retested every occurrence of Wait or Repeat.  I don't believe this to be true, or ISY would be bogged down looping by restarting every program with a Wait line being executed.

State variables are tested with each loop cycle I believe - they don't need to be called or triggered. A trigger event occurs when the State variable changes from it's prior value. Programs that have a State variable in their 'If' that just changed will then have a trigger queued for them. 

If a running program is 'waiting' - and such a trigger is received, it restarts execution by evaluating the test.

At least - this is how I remember it..

  • Like 2
Posted
1 hour ago, MWareman said:

State variables are tested with each loop cycle I believe - they don't need to be called or triggered. A trigger event occurs when the State variable changes from it's prior value. Programs that have a State variable in their 'If' that just changed will then have a trigger queued for them. 

If a running program is 'waiting' - and such a trigger is received, it restarts execution by evaluating the test.

At least - this is how I remember it..

hmmmm. I have worked with event based systems that worked like that.  IIRC I was informed that ISY does no scanning. It would be easy to maintain a trigger stack and use much less CPU overhead...maybe :)

Forum posts have circulated that a program will stop and conditions re-evaulated at every Wait and/or Repeat,  based on the wiki being misstated the way the logic flow works, IMHO. This is causing confusion. Programs containing Waits do not restart  endlessly.

Guest
This topic is now closed to further replies.

  • Recently Browsing

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

  • Forum Statistics

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