Jump to content

Toggle Program


khargy

Recommended Posts

Posted

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

Posted

When the Program changes the status of 'office', either On or Off, the Program If is reevaluated because of the Status change. It is now Off if it was On or On if it was Off. The Program runs over and over each time the Status is reversed.

Posted

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.

Posted

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.

Posted
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.

Posted

Because of the programming architecture of the ISY, you will find that using ELSE is rarely the right solution. This is something I have complained about for a long time (trigger conditions vs. IF conditions), but there doesn't appear to be any improvements coming anytime soon.

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37.1k
    • Total Posts
      371.5k
×
×
  • Create New...