Jump to content

Is there a smarter way to write this timing function ?


satwar

Recommended Posts

From the Wiki:

 

"What this means [wrt/Wait or Repeat] 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)."

 

Program conditions are usually evaluated as soon as a change occurs unless there's a Wait or Repeat at the end of which the program conditions are evaluated. But, that's only for statements following the Wait or Repeat clause. In you original example, there are no statements following the Wait, so the program will terminate at the end of the Wait duration and will not be evaluated again (until the next trigger).

 

"which causes the program's overall condition to become false... true" <-- This particular sentence (from Scope, Precedence and Execution Order) completes what I found other explanations excluded.  The status has to change for the program containing either wait or repeat to be affected.

 

"the program's conditions are reevaluated each time a Wait or Repeat statement is encountered," <--This sentence from the same is confusing because I believe it is not the condition that's evaluated but the "status" (unless by conditions they're referring to the condition of it's status :)

 

Anyway.. nit-picky crap but I had the wrong idea of what was going on. 

 

 

Jon...

Link to comment

Yup.

 

The statements posted by Stu from the wiki article are out of their context and only  an example used in the context of the section.

 

The point I made was the example was only specific to the program under discussion but in reality any program, device, rest input, or variable change, wherever the change originates from,  can change the progression of the program in question from False to True or vice versa.

 

The example, being out of context, implies only the  program can change it's own course of execution from false to True or vice versa.. This is not correct and is causing confusion for users.

Link to comment

Here's the entire statement:

 

Statement Execution Order

Within the Then or Else clause of a program, statements are executed from top to bottom in the order in which they occur. When a statement calls another program, the called program begins executing, and the calling program immediately continues execution with the next statement in sequence--it does not wait for the called program to complete before continuing.

 

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. 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).

 

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated.

 

Thus, a Wait or Repeat will execute as expected unless a statement prior to the Wait or Repeat caused to value of the condition(s) to change.

Link to comment

Thus, a Wait or Repeat will execute as expected unless a statement prior to the Wait or Repeat caused to value of the condition(s) to change.

 

Umm, not to be difficult but that wording doesn't seem to be correct.

 

It appears it's the status of the program (true/false) that triggers the termination of the program. But I agree with everything up to that following Repeat :)

 

The conditions can be changed and not affect the status of the program.

 

 

Jon...

Link to comment

It is the occurrence of a condition that triggers a Program, not a change in Program True/False status.  In this Program the Wait is terminated if the Motion Sensor - Sensor senses motion within the 5 minute Wait and the Then clause restarted even though Program Status is always True.

 

AAAA4 - [iD 006C][Parent 0001]
 
If
        Control 'MS I2CS-Sensor' is switched On
 
Then
        Wait  5 minutes 
        Set 'SwitchLinc Dimmer 1' Off
 
Else
   - No Actions - (To add one, press 'Action')
Link to comment

 

It is the occurrence of a condition that triggers a Program, not a change in Program True/False status.  In this Program the Wait is terminated if the Motion Sensor - Sensor senses motion within the 5 minute Wait and the Then clause restarted even though Program Status is always True.

 

AAAA4 - [iD 006C][Parent 0001]
 
If
        Control 'MS I2CS-Sensor' is switched On
 
Then
        Wait  5 minutes 
        Set 'SwitchLinc Dimmer 1' Off
 
Else
   - No Actions - (To add one, press 'Action')

 

 

What I'm trying to clear up in my thick skull is how Wait and Repeat interact with the conditions of the program, and right now I don't think they do.  Should Wait or Repeat be active and the program status change to false (in the case of Else usage) I don't believe the conditions are reevaluated but rather the program terminated as though it had completed the Else structure because Wait and Repeat are acting more like placeholders that allow termination at that point if there is a status change.

 

So.. I would amend Stu's statement to..

 

"Thus, a Wait or Repeat will execute as expected unless a statement prior to the Wait or Repeat causes a change in the Status of the program."

 

Edit: or the program is restarted :)

 

 

Jon...

Link to comment

I would not describe WAIT or REPEAT statements as "interacting" with a program condition. Instead, I would describe such statements as an off ramp. If, for example, something triggers a program condition while that program is executing a wait or repeat, the program execution will halt and restart, based on the results (true or false) of the latest triggered evaluation.

Link to comment

jerlands

 

"What I'm trying to clear up in my thick skull is how Wait and Repeat interact with the conditions of the program, and right now I don't think they do.  Should Wait or Repeat be active and the program status change to false (in the case of Else usage) I don't believe the conditions are reevaluated but rather the program terminated as though it had completed the Else structure because Wait and Repeat are acting more like placeholders that allow termination at that point if there is a status change."

 

Not correct.   When a Program is in a Wait or Repeat and the trigger conditions change/occur, the Wait/Repeat is terminated and the If clause evaluated.  When the If evaluates to True the Then clause executes (as in my post #30 Program).  When the If evaluates to False the Else clause executes.  What happens when the If reevaluation invokes the Then or Else clause depends on the statements in the respective Then/Else clause.  

Link to comment

Not correct.   When a Program is in a Wait or Repeat and the trigger conditions change/occur, the Wait/Repeat is terminated and the If clause evaluated.  When the If evaluates to True the Then clause executes.  When the If evaluates to False the Else clause executes.  What happens when the If reevaluation invokes the Then or Else clause depends on the statements in the respective Then/Else clause.  

 

Is the following true for any program including those not using Wait or Repeat --> When a Program's trigger conditions change/occur, the If clause is evaluated or... is the if clause only reevaluated if in Wait or Repeat?

 

 

Jon...

Link to comment

jerlands

 

When a Program's trigger conditions change/occur, the If is evaluated.   When the If evaluates is dependent on whether there is an active Wait/Repeat.  When the Program is in a Wait or Repeat the If is evaluated immediately.  When the Program is executing an Then/Else clause without Wait/Repeat the If is evaluated when the current executing clause completes.

Link to comment

jerlands

 

When a Program's trigger conditions change/occur, the If is evaluated.   When the If evaluates is dependent on whether there is an active Wait/Repeat.  When the Program is in a Wait or Repeat the If is evaluated immediately.  When the Program is executing an Then/Else clause without Wait/Repeat the If is evaluated when the current executing clause completes.

 

Thanks you.. that helps to clear things up.  knowing what conditions terminate the program when using Wait and Repeat will help prevent program errors.  I believe the key factor in the definition is "trigger conditions" or those that change the status of the program.

 

 

Edit: also.. I now think I understand when the conditions are evaluated, at trigger, at completion of clause and at occurrence of Wait and/or Repeat..

 

 

Jon...

Link to comment

Thanks you.. that helps to clear things up.  knowing what conditions terminate the program when using Wait and Repeat will help prevent program errors.  I believe the key factor in the definition is "trigger conditions" or those that change the status of the program.

 

 

Edit: also.. I now think I understand when the conditions are evaluated, at trigger, at completion of clause and at occurrence of Wait and/or Repeat..

 

 

Jon...

Look at this as more than the avoidance of programming errors. This is also a capability to exploit!

Link to comment

Just to be clear, there are no "terminate" conditions or Then/Else clause actions.

 

"knowing what conditions terminate the program" <-- by this I meant.. e.g., "If Time is 0600AM"  this condition will not reevaluate as unmet (no matter what time of day as long as the Wait or Repeat are active) because it doesn't change the status of the program.  or.. using an integer variable because a change in the variables state does not affect the status of the program.

 

 

Jon...

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...