Jump to content

Simple program problem


drinkwater

Recommended Posts

Posted

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 ?

Posted

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.

Posted

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 ?

Posted

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.

Guest
This topic is now closed to further replies.

×
×
  • Create New...