Jump to content

Nested Conditions


Algorithm

Recommended Posts

Posted

How can one nest conditions, something like (pseudo-code):

 

IF
   Condition 1
THEN
   IF
       Condition 2
   THEN
       Action 1
   ELSE
       Action 2
   ENDIF
ELSE
   IF
       Condition 3
   THEN
       Action 3
   ELSE
       Action 4
   ENDIF
ENDIF

Most likely it would need to be done with separate programs, but how?

Posted

At this point it is only done by separate programs. You build your lowest IF program then add it to the next bigger IF program.

 

I will try to build an example and paste it here, but we are getting ready to go to dinner soon, for my younger guy has just turned two, so off to the Spaghetti Factory we go.

Posted
At this point it is only done by separate programs. You build your lowest IF program then add it to the next bigger IF program.

 

I will try to build an example and paste it here, but we are getting ready to go to dinner soon, for my younger guy has just turned two, so off to the Spaghetti Factory we go.

 

Happy birthday to your son! Have a good time, all of you. Will look for some examples after you've recovered. :lol:

Posted

Joe, wouldn't the nesting be handled if the "Run Program" that was suggested in another thread evaluated the "If" conditions rather that just running the "Then" action. So you could convert your nested IFs to three programs. Something like:

 

Program Content for 'Nested Ifs Program'

If
    Condition 1

Then
    Run program 'Condition 2 Program'

Else
    Run program 'Condition 3 Program'

----

Program Content for 'Condition 2 Program'

If
    Condition 2

Then
    Action 1

Else
    Action 2

----

Program content for 'Condition 3 Program'

If
    Condition 3

Then
    Action 3

Else
    Action 4

Posted
Joe, wouldn't the nesting be handled if the "Run Program" that was suggested in another thread evaluated the "If" conditions rather that just running the "Then" action. So you could convert your nested IFs to three programs.

 

Yes, that is exactly so. But I'm not sure how long it may be until the Run Program (with IF) may be approved and implemented. I was hoping there may presently be a way to nest conditionals, even if not as nice as the above.

Posted

You can do this using folder conditions. Folders can be nested as well.

 

In your example, create a folder and put your programs in it as follows

 

Folder:
IF 
   Condition 1
THEN
   Allow the programs in this folder to run. 

Program 1:
IF 
   Condition 2 
THEN 
   Action 1 
ELSE 
   Action 2 
ENDIF 

Program 3:
IF 
   Condition 3 
THEN 
   Action 3 
ELSE 
   Action 4 
ENDIF 

Posted
You can do this using folder conditions. Folders can be nested as well.

 

In your example, create a folder and put your programs in it as follows

 

Yes, that will do it! Thank you Chris. Now, could you give us the rundown on what happens to running programs within a folder, when the folder conditions become False, asked in this thread?

Posted

Thanks Chris! I never thought of doing it that way.

 

 

You can do this using folder conditions. Folders can be nested as well.

 

In your example, create a folder and put your programs in it as follows

 

Folder:
IF 
   Condition 1
THEN
   Allow the programs in this folder to run. 

Program 1:
IF 
   Condition 2 
THEN 
   Action 1 
ELSE 
   Action 2 
ENDIF 

Program 3:
IF 
   Condition 3 
THEN 
   Action 3 
ELSE 
   Action 4 
ENDIF 

Posted
You can do this using folder conditions. Folders can be nested as well.

Thank you Chris. I hadn't thought of using folder conditions this way. I'd only used them for organizing/controlling the included programs with broad seasonal time controls and hadn't realized that folders could be nested!

Posted
You can do this using folder conditions. Folders can be nested as well.

 

In your example, create a folder and put your programs in it as follows

 

Folder:
IF 
   Condition 1
THEN
   Allow the programs in this folder to run. 

Program 1:
IF 
   Condition 2 
THEN 
   Action 1 
ELSE 
   Action 2 
ENDIF 

Program 3:
IF 
   Condition 3 
THEN 
   Action 3 
ELSE 
   Action 4 
ENDIF 

 

Forgive me for being dense, but I haven't yet quite got what I need here.

 

Let's say the programs in Folder are all mutually exclusive (but encompass all possible conditions of the set), so that exactly one program should run. [NOTE]

 

So, a trigger runs a certain program, let's call it Program 1. Program 1 takes some actions, then requires one group of additional actions, selected from a number of such groups, to be taken. So we place each group of additional actions in a program, and place the collection of such programs in Folder.

 

Now, how can I have the one program whose conditions are true, automatically run when Folder's conditions become true? What conditions should Folder have to allow Program 1 to run the one program within it whose conditions are true?

Posted

To put it another way, folder conditions do not initiate any activity within the folder, they simply deny/allow such activity when some external event occurs.

 

So in my example where the conditions for all of the programs within folder are based on other 'flag' programs, rather than on external events such as Status, Control or X-10, how can one of the programs be made to run when the folder conditions become true? It seems (from what I've observed) that such 'flag' conditions of programs within the folder are not continuously evaluated the same way other conditions are.

 

This could be accomplished with the 'Run If...' capability should it become available, but is there any way to do it right now?

Posted

The problem you are having is that you want an event that affects only the Folder conditions to also cause the programs within the folder to run.

 

For example:

 

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

If
       X10 'A6/On (3)' is Received

Then
  Allow the programs in this folder to run.

 

Program A within the folder:

If
       Status  'Light1 ' is Off

Then
       Set 'Light1 ' On

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

 

In this case, when 'A6/On' is received, the Folder Condition becomes True, but Program A will not run because the 'A6/On' is not an event relevant to that program.

 

To get this type of nested condtion, you have to do it in a reverse sort of way:

 

Program: Condition1

If
       X10 'A6/On (3)' is Received

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

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

 

If
       Program 'Condition1' is True
   And Status  'Light1' is Off

Then
       Set 'Light1' On

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

Posted

Thank you, Chris!

 

So with the nesting example I'm trying to achieve, I don't want to have a folder with conditions, but extra conditions on each related program (and perhaps all the related programs in a folder for organization)?

 

So it might look something like this:

Program: Condition1

If
       Condition 1 is True

Then
       Condition 1 Actions
       Run Program 'Condition1' (Else Path)

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

Program: Condition2
If
       Program 'Condition1' is True
   And Condition 2 is True

Then
       Condition 2 Actions

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

Program: Condition3
If
       Program 'Condition1' is True
   And Condition 3 is True

Then
       Condition 3 Actions

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

 

and so forth for as many conditions as required? And after program Condition1 is complete, it runs its own Else path to make itself false until the next trigger.

 

I tried one group like this, and it seemed to operate as desired. So, if this is the correct method, then I'll get busy with doing more of them. :D

Posted

I tried one group like this, and it seemed to operate as desired. So, if this is the correct method, then I'll get busy with doing more of them.

I think this is the best method for what you want to do.

 

And after program Condition1 is complete, it runs its own Else path to make itself false until the next trigger.

Yes, that is a good way to change the program back to False, although it should be used on an as needed basis. For example, you wouldn't do that if your condition was a From/To (or From/For) time range because the program would automatically become True when entering the time range and False when leaving it.

 

I should have also mentioned that you can use the 'And (...)'/'Or (...)' buttons as well to further nest conditions within a program.

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.


×
×
  • Create New...