Jump to content

If, Then, Else Path question


prak7121

Recommended Posts

Posted

I feel silly asking this question after so many years of programming but I did a search and could not find a good answer for the following question:

When I program, how does the If Path, Then Path, Else Path work?  That is, how do I choose one of the 3 options and where do I put them.  For example does Then Path only get put in the Then section or can it be both in the Then or the Else? 

Here is a sample program that I believe I fixed this morning.  I had the (Then Path) as (If Path).

 

If
        On Sun
        From    10:00:00PM
        To      11:55:00PM (same day)
 
Then
        Set 'Plant Heat- Main' 44° (Heat Setpoint)
 
Else
        Run Program 'VeriForm Plant afterhours' (Then Path)
 
In the above example I want the Else commands to only run if the statements in If area are not true.

Posted (edited)

I believe you have it correct it just depends on what that second program does.  THEN only ever triggers when IF is true, if it isn't, that's when ELSE triggers.  In your example, on Sunday from 10pm to 11:55pm, so 1 hour 55 minutes, it will set whatever Plant Heat is, to 44 degrees.  On other times, it will then run that VeriForm Plant program, being the ELSE path but it does depend on what this one does.  Say for example you instead had it say "Set Plant Heat - Main 30 degrees" (not sure if that's C or F sorry), then it would be 44 from 10 to 11:55, and 30 all other times.  That's a better way I think to accomplish something like that.  Are you able to post what that second program is, as that will help us determine the best way to write this program, as if it's something simple like a setting, or light being on etc, you could just put that right in the ELSE path, you don't need a separate program for it. 

 

One thing I forgot to mention is that with IF and THEN, there's 2 things that happen with IF.

 

1) It can trigger something one time.  So IF time is 5pm and LIGHT1 is OFF, THEN wait 10 minutes, turn LIGHT1 ON"  Useless program, but at 5pm if the light is off, the program waits 5 minutes (because IF is true) and then LIGHT1 comes on and program ends.

 

2) It can trigger based on status.  So for example, say you wanted a program that says IF the garage door is open for 60 minutes and not closed, automatically close the door.  So "If status GARAGE DOOR is OPEN, THEN wait 60 minutes, SET CONTROL GARAGE DOOR to ON".  In this example it's pretty cool because our criteria are the door is open.  So as long as that door is open, the IF is true, meaning the "Wait 60 minutes" will run, and stay true, then close the door.  If however you close the door after 20 minutes, well the IF program is now no longer true, so that THEN statement that's waiting for 60 minutes, now ends and doesn't finish the program because IF is not true, and it doesn't need to keep running.  So it's great for things like that.

Edited by 416to305
Posted (edited)

Only "Schedule" and "Condition" items will be placed in the If clause. When you click one of those two buttons the If clause is highlighted above. Notice the button below only has the "Add to If" option. It's not possible to add them to the Then or Else clauses.

 

Only "Actions" items can be put in Then and/or Else clause. Any Action can be put in the Then or Else clause or even both. All Actions have an "Add to Then" or "Add to Else" button. They can't be placed in the If clause.

 

So basically you can't do it wrong, although you can construct your logic in such a way it doesn't work the way you want.

 

When the If clause evaluates as "True" the Then clause is executed. ANYTIME the If clause evaluates as "False" the Else clause is executed even if the Then is currently running. That is true in reverse as well.

 

The If clause is evaluated immediately whenever there is a state change to any item in it. For example, when testing for the Status of a device in the If clause it will be evaluated anytime the device state changes from On, Off, Dim, etc. The new answer will cause immediate execution of either Then or Else clause depending on the answer. This is true even if one of the clauses is already being executed. Execution will stop, the If will be evaluated, and the new answer will drive the execution of Then or Else depending on the new answer even if the answer is the same as it was before. Execution begins anew for Then or Else.

 

In your example, the If clause will be evaluated twice on Sunday at 10pm and at 1155pm. When it evaluates "True" on Sun at 10pm the Heat Point will be set to 44F. When the time schedule is over at 155pm it will evaluate False to run the Else clause and the program 'Veriform' will run but the set point will still be set at 44F unless some other program changes it.

Edited by shannong
Posted (edited)

ISY programs are event driven.  The if section of a program does two things: Define Triggers and evaluate True/False.  Both are critical.

 

A time based program (From to...) triggers twice.  Once at the beginning of the time range and once at the end.  When triggered, the if clause is evaluated for true/false.  True runs then, False runs else.  Once triggered at the From time, the if is not re-evaluated again until the To time is reached (unless there are other triggers in the if section other than the time range)

 

It is important to understand what triggers an if and what doesn't.  Time From/To, Device Status changes, Device Control events, State variable value changes, Elk, Energy and Weather module variable value changes will can trigger an If.  Integer variable changes DO NOT trigger an if but ARE evaluated when used in an if that gets triggered by other means.  With regard to variable value changes, the value has to change to trigger, not just update to the same value. Same with the status of a device.

 

The If section of a program will always be evaluated when called by another program or when manually called.  When the if is evaluated, the evaluation follows what one would expect from other languages in terms of And, Or and the use of (Parens to group items).

 

Given the above, in your example, if the ISY were started up at Noon on Monday, nothing would happen until Sunday @ 10PM when the program would trigger and run the Then.  It would then trigger again at Sunday @ 11:55Pm and run the Else.

 

As Shannong points out above, the function of the Then is not undone when the else runs at 11:30.  You would need to deal with that in the else section if necessary.

 

Hope this helps

 

-Xathros

Edited by Xathros
Guest
This topic is now closed to further replies.

×
×
  • Create New...