JGLI

Multiple if statements...

17 posts in this topic

Can you have multiple "IF" statements that behave as "AND"? 

I have setup the system so that if either garage door opens the garage thermostat is turned off.  The system is also set so that when a garage door is off, a 5 minute timer starts, after which the thermostat goes back on.  But I want to make sure both doors are closed before it turns on.  I attached a screen shot of the programming with two If statements.  Will this work?

Multipleif.tiff

Share this post


Link to post
Share on other sites

When does the timer start?

 

make a number variable and set it to 0. Then program when the garage opens +1 when the close -1. 

Then when that variable changes 

if >0 turn off tstat

if = 0 set to auto

And forget the tomer

Share this post


Link to post
Share on other sites

Timer starts when the door closes.  I want to make sure that the thermostat doesn't turn back until 5 minutes after both doors are closed.

How does your logic help with multiple If - i.e., taking into account both doors (and the delay).

Share this post


Link to post
Share on other sites

Sorry didn't look at picture. Just "nest" the two statements under the first conditional by dragging them onto the ?

shoukdnlook like this

? If ....

        ? If. .....

                -> set to auto

Share this post


Link to post
Share on other sites
3 minutes ago, knowitall said:

Sorry didn't look at picture. Just "nest" the two statements under the first conditional by dragging them onto the ?

shoukdnlook like this

? If ....

        ? If. .....

                -> set to auto

 

3 minutes ago, knowitall said:

Sorry didn't look at picture. Just "nest" the two statements under the first conditional by dragging them onto the ?

shoukdnlook like this

? If ....

        ? If. .....

                -> set to auto

But if you nest them you aren't really getting an "AND" are you?  I need to make sure both doors are closed before I turn on thermostat.  If I nest it, I would need to do it twice, one with one door at the top and the other with the other door at the top (at least in traditional programming).

Share this post


Link to post
Share on other sites

Sure you are cus both conditionals must be true  

timer expires left door open nothing happens. 

 

Timer expires left door closed right door open nothing happens. 

Timer expires left door closed right door closed tstat goes to auto

Share this post


Link to post
Share on other sites

OK, so my brain is soft.  I see the logic working.

If Left is closed, and then if Right is closed, then the stat goes to Auto.

My concern was that it wasn't testing for Right, but its irrelevant as if Left is Open it won't turn the stat on.

 

Is there a simpler way to do this?

In normal code i would have written something like this?

If Left is open or Right is Open 

BothDoorOpen := True

End If

If Left Door changes to Closed & Right Door is Closed

BothDoorOpen := False

If Right Door changes to Closed and Left Door is Closed

BothDoorOpen :=False

When BothDoorOpen = False & 5 minute have elapsed, 

Set Thermostat to Auto

 

Share this post


Link to post
Share on other sites
9 hours ago, JGLI said:

Can you have multiple "IF" statements that behave as "AND"? 

I have setup the system so that if either garage door opens the garage thermostat is turned off.  The system is also set so that when a garage door is off, a 5 minute timer starts, after which the thermostat goes back on.  But I want to make sure both doors are closed before it turns on.  I attached a screen shot of the programming with two If statements.  Will this work?

Multipleif.tiff

JGLI, your programming is correct, all you have to do is nest all the statements. To answer your question: yes! When you have 2 or more "if" statements nested, they act as "and". But they have to be nested.

Share this post


Link to post
Share on other sites

The reason my pseudo code would be easier is that its all on one place.  This is a lot more than 3 lines of code.

You have to setup a timer, go to both dear and create programing for open and closing, and then this snippet which happens to be three lines.

Eddy, thanks for confirming that the nesting of Ifs behaves like "AND".

Share this post


Link to post
Share on other sites

but you can create macros and call macros in multiple places which cuts down on progamming

Share this post


Link to post
Share on other sites

This is a simple 3 line script to make this work. Am I missing something? The OP had it right the first time, just needs to nest the lines. 

Share this post


Link to post
Share on other sites

All good now, just need to get used to the way this work. Thanks for the help.

Share this post


Link to post
Share on other sites

I'm in DFW airport waiting for a connecting flight and was able to test the code (opened the doors, watched thermostat status, etc.).  All worked well  Thanks.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
    • 5 Posts
    • 24 Views
    • 18 Posts
    • 402 Views
    • 11 Posts
    • 209 Views
    • 10 Posts
    • 128 Views
    • 2 Posts
    • 40 Views
    • 3 Posts
    • 126 Views