Jump to content

Combining Time Conditions in an If Statement


LarryCRetired

Recommended Posts

Posted

I have a program that combines two different time conditions in my If Statement.  However, the program indicates it runs but the then statement is not executed.  Just wondering if what I am trying to do is allowed as a programing statement in the ISY.  I can do a work around so this is not critical but I want to satisfy my curiosity.

Here is my program.  Since my garage is not yet at a freezing temperature, I am using another temperature to test the program.  My Tag values are updated every 15 minutes.

The  variable $i_Ctl_Garage_Freeze_Switch <= 6, has a value of 0.  Any thoughts would be appreciated.

1467283825_IfStatementConditions.JPG.b5aa42e8467e5ebd1341bf8519499337.JPG

 

 

Posted (edited)

Unless the temperature changes at exactly 1 hour after the last time the program ran, the condition won't be true. In other words, this program's condition is almost never true, except at 6 am each day. The temperature update occurs at most every 15 minutes. Therefore, the program condition is evaluated at most 48 + 2 times a day. The temperature may not change every 15 minutes, so the actual number of condition evaluation is most likely less than 50.

Edited by jfai
Posted (edited)

The conditions in a program's If statement are just that: conditions. They will be evaluated every time the program is triggered to determine whether the Then branch or Else branch of the program will be executed. The events that trigger a program are "divined" by the ISY from the If conditions. So in the case of the OP's program above, it will be triggered:

1) at 6:00 am;
2) at 6:00 pm;
3) the Last Run Time for the "Freeze Warning Day - Tag" program is updated;
4) the "Temperature" driver value for the the "Tags / Garden" device changes; and
5) the i_Ctl_Garage_Freeze_Switch variable changes.

I don't imagine the OP wants the program to run all of these times. If I understand what the OP wants here (it wasn't specified), the solution is two programs: a first program that is enabled and that has the "Tags / Garden Temperature" condition along with a  6:00 AM condition that runs a second program in the Then branch, and the second program that is disabled and has all of the other conditions (time range, last run time, variable count) and performs the actual statements in the Then branch.

Edited by Goose66
  • Like 1
Posted
4 minutes ago, Goose66 said:

I hate to disagree, but... I disagree. ?

The conditions in a program's If statement are just that: conditions. They will be evaluated every time the program is triggered to determine whether the Then branch or Else branch of the program will be executed. The events that trigger a program are "divined" by the ISY from the If conditions. So in the case of the OP's program above, it will be triggered:

1) at 6:00 am;
2) at 6:00 pm;
3) the Last Run Time for the "Freeze Warning Day - Tag" program is updated;
4) the "Temperature" driver value for the the "Tags / Garden" device changes;

What are you disagreeing with? Do you have another explanation why the email isn't sent?

Posted

I didn't get 

1 minute ago, jfai said:

What are you disagreeing with? Do you have another explanation why the email isn't sent?

I accidently posted before finishing my reply. But in further consideration, yes the last run time should be > and not =.

Posted (edited)

Checking the last run time for ">" instead of "=" isn't much better. You'll get an email at 6 am every day. And then maybe once or twice throughout the day, but at seemingly random times. I doubt that's the intent of the program.

Assumptions:

  1. The program was run the first time "manually" once after 6 am (otherwise it won't run until 6 pm the same day, and then it won't send the email). Let's say the program ran at 10 am. No email will be sent because the "time > last run + 1 hour" is false.
  2. The temperature updates happen at 15-minute intervals starting on the hour and the temperature changes each time (unlikely, but it's the worst case scenario).
  • At 10:15, "time > last run + 1 hour" (= 11:00) is false. No email.
  • At 10:30, "time > last run + 1 hour" (= 11:15) is false. No email.
  • etc: the "time > last run + 1 hour" condition will only be true if the temperature doesn't change for at least 60 minutes, which may or may not happen.
  • At 18:00, the time-of-day condition is false. No email. 

 

Edited by jfai
Posted

Thanks everyone for providing your comments.  I need to digest them but I think I get it.  I was trying to do something fancy but I think I need to just add some time statements in my If Statement which at the same time I check the garage temperature.  All this to make sure my wife's coke does not freeze in the winter?.

I may still mess with this a little more to get a better understanding of these statements.  I just bought a bunch of Tags and added them to my system.  I did buy them so Jimbo gets some credit toward his purchases.  

I do appreciate your help. 

Posted
3 hours ago, Goose66 said:

So in the case of the OP's program above, it will be triggered:
5) the i_Ctl_Garage_Freeze_Switch variable changes.

Question, is that true when including an INTEGER variable?  Would it not need to be a STATE variable changing to cause the program to trigger?  

Using in integer variable in combination with AND (as OP has done) can have logical usage, however using integer variables alone of in conjunction with OR don't seem to have value in an IF statement.

I'm guessing on OP's variable naming convention that it's an integer variable, but that is not stated and I'm in fact guessing.

Posted
39 minutes ago, MrBill said:

Question, is that true when including an INTEGER variable?  Would it not need to be a STATE variable changing to cause the program to trigger?

Correct.

40 minutes ago, MrBill said:

Using in integer variable in combination with AND (as OP has done) can have logical usage, however using integer variables alone of in conjunction with OR don't seem to have value in an IF statement.

Correct: an integer variable as the sole condition will not trigger evaluation of the condition.  However, another program could use Run(If), and there may be a reason to split the programs.

An integer variable OR'ed with other conditions is not uncommon, e.g., checking some kind of configurable threshold.

Therefore: it depends on what you're trying to do. There are many ways to slay a dragon. ?

Posted

Gentlemen

I am totally confused.  I changed my program to be as follows:

1104979696_IfStatementConditions-2.JPG.acbda232c8f9b3aeac88a763b5ab29a7.JPG

My garage temperature did not fall below 55 degrees during the night but the "Then Logic" ran every hour from 6 PM to 5 AM.  Two things seem to defy logic.

The "Then" should not have run since the Tag temperature was above 32 degrees and the switch counter (an integer) should have limited the number of times the "Then Logic" should have run to 7 times since the switch counter starts out at 0 even though the check was not working on the Tag Temperature.

Any thoughts would be appreciated.

 

 

 

Posted

You need some ( ) around all your “Or” statements. That “block” will become true every hour then evaluate the two “And” statements as you intend.


Sent from my iPhone using Tapatalk

  • Like 2
Posted

+1 to what @JBanaszak said. Remember "Not, And, Or." It's going to look at NOTs first, then ANDs, and then ORs, when there are no parenthesis to control the order of evaluation. So in this case, the AND statements are evaluated with the "Time is 5:00 AM", and then ORed with the rest of the "Time is X:00" statements.

  • Like 1
Posted

Thanks guys.  I guess I never understood the order of evaluation. Thanks for pointing that out. 

I guess you can always teach an old dog new tricks.  Sometimes it just takes awhile.

Appreciate your quick responses.

 

Posted
Gentlemen
I am totally confused.  I changed my program to be as follows:
1104979696_IfStatementConditions-2.JPG.acbda232c8f9b3aeac88a763b5ab29a7.JPG
My garage temperature did not fall below 55 degrees during the night but the "Then Logic" ran every hour from 6 PM to 5 AM.  Two things seem to defy logic.
The "Then" should not have run since the Tag temperature was above 32 degrees and the switch counter (an integer) should have limited the number of times the "Then Logic" should have run to 7 times since the switch counter starts out at 0 even though the check was not working on the Tag Temperature.
Any thoughts would be appreciated.
 
 
 

BODMAS applies here....

OR is matched before AND.

You need to group the OR conditions in parenthesis.
  • Like 1
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...