drinkwater Posted March 26, 2012 Share Posted March 26, 2012 If $GarageDoorSensor is 1 And From Sunset + 15 minutes To Sunrise (next day) Then Set 'Garage Exterior Light' On Wait 1 minute Set 'Garage Exterior Light' Off Else - No Actions - (To add one, press 'Action') The 'Garage Exterior Light' turns on properly when $GarageDoorSensor variable is set to 1 but does not turn off after 1 minute. Any idea why ? Link to comment
LeeG Posted March 26, 2012 Share Posted March 26, 2012 The State variable is changing value before the Wait 1 minute completes. This causes the If to be reevaluated as False driving the Else clause so statements after the Wait are not executed. Link to comment
drinkwater Posted March 26, 2012 Author Share Posted March 26, 2012 Yes - the state variable does change back to 0 before the 1 minute is up. I would have thought that the Wait 1 Minute would prevent the program from reevaluating the IF. How would I go about getting the desired behaviour ? Link to comment
LeeG Posted March 26, 2012 Share Posted March 26, 2012 Any time a clause has a Wait or Repeat statement the If can be reevaluated. The UDI Wiki has an excellent explanation of how Repeat and Wait statements can affect execution of statements after the wait or Repeat. One solution is to change the State variable in the Then clause If $GarageDoorSensor is 1 And From Sunset + 15 minutes To Sunrise (next day) Then Set 'Garage Exterior Light' On Wait 1 minute Set 'Garage Exterior Light' Off $GarageDoorSensor is 0 Else - No Actions - (To add one, press 'Action') Another solution is to move the Then logic to a second Program that has no If section. The current Program calls the second Program to perform the logic. The first Program cannot be reevaluated because there is no Wait. Even if it is reevaluated to False it does not affect the second Program. Link to comment
drinkwater Posted March 26, 2012 Author Share Posted March 26, 2012 Thanks so much - I will give that a try. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.