Jump to content

Please provide integer variables and a select case structure


Melor

Recommended Posts

I cannot believe that I have been creating variables by setting the status of programs. Happily I have only needed two bit variables so far...

 

This is a terrible shortcoming of a great product.

 

With a variable and some type of select case structure it would be a pleasure to create a variety of scenes that can be selected by one button on a KPL, unlike the workaround needed now. The workaround needs 4 programs, one for each scene and two "variable" bit programs. Not only is this a pain to code and organize, but prone to errors and difficulty implementing. Below is one of 4 scene programs that cycle through on one KPL button.

 

Paul

 

 

 

If

(

Control 'MBR KPL - C Scene Changer' is switched On

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is False

And Program 'zzz MBR Mood Flag2' is True

 

Then

Set Scene 'sc MBR Mood Reading' On

Run Program 'zzz MBR Mood Flag1' (Then Path)

Run Program 'zzz MBR Mood Flag2' (Else Path)

Set Scene 'sc MBR KPL Scene Button C' On

 

Else

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

Link to comment

Hi Paul,

 

Thanks so very much for the feedback. You are 100% correct and this has been a regularly requested feature slated for 2.8 or 2.9. In short, we understand its importance and shall get it done.

 

With kind regards,

Michel

 

I cannot believe that I have been creating variables by setting the status of programs. Happily I have only needed two bit variables so far...

 

This is a terrible shortcoming of a great product.

 

With a variable and some type of select case structure it would be a pleasure to create a variety of scenes that can be selected by one button on a KPL, unlike the workaround needed now. The workaround needs 4 programs, one for each scene and two "variable" bit programs. Not only is this a pain to code and organize, but prone to errors and difficulty implementing. Below is one of 4 scene programs that cycle through on one KPL button.

 

Paul

 

 

 

If

(

Control 'MBR KPL - C Scene Changer' is switched On

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is False

And Program 'zzz MBR Mood Flag2' is True

 

Then

Set Scene 'sc MBR Mood Reading' On

Run Program 'zzz MBR Mood Flag1' (Then Path)

Run Program 'zzz MBR Mood Flag2' (Else Path)

Set Scene 'sc MBR KPL Scene Button C' On

 

Else

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

Link to comment

Hello Paul,

 

This does not directly address the point of your post (I think most of us are anxiously awaiting variables, timers, etc.), but rather the workaround.

 

The program you posted probably won't work as expected, because your If clause depends upon two conditions ('zzz MBR Mood Flag1' and 'zzz MBR Mood Flag2') whose values are changed in the Then clause. When the first is changed, the overall condition becomes false, and therefore the Then clause terminates and the Else clause executes.

 

One can normally get away with changing a single condition element, provided it is the last statement of the Then (or Else) clause. But since you are changing two conditions, you should use a separate program.

 

Yes, it is messy. If you post your requirements, perhaps someone may be able to provide a solution.

Link to comment

Ouch...

 

 

Hello Paul,

 

This does not directly address the point of your post (I think most of us are anxiously awaiting variables, timers, etc.), but rather the workaround.

 

The program you posted probably won't work as expected, because your If clause depends upon two conditions ('zzz MBR Mood Flag1' and 'zzz MBR Mood Flag2') whose values are changed in the Then clause. When the first is changed, the overall condition becomes false, and therefore the Then clause terminates and the Else clause executes.

 

One can normally get away with changing a single condition element, provided it is the last statement of the Then (or Else) clause. But since you are changing two conditions, you should use a separate program.

 

Yes, it is messy. If you post your requirements, perhaps someone may be able to provide a solution.

 

Actually it works GREAT. I use the two flag programs as bits in a two bit word. There are 4 states 00, 01, 10 and 11. Each time a button on a KPL is triggered the bits are incremented by one. Each state is associated with a particular scene. You are correct. It is messy. Can I say this is a two bit solution to a two bit programming environment? Yes I can. I cut my teeth learning to program 8080 cpu's with front panel switches. At least the 8080 was well documented. I have no problem building words with bits, but where is the documentation that tells you that by running the else you set a 0 and running the then you set a 1? You need an area on your website that explains how the program works with examples of code that illustrate that which is not apparently documented.

 

I will post the entire code for one of my rotating scene changers in my next post on this thread.

 

Paul

Link to comment

Purpose: 1)Create a group of scenes that can be rotated through with one button on a KeyPadLinc ( KPL )

2) Have the light on the KPL button act as an indicator.

3) Allow for a timeout that breaks the rotation from one scene to the next if desired.

 

An example. You have a KPL that controls your lighting scheme in your bedroom. In my case I have two bedside table lights, recessed lighting in the ceiling, a sitting room light, bathroom vanity lights and accent lights in the bathroom. 6 sets of lights and 6 controls in my master bedroom.

I want to be able to press a single KPL button and

1) Have a candle-light scene with all lights very dim.

2) Set a TV in bed scene with all lights moderate.

3) Set a “reading scene†with lights on the bedside tables bright, other lights moderate.

4) Turn all lights on to max.

5) Turn all lights off.

To do this you need to create a variable that you increment through each of the scenes so that upon each KPL button press you set the correct scene. Since the ISY doesn’t support variables a little improvisation is needed.

In my example I use button C of a KPL. It is a controller of a single scene that has no other controls linked to it. This scene allows the ISY to signal back to the KPL by illuminating the light in the switch. This can signal the end of the 4 scene cycle or simply that you are using the scene button.

The four scenes are “sc 1†– “sc 4†Assume the first one is all lights on like in the list above. Scene 5 is actually scene 1 – off and not a programmed scene.

 

The flag programs are two indicators of off or on. Together they create a binary variable that has 4 states off-off, off-on, on-off, on-on. In binary this is 00, 01,10,11 or in decimal 0,1,2,3. Piece of cake. There is no if/then/else component of these two programs. Just create a flag1 and flag2 program.

 

You need 4 programs, one for each of the 4 programmed scenes. Each program will check for a button press on KPL button c and run whatever of the 4 programs matches the status of the flags.

 

To create a timeout that resets the series to a start simply run the else path of the two flag variables so the next time it is run it will start at the first scene. To this at whatever time interval you want to set using a wait state after the button control is pressed.

 

Paul

 

btw, this does work in three different rooms of my house controlled by three different KPLs. My bedroom, the kitchen and the exterior lights. If you have difficulty let me know. Or wait for a variable and even better a select case type of structure.

 

PJ

 

 

===============================================================

This is the one that runs with the c-button AND state 0 ( or 00b or off-off )

If

(

Control 'MBR KPL - C Scene Changer' is switched On <=These two lines check for a button press

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is False = These two lines check for a 00 state.

And Program 'zzz MBR Mood Flag2' is False

 

Then

Set Scene 'sc MBR Mood Low Light' On <= This turns on the lowest light scene

Run Program 'zzz MBR Mood Flag2' (Then Path) < =This sets the state from 00 to 01 ( the second bit is now on )

Set Scene 'sc MBR KPL Scene Button C' On < =This keeps the light on the KPL.

 

Else

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

===============================================================

This program runs with state 01

If

(

Control 'MBR KPL - C Scene Changer' is switched On

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is False

And Program 'zzz MBR Mood Flag2' is True

 

Then

Set Scene 'sc MBR Mood Reading' On

Run Program 'zzz MBR Mood Flag1' (Then Path)

Run Program 'zzz MBR Mood Flag2' (Else Path)

Set Scene 'sc MBR KPL Scene Button C' On

 

Else

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

===============================================================

This one runs with state 10

If

(

Control 'MBR KPL - C Scene Changer' is switched On

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is True

And Program 'zzz MBR Mood Flag2' is False

 

Then

Set Scene 'sc MBR Mood TV' On

Run Program 'zzz MBR Mood Flag2' (Then Path)

Set Scene 'sc MBR KPL Scene Button C' On

 

Else

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

===============================================================

This is the last of the 4 scenes that is run with the button advance. 11 binary or 3 decimal.

If

(

Control 'MBR KPL - C Scene Changer' is switched On

Or Control 'MBR KPL - C Scene Changer' is switched Off

)

And Program 'zzz MBR Mood Flag1' is True

And Program 'zzz MBR Mood Flag2' is True

 

Then

Set Scene 'sc MBR Mood All Lights' On

Run Program 'zzz MBR Mood Flag1' (Else Path)

Run Program 'zzz MBR Mood Flag2' (Else Path)

Set Scene 'sc MBR KPL Scene Button C' Off

 

Else

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

===============================================================

So how do you get the 5 th scene? Check for a fast on or fast off ( double click on the button ) and turn off the “all lights on†scene.

 

If

Control 'MBR KPL - C Scene Changer' is switched Fast On

Or Control 'MBR KPL - C Scene Changer' is switched Fast Off

 

Then

Set Scene 'sc MBR Mood All Lights' Off

Set Scene 'sc MBR KPL Scene Button C' Off <= turn OFF the LED in the KPL

Run Program 'zzz MBR Mood Flag1' (Else Path) <= These two lines reset the counter to 00 so the next time it is run it starts at the low light.

Run Program 'zzz MBR Mood Flag2' (Else Path)

 

Else

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

Link to comment

Hello Paul,

 

You are 100% correct! I checked with our programming guru, and it seems that there are certain other factors that come into play.

 

A series of statements within a Then clause (or within an Else clause), up to the next Wait or Repeat statement, are atomic. In other words, all such statements are executed before the conditions of the program are retested. The program's conditions are reevaluated each time a Wait or Repeat statement is encountered, and at the end of each iteration of a Repeat loop.

 

What this means is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or the Then clause).

 

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated.

 

Apologies for any confusion, and I hope this helps to clarify program execution with regard to changing conditions.

 

Thanks for posting your cyclic-scenes example, which should certainly be helpful to others with similar needs.

Link to comment

Archived

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


×
×
  • Create New...