Jump to content

Lights not turning off at end of program...


swbrains

Recommended Posts

Hi,

 

I wrote the following program to turn a light on and off randomly through the night, between 1am and 5am. The program is named 'Random Foyer Light':

If 
   From  1:00 AM 
   To    5:00 AM (same day)
Then
    Set 'Foyer Light' On
    Wait 15 minutes (random)
    Set 'Foyer Light' Off
    Wait 4 minutes (random)
    Run Program 'Random Foyer Light' (If)
Else 
    -- No Action --

The program ran fine and turned the light on and off for random periods of time, but after 8:00 AM, the light was still on. I would have thought that the last action that would occur during the last run would be to turn the light off, wait a few minutes, then try to execute the program again but if it was after 5 AM it would simply stop, leaving the light off. I had also assumed that if the program was in the first (on) "wait" period when it passed 5 AM, that the current execution would at least run to completion which would include turning the light off again after several minutes.

 

What am I missing or misunderstanding about how the program executes?

Link to comment

The To time occurred during the Wait between the On and Off Actions. This causes the Program to be triggered again at 5:00AM. The If is False at that point running the Else clause so the Off is not executed.

 

Add an Off in the Else clause to insure the light is turned Off at 5:00 AM.

 

EDIT: A Wait of some minutes can be coded in the Else before the Set 'xxxx' Off to insure the light does not turn On in the Then and immediately turn Off in the Else, if that is a concern. Would very much depend on the timing since the Wait times in the Then clause are random.

Link to comment

Thanks -- I'll try that.

 

So the TO time is used to trigger an instance of the program?

 

If I add an OFF command to the ELSE, will that ONLY occur at exactly 5 AM, or will it occur at all times not between 1 AM and 5 AM? That is, if I add an OFF to the ELSE, it won't cause the light be turned off every time I turn it on manually after 5AM, will it?

 

Thanks!

Link to comment

The Program is triggered by the IF statement twice. At the From time the Then clause is run, at the To time the Else clause is run. Not limited to the From/To definition, anytime a condition in the IF changes that causes a trigger or reevaluation it is done immediately if in a Wait or Repeat statement.

 

Reevaluation will not interrupt other Action statements while they are executing. For example, if the To time arrived and the Then clause is running a series of Action statements the sequence will continue until a Wait or Repeat is encountered.

 

Turning the light On/Off manually during or after From/To time does not cause any Program action with the If statement being used. Some device Status check would, should that be part of the IF and the device status changes.

 

The UDI Wiki has a good description of this.

Link to comment

Archived

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


  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      36.9k
    • Total Posts
      370.3k
×
×
  • Create New...