Jump to content

trouble with a program


aweber1nj

Recommended Posts

(Sorry the title couldn't be more descriptive...)

 

I can export the program if it helps, but here's the "main program":

 

If

        From    Sunset  + 10 minutes
        To      10:05:00PM (same day)
    And Status  'L R Lights 1' is Off
    And Status  'L R Lights 2' is Off
    And Status  'L R Lights 3' is Off
    And Status  'L R Lights 4' is Off
 
Then
        Set 'L R Lights 3' On
 
Else
        Run Program 'LRLightsOff1' (If)

Here's "LRLightsOff1":

 

If

        Status  'L R Lights 1' is Off
    And Status  'L R Lights 2' is Off
    And Status  'L R Lights 4' is Off
 
Then
        Set 'L R Lights 3' Off
 
Else
   - No Actions - (To add one, press 'Action')

 

So basically, what I'm trying to do at sundown is check if any of the Living Room ("LR") lights have already been turned on.  If not, turn on #3.

 

At 10:05PM, if none of the other lights are on, turn #3 off.  (This is a very "simplistic" program - it should probably have a way to record if any lights have been toggled/adjusted at all in the room and disable the auto-off at 10:05.)

 

What happens is that at sundown, #3 goes on...then off...then on...then off...in a loop.

 

I guess this is an artifact of the if statement.  I was under the impression that it only gets evaluated at the designated time, where a time is in the IF statement.  I guess it's triggering again as the state of LR3 changes (though that doesn't explain why it would loop -- that would make it turn on once, and then turn off)?

 

Anyway, can someone tell me why my logic is incorrect, and "for bonus points" suggest a way to implement what I'm trying to do?

 

THANKS!

-AJ

Link to comment

Any time anything in the IF changes, it is re-evaluated.

 

At Sunset+10, if everything is off, Light3 turns on.   Since Light3 is now on, the IF is re-evaluated, and since Light3 is on, it runs the else.  Since the other lights are off, Light3 is turn off.   The reevaluates the IF again, this time it's true.

 

The way you have it now, adjusting any lights (1, 2, or 4) between sunset and 10 will also cause problems.

 

A couple options:

 

A) Remove the test of "Light3" from the IF.  Since you are going to turn it on anyway, it doesn't matter if it's already on, does it?

 

B) You could break it into 2 programs.   One for Sunset+10, and another for 10:05 PM.   Also, I would remove the "Light3" from the IF test (same reason as above).   If you want to test for Light3 still, add a small wait at the beginning just so that light doesn't turn on until after the same moment in time as sunset, otherwise you might get stuck in a loop for a second with the light flashing on and off.

Link to comment

Great info, and thank you for the quick reply!

 

I'm going to split it into two programs.  I'm also going to try creating a variable to track when one of the LR Lights is turned "on" (is not "Off"), and increment that each time a light is turned on...with some creative thinking, that should help me track whether someone manually toggled a light (on), or whether the program ran and turned it on automatically.

 

Thanks again,

AJ
 

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...