Jump to content

If statement order


sceaton

Recommended Posts

Posted

Do we differentiate between when a KPL button was pressed, and just testing whether the button status is on/off by the order of the 'If' statements?

 

For example, I want to run an "all off" scene when my "Away" button is pressed on. Later, at sunset, I want to turn on another scene IF the away button is ON.

 

Program: Start Away Mode

If
       Control 'KPL@Office - Away' is On //same as below

Then
       Set  Scene 'All Off' Off

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

 

Program: Welcome Home

If
       Time is Sunset 
   And Control 'KPL@Office - Away' is On //same as above

Then
       Set  Scene 'Welcome Home Evening' On

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

 

 

Does the ORDER of the if statements determine what triggers the program to fire? So the first program will look for the Away button to be pressed. The second program will wait for Sunset ... at sunset, it will then move to the next condition and check the status of the Away button and continue (or not).

 

I understand that I can't control the status of a KPL button directly; the workaround is to place the button into a scene, and turn that scene on or off.

 

I guess I'm confused as to what exactly the KPL limitation is when making programs, and why we can't use both status and control events.

 

Thanks!

Posted

The order of the IF statements does not matter. In your second program, you should be testing the 'Status' of the button.

 

I think part of your confusion are the bugs in the current beta drop (not being able to test status of KPL, program true/false not set consistently). These have been fixed for the next drop.

 

In general though, I would use a folder condition instead.

 

Folder 'Away' - Allows programs in the folder to run if 'Keypad A' is pressed On, stops them from running when it is pressed 'Off'

Folder Conditions for 'Away'
Add conditions to limit when programs in this folder are allowed to run.

If
       Control 'Keypad A' is switched On
   And Control 'Keypad A' is not switched Off

Then
  Allow the programs in this folder to run.

 

Then just put your 'Welcome Home' program in your 'Away' folder

 

Program 'Welcome Home'

If 
       Time is Sunset 

Then 
       Set  Scene 'Welcome Home Evening' On 

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

Posted
I think part of your confusion are the bugs in the current beta drop (not being able to test status of KPL, program true/false not set consistently). These have been fixed for the next drop.

 

You're right! Thanks for explanation! ... crystal clear!

 

~shawn

Posted

except ...

 

Why are the two If statements necessary? If it is switched On, doesn't that inherently mean it is NOT switched Off?

Folder Conditions for 'Away'
Add conditions to limit when programs in this folder are allowed to run.

If
       Control 'Keypad A' is switched On
   And Control 'Keypad A' is not switched Off

Then
  Allow the programs in this folder to run.

Posted

Good Question!

 

The big change from 2.4.8 is that there are no longer inferred events. This is the primary reason for replacing 'Finally' with 'Else'.

 

The key here is that the true/false status, and whether a program runs (either the Then or the Else) is dependent on a recognized event.

 

For Controls and X10 messages, events must match exactly, meaning:

 

- For Controls, both the switch and value must match

- For X10 Messages, the house code/unit code and command must match.

 

The 'is not' allows you to test for the negative (i.e. false if the button is pressed)

 

Therefore the following program will only change state if 'Keypad A' is switched On, or switched Off. If you press 'Fast On' or 'Brighten' on 'Keypad A', the program will not change because these events are not relevant to the program.

 

If 
       Control 'Keypad A' is switched On  
   And Control 'Keypad A' is not switched Off 

 

FYI ... As discussed in another thread, if you explicitly run a program, its status becomes true. If you explicitly Run the else its status becomes false.

 

Not all of these changes are in the code drop you are using now; but they will be in the next code drop.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing

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

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      37.2k
    • Total Posts
      372.5k
×
×
  • Create New...