ISY-99i/ISY-26 INSTEON:Comparative Study using Run If

From Universal Devices, Inc. Wiki
Jump to: navigation, search

As a comparative study of a system with and without the use of the Run (If) command, consider a Movie Time KPL non-toggle-off button with the following function: the first time the button is pressed, the system goes to the Movie Prep stage, which turns on the kitchen lights (to make popcorn), and turns on the theatre lights. The next press of the button shifts the system to the Movie Start stage, which turns the kitchen lights off, and fades the theatre lights down. A press of the button while in this state, shifts the system to the Movie Stop state, which fades up the theatre lights, turns on the bathroom light (for refreshing pause), and turns on the kitchen light (to fetch more beverage). Additional presses of the button alternate between Movie Start and Movie Stop. The system does not turn the bathroom light back off, simply because it may still be in use; that step could be added at the discretion of the user.

Using the Run (If) command, the required functionality could be obtained by use of a group of programs such as the following:

Program 'Movie Time Macro' - Enabled
If
        Control 'Movie Time KPL non-toggle button' is switched Off
     Or Control 'Movie Time KPL non-toggle button' is switched Fast Off

Then
        Run Program 'Movie Time Prep' (If)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Flag' - Not Enabled
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
   - No Actions - (To add one, press 'Action')

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Prep' - Not Enabled
If
        Program 'Movie Time Flag' is False

Then
        Set 'Kitchen Movie Scene Fade' On
        Set 'Living Room Movie Scene Fade' On
        Run Program 'Movie Time Start/Stop' (Else Path)
        Stop Program 'Movie Time Start/Stop'
        Run Program 'Movie Time Flag' (Then Path)

Else
        Run Program 'Movie Time Start/Stop' (If)


Program 'Movie Time Start/Stop' - Not Enabled
If
        Program 'Movie Time Start/Stop' is False

Then
        Set 'Kitchen Movie Scene Fade' Off
        Set 'Living Room Movie Scene Fade' Off

Else
        Set 'Kitchen Movie Scene Fade' On
        Set 'Living Room Movie Scene Fade' On
        Set 'Main Bath' On

In this group of programs, only the Movie Time Macro program is enabled, so that Movie Time button presses will activate it. The other programs are not enabled, in order that they not run independently, but only when called from another program.

The Movie Time Flag program has no conditions or actions. It simply serves as a status flag. When the Then path is run, the program's status becomes True, and when the Else path is run, the program's status becomes False.

The Movie Time Macro program receives a button press, and calls the Movie Time Prep program's If clause. On the first button press, Movie Time Flag will be False, and so Movie Time Prep will run its Then path, which executes the preparation statements. It also calls the Else path of Movie Time Start/Stop in order to initialize that program's status to False, and immediately calls Stop to prevent the statements in the Else clause from executing. Finally, it calls the Then path of Movie Time Flag, setting it to True. Successive button presses will therefore cause Movie Time Prep to run its Else path, which calls Movie Time Start/Stop.

On the first call to Movie Time Start/Stop, its status is False which means that its condition is True. It therefore runs its Then path, executing the movie start statements, and setting its status to True. Therefore on the next call its condition will be False, and it will run its Else path, executing the movie stop statements, and setting its status back to False. Successive calls will cycle between Movie Start and Movie Stop.


Without the use of the Run (If) command, the required functionality can still be obtained, though with significantly greater complexity, by use of a group of programs such as the following:

Program 'Movie Time Flag'
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
   - No Actions - (To add one, press 'Action')

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Playing Flag'
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
   - No Actions - (To add one, press 'Action')

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Macro'
If
        Control 'Movie Time KPL non-toggle button' is switched Off
     Or Control 'Movie Time KPL non-toggle button' is switched Fast Off

Then
   - No Actions - (To add one, press 'Action')

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Prep'
If
        Program 'Movie Time Macro' is True
    And Program 'Movie Time Flag' is False

Then
        Set 'Kitchen Movie Scene Fade' On
        Set 'Living Room Movie Scene Fade' On
        Run Program 'Movie Playing Flag' (Else Path)
        Run Program 'Movie Time Prep Action' (Then Path)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Prep Action'
If
   - No Actions - (To add one, press 'Action')

Then
        Run Program 'Movie Time Macro' (Else Path)
        Run Program 'Movie Time Flag' (Then Path)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Start'
If
        Program 'Movie Time Macro' is True
    And Program 'Movie Time Flag' is True
    And Program 'Movie Playing Flag' is False

Then
        Set 'Kitchen Movie Scene Fade' Off
        Set 'Living Room Movie Scene Fade' Off
        Run Program 'Movie Time Start Action' (Then Path)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Start Action'
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
        Run Program 'Movie Time Macro' (Else Path)
        Run Program 'Movie Playing Flag' (Then Path)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Stop'
If
        Program 'Movie Time Macro' is True
    And Program 'Movie Time Flag' is True
    And Program 'Movie Playing Flag' is True

Then
        Set 'Kitchen Movie Scene Fade' On
        Set 'Living Room Movie Scene Fade' On
        Set 'Main Bath' On
        Run Program 'Movie Time Stop Action' (Then Path)

Else
   - No Actions - (To add one, press 'Action')


Program 'Movie Time Stop Action'
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')

Then
        Run Program 'Movie Time Macro' (Else Path)
        Run Program 'Movie Playing Flag' (Else Path)

Else
   - No Actions - (To add one, press 'Action')

The programs Movie Time Flag and Movie Playing Flag have no conditions or actions. They simply serve as status flags. When the Then path is run, the program's status becomes True, and when the Else path is run, the program's status becomes False. Since these Flag programs have no conditions, it does not matter whether their Enabled box is checked or unchecked. The remainder of the programs must have the Enabled box checked, in order that their conditions be automatically evaluated.

When the Movie Time button is pressed (or double-pressed), the Movie Time Macro program runs its Then path, and the program's status becomes True. The Then clause contains no actions, but the program's status is used in the conditions of the following programs.

When Movie Time Macro becomes True and Movie Time Flag is False, program Movie Time Prep runs. It turns on the kitchen and theatre lights, initializes the Movie Playing Flag to False, and then runs the Movie Time Prep Action program. That program then runs the Movie Time Macro program's Else path to set that program's status back to False, and then sets the Movie Time Flag to True. The reason that these two steps must be placed in a separate program rather than in the Movie Time Prep program, is because each of these two steps changes one of the conditions of the Movie Time Prep program, and as soon as the first of these conditions is changed, that program immediately stops running, so the second step would never be executed if these steps were in that program.

The next time the Movie Time button is pressed and Movie Time Macro becomes True, Movie Time Prep will not run because Movie Time Flag is now True. Instead Movie Time Start will run, since its conditions are met. This program turns off the kitchen and theatre lights, and then runs the Movie Time Start Action program. That program then runs the Movie Time Macro program's Else path to set that program's status back to False, and then sets the Movie Playing Flag to True. These two steps are in a separate program for the same reason as above.

The third time the Movie Time button is pressed, neither Movie Time Prep nor Movie Time Start will run because both Movie Time Flag and Movie Playing Flag are True. Instead, Movie Time Stop will run, since its conditions are met. This program turns on the kitchen, theatre and bathroom lights, and then runs the Move Time Stop Action program. That program then runs the Movie Time Macro program's Else path to set that program's status back to False, and then sets the Movie Playing Flag back to False. These two steps are in a separate program for the same reason as above.

It should be noted that the order of the statements in each of the ... Action programs is very important. If Movie Time Prep Action set Movie Time Flag to True before setting Movie Time Macro to False, then Movie Time Start would immediately run. Similarly if Movie Time Start Action set Movie Playing Flag to True before setting Movie Time Macro to False, Movie Time Stop would immediately run. And if Movie Time Stop Action set Movie Playing Flag to False before setting Movie Time Macro to False, then Movie Time Start would immediately run.

It can be seen that the use of the Run (If) command reduces the number of required programs, removes the requirement for special ordering of statements, simplifies the conditions within the If clause of the programs, and provides a more clear and understandable system.




ISY-26 INSTEON / ISY-99i Series INSTEON : How-To Guide