LarryCRetired Posted November 3, 2020 Posted November 3, 2020 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.
jfai Posted November 3, 2020 Posted November 3, 2020 (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 November 4, 2020 by jfai
Goose66 Posted November 3, 2020 Posted November 3, 2020 (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 November 3, 2020 by Goose66 1
jfai Posted November 3, 2020 Posted November 3, 2020 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?
Goose66 Posted November 3, 2020 Posted November 3, 2020 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 =.
jfai Posted November 3, 2020 Posted November 3, 2020 (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: 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. 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 November 3, 2020 by jfai
LarryCRetired Posted November 3, 2020 Author Posted November 3, 2020 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.
MrBill Posted November 3, 2020 Posted November 3, 2020 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.
jfai Posted November 3, 2020 Posted November 3, 2020 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. ?
LarryCRetired Posted November 5, 2020 Author Posted November 5, 2020 Gentlemen I am totally confused. I changed my program to be as follows: 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.
JBanaszak Posted November 5, 2020 Posted November 5, 2020 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 2
Goose66 Posted November 5, 2020 Posted November 5, 2020 +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. 1
LarryCRetired Posted November 5, 2020 Author Posted November 5, 2020 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.
MWareman Posted November 7, 2020 Posted November 7, 2020 Gentlemen I am totally confused. I changed my program to be as follows: 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. 1
Recommended Posts