Light Schedule with Override Switches

A user wrote today with a small example to turn an output on with a schedule and off depending on the state of an input. The program they submitted has a goto and some tricky logic, I suggested some small changes to simplify it and posted here so others can learn:


I am trying to do this very simple program and I don’t know why it doesn’t work. The prog file is attached, here is the code:

10 IF SCH1 THEN START OUT7
20 IF TIME-ON ( OUT7 ) > 00:30:00 THEN GOTO 30
30 IF IN1 > 1 THEN START OUT7

The problem is that out7 starts when sch1 is off because in1>1 but it stops when in1<1…I want that out7 still on for 30 minutes after in1 becames from >1 to <1.

Can you help me?

1 Like

I can see a logic hole in your program there with the goto statement jumping to line 30 which it will do anyway after running line 20.

The general rule about gotos is ‘don’t use them’… .well only use them if you really need to.

I have added a VAR1 which keeps track of the IN1 condition.

Then you can use TIME-OFF on var1 instead. No gotos required and the program is easy to understand.

10 IF IN1 > 1 THEN START VAR1

20 IF IN1 < 0.95 THEN STOP VAR1

30 IF SCH THEN START OUT7

40 IF TIME_OFF VAR1 THEN STOP OUT7

1 Like

A post was split to a new topic: Light Switch Timer Program

The user wrote back and there’s more to the story:


Hi maurice, this dosen’t work. What I need is, if sch1 is on then turn on out5.

10 IF SCH THEN START OUT5

If sch 1 is off and in1> 1. (like someone presses a button) then start out5 for 10 minutes.

IF+ IN1 THEN START VAR1
IF TIME-ON( VAR1 ) > 0:01:00 THEN STOP VAR1
IF NOT SCH1 AND NOT VAR1 THEN STOP OUT1

If someone press again in that períod of 10 minuts, restart the timer.

1 Like

So its basically a momentary light switch with schedule and after hours override.
VAR1 : TIME LEFT FOR OVERRIDE TIMER
VAR2 : AFTER HOURS OVERRIDE INTERVAL

10 IF SCH OR VAR1 > 0:0:0 THEN START OUT5 ELSE STOP OUT5
20 IF+ IN1 THEN VAR1 = VAR2
30 IF INTERVAL( 0:0:01 ) AND VAR1 > 0:0:0 THEN VAR1 = VAR1 - 0:0:01

Notes: the IF+ statement resets the timer to the full override time interval. Use IF+ to do it on the rising edge, single event. You could do it with a regular IF but the IF+ will let the timer start decrementing immediately after a button press even if the button is still held down, subtle difference but why not.

The VAR1 timer shows how much time is left before the lights go off, add these to your graphical floorplans so you can see at a glance how long till the lights go off.

The VAR2 override interval can also be placed on the user graphical interface to let the building operator adjust the amount of time the lights will be on for each hit on the switch.

1 Like