Skip to content
View in the app

A better way to browse. Learn more.

Universal Devices Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Nested If's?

Featured Replies

Hi - trying to find out if there is a way to do a nested "if". In other words - I need the "if" to be inside the "Then" and the "Else" (I need to do this for a variable test as part of a program that tests status of several devices).

I cannot add this test as part of the first "if" because then the "else" will fire and run those commands - though I need the same "if" within the else.

Basically the code would be:

IF status Device_X is off

AND status Device_Y is off

AND status Device_Z is off

Then

if variable Poll_Running =1

Then do something

Else

if variable Poll_Running =1

then do something different

Bottom line - if the Poll_Running variable is not 1 - then I don't want anything to happen irrespective of the state of the devices.

Any thoughts?

If I understand your needs, Create the variable Poll_running as an integer type and add it to the If. They do not cause a program to trigger like state type.

Edited by hart2hart

You can't have an IF statement in the THEN or ELSE statement

You can split it up into two programs

Edited by Techman

There is a nasty way of doing most of these using "repeat while" construct.

If whatever
Then
do something
Repeat While 'lamp' < 1%
do somethingElse
set 'lamp' = 100%
Repeat for 1 times
do anotherthing
Else
--

Of course you can set a variable before the repeat while loop and then modify it in the loop.

Dirty but it can work in most cases.
Multiple Case type constructs can be built by terminating each Case with a line:
Stop 'ThisProgram' .

Note: Repeat For X times is a program logical syntax error. 'Repeat 1 times' means no repeat at all. Should have been named:
'Execute for 1 times'.

11 hours ago, SMonk said:

trying to find out if there is a way to do a nested "if"

@hart2hart 's solution should work in your particular situation. If, for some reason, you cannot change the variable to an "integer" type, then allow me to expand upon @Techman 's suggestion to try a second program:

if IF status Device_X is off

AND status Device_Y is off

AND status Device_Z is off

then run a second program (if path)

Second program (disabled):

if variable Poll_Running =1

then do something

  • Author
16 hours ago, hart2hart said:

If I understand your needs, Create the variable Poll_running as an integer type and add it to the If. They do not cause a program to trigger like state type.

I originally thought about this (the Poll_Running variable is already an integer - set by a prior program). Unfortunately if I add th ePoll_Running variabel to the if clause - then when this runs if Poll_Running is "not" 1 - then it will default to the "else" clause when triggered - which I do not want it to do.

  • Author
4 hours ago, oberkc said:

@hart2hart 's solution should work in your particular situation. If, for some reason, you cannot change the variable to an "integer" type, then allow me to expand upon @Techman 's suggestion to try a second program:

if IF status Device_X is off

AND status Device_Y is off

AND status Device_Z is off

then run a second program (if path)

Second program (disabled):

if variable Poll_Running =1

then do something

Yes - this is the approach I decide to try out. It does work - but it's just a lot of programs (as I need to do this for many rooms (one program per room, and one line of the if statement for each device in a room) - hence looking to try and reduce number of programs by finding some potential alternative.

12 hours ago, larryllix said:

There is a nasty way of doing most of these using "repeat while" construct.

If whatever
Then
do something
Repeat While 'lamp' < 1%
do somethingElse
set 'lamp' = 100%
Repeat for 1 times
do anotherthing
Else
--

Of course you can set a variable before the repeat while loop and then modify it in the loop.

Dirty but it can work in most cases.
Multiple Case type constructs can be built by terminating each Case with a line:
Stop 'ThisProgram' .

Note: Repeat For X times is a program logical syntax error. 'Repeat 1 times' means no repeat at all. Should have been named:
'Execute for 1 times'.

This is very interesting - I have never used the "Repeat While" function - I will investigate that. This "could" be the solution to reducing the number of programs significantly. I'll let you know how it goes.

The second program method is the way I do it. The second program is a disabled program that only gets run by the first program. I even name it starting with DNE (for Do Not Enable) to make it stand out.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.