Jump to content

Toggle Program


khargy

Recommended Posts

Ok, so I thought I understood the if-then-else logic, but I guess not :)

 

I'm trying to write a program that will toggle the light on or off:

 

if
Status 'office' is not off
then
Set 'office' off
else
Set 'office' on

 

when I do a run(if) on that program it just goes into an infinite loop!

 

What am I missing?

 

Thanks,

Ken

Link to comment

Well I'm not TRYING to make it flash :) I was just trying to make it turn the light off if it's it on and on if it's off... ultimately I want to use this logic for IR control -- the idea being that when a specfic IR button is pushed it'll call the toggle program. Currently I have to have two programs for each IR button -- one if the light is on and one if the light is off. I figure there must be a better way.

Link to comment

No, using two programs is the correct approach. If you try to use the ELSE portion of a program to handle the opposite status condition that you are using in the IF portion, it will cause the program to loop when the change in status causes the program to be re-evaluated--as you've already discovered. :D

 

Consider the following example:

 

If Control IR 255

and Status Light is Off

 

Then Turn ON Light

Else Turn OFF Light

 

The program is re-evaluated when:

 

a) The IR code is received by the ISY

B) The Status of the light changed from ON to OFF, or

c) The Status of the light changed from OFF to ON.

 

Only if a and b are true will the THEN branch of your program run, as you intend. The problem is that if only a, or only b, or only c, or a and c, then the ELSE branch would execute. So when you changed the light status from within the program, the conditions changed and it ran the Else.

 

The solution here is to use two programs and avoid using ELSE.

Link to comment
Well I'm not TRYING to make it flash :) I was just trying to make it turn the light off if it's it on and on if it's off... ultimately I want to use this logic for IR control -- the idea being that when a specfic IR button is pushed it'll call the toggle program. Currently I have to have two programs for each IR button -- one if the light is on and one if the light is off. I figure there must be a better way.

Hello Ken,

 

What both Lee and Tom have posted is correct. So, one way or another, you will end up with two programs. However, from what you wrote above, it sounds as though you are using three programs, where two will do.

 

Your original program as posted at the beginning of this thread should work fine. The trick is that you must uncheck the Enabled checkbox so that the program does not automatically re-evaluate. You can then use your IR button recognition program to call this toggle program.

Link to comment

Archived

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


×
×
  • Create New...