gregkinney Posted August 3 Share Posted August 3 I found out from another forum post recently that I have been using the 'wait' function incorrectly. I had assumed that 'wait' was the same logic as other programming languages where it temporarily stalls the running program for a period of time. But @TJF1960 pointed out that if there is a 'wait' in the 'then', the program will re-evalate if the 'if' changes. My goal in some of my programs is to have a 'wait' in the 'then' which will simply stall the program for a period of time, and not keep evaluating whether the 'if' is true during this 'wait' time. Can someone help me accomplish this? My only thought was if it was split up into two programs, where the second program did not have any 'if' logic to evaluate. Wondering if there is a cleaner way. I have noticed that if the 'if' is a time, it will still use the 'wait': living kodi clean nightly - [ID 0272][Parent 0073] If Time is 3:33:33AM Then Resource 'living.kodi.on' Wait 6 seconds Resource 'living.kodi.clean' Else - No Actions - (To add one, press 'Action') #enabled And also, for some reason this works: office bath fan 7.5 - [ID 0159][Parent 01C2] If 'Rooms / Office / Office Bath Fan' is switched Fast Off Then Wait 2 seconds Set 'Rooms / Office / Office Bath Fan' On Wait 7 minutes and 30 seconds Set 'Rooms / Office / Office Bath Fan' Off Else - No Actions - (To add one, press 'Action') Which leaves me thoroughly confused. Quote Link to comment
paulbates Posted August 3 Share Posted August 3 The typical way to fix this is to put the 'Then' statements in a second program with no 'If'. Have the first program (with the if) only have program 'run then' statement that calls the second program. That will solve the problem with the living kodi clean program.. The second program, with no 'if', will run uninterrupted to conclusion The office bath the program works because you physically double-tap the switch for fast off to trigger the program. The only thing that could change that during the wait is another fast-off.... which would restart the program. Quote Link to comment
oberkc Posted August 4 Share Posted August 4 5 hours ago, gregkinney said: My goal in some of my programs is to have a 'wait' in the 'then' which will simply stall the program for a period of time, and not keep evaluating whether the 'if' is true during this 'wait' time. To be clear, wait statements do not force an evaluation. Programs will not automatically "keep evaluating" during wait statements. Wait statements are not program triggers. There would still need to be an external trigger to occur to force an evaluation during a wait statement. Quote Link to comment
Goose66 Posted August 4 Share Posted August 4 To be clearer (😁), the wait in the program is not causing the if statement of the program to be reevaluated. What is happening is events are causing the same program to execute again, and if the presently executing program is in a WAIT, then execution of it will stop in favor of the newly triggered instance of the program. In other words, basically you can’t have two copies of the same program running at the same time. Normally this is actually quite handy feature, and you can structure your programs to take advantage of it. This generally involves the use of the frequently discussed two-program structure - one enabled with trigger conditions and one disabled with simple if statements regarding state. This is discussed ad nauseum in this forum and I won’t go into detail here. Suffice to say in both of your examples above the programs could be structured to take advantage of this feature and create intuitive responses. Quote Link to comment
gregkinney Posted August 4 Author Share Posted August 4 Thank you everyone for your input. Yes @Goose66 I am familiar with the two-program structure and will use that moving forward to achieve what I want. I guess if I see it the way you see it, as a benefit, it can be used to my advantage. I think my black-and-white logic brain was having a hard time with that. Quote Link to comment
Goose66 Posted August 4 Share Posted August 4 We were all there in the beginning of our programming efforts. I fought it for years, but was finally assimilated… 1 1 Quote Link to comment
Guy Lavoie Posted August 24 Share Posted August 24 It looks like what Goose66 is saying is that the program will retrigger (as we'd say about an electronic circuit), so any resulting sequences and timings are started over from the beginning. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.