Jump to content

Waits & program re-execution


marvel

Recommended Posts

Posted

Question:

 

If a program executes and begins a "wait", and the original conditions that executed the program become true again before the wait elapses, what happens? Does the ISY99i spawn a second copy of the program, terminate the original and start over, or does the original have to finish before we can re-execute? If the original program is not terminated and restarted, then how do we build timers that can be terminated or reset before completing?

 

Practical example:

 

I want to brighten the outside lights when motion is detected, then dim them back down after a minute without motion. I'm using a Dakota EZSnsRF motion sensor which briefly turns on every time motion is detected. Program should be simple enough, if (status of EZSnsRF motion sensor = on) then (brighten, wait 1 minute, dim).

 

What happens if, 40 seconds into the wait, the motion sensor is triggered again? Does the initial execution of the program continue and execute the dim function after the remaining 20 seconds have lapsed? If so, have we now spawned multiple copies of the same program, each with their own wait running? Or is that initial execution terminated and restarted, effectively resetting the 1 minute timer? I'm hoping for the latter, of course; if that is not the case, how do I handle this?

 

Thank you!

Posted

Any time a Program encounters a Wait or Repeat the If can be reevaluated. This can occur anytime during the Wait period. Only one copy of the Program executes. If the reevaluation causes the Program to be invoked again the current copy is terminated.

 

It is important to know what the If looks like. If Status and If State variable cause a reevaluation anytime the Status or State variable change values (when a Wait or Repeat is encountered). If no Wait or Repeat the IF condition can change with no affect on Program execution.

 

"What happens if, 40 seconds into the wait, the motion sensor is triggered again?"

 

The Program will not be in the Wait more than a few seconds. When the Motion Sensor sends the Off the Program If Status is reevaluated, the condition is now False so the Else runs which does not have any logic so the Program ends.

 

In this case an If Control On is more appropriate. The On causes the Program to trigger and the Then clause runs because it is an On command. The Off command has no affect on an If Control On. Should another On be received before the Wait completes the current Program is terminated and a new copy runs with a new Wait interval.

 

The UDI Wiki has a very good explanation of Wait/Repeat and how they can affect Program execution.

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.5k
×
×
  • Create New...