Jump to content

Simple Program Review


PB11

Recommended Posts

Hello All

I'm hoping I can get someone's opinion on this little program.

I've previously run this successfully without the else, but I found as my wife came home and I was in the kitchen it triggered the changing of my kitchen to coming home lighting.

I've now created a second PB Arriving Home which will not change the kitchen lighting if one of us is home.

What I'm not certain about is what triggers the assessment of the "else" statement.

My assumption is that the "Else" will not be considered unless the "If" is triggered by the changing of our geofence status and the "If" criteria not being met . Is this correct, or will ISY run through it based on something else?

When is it correct to group "if" statements in "(   )"

Thanks very much

image.png.35d5c2b623d7fdc7e6f60a6a4b464617.png

Link to comment

This Program Runs when either geofence changes state.  Assuming that iNeighborhood is an Interger variable it will not run when the variable changes state. (however, if it was a State variable it would also run when the variable changes state.)

When it runs it will evaluate all 3 conditions to either true or false.  When all 3 are true the THEN block will run, OTHERWISE the ELSE Block will run.  So in a nutshell, if EITHER geofence changes state, then EITHER "Then" or "Else" will be executed.

16 minutes ago, PB11 said:

When is it correct to group "if" statements in "(   )"

Grouping with ( ) causes what's inside the () to be evaluated first. (just like algebra)

so if you put the 2nd and 3rd elements in your above IF statement in ( ) then the iNeighboorhood condistion would only apply to APiPhone. 

Link to comment

 

Ok, clear on the (). Thanks for that.

Regarding the "If", 

49 minutes ago, MrBill said:

So in a nutshell, if EITHER geofence changes state, then EITHER "Then" or "Else" will be executed.

So PB geofence changing to false, and AP Geofence still at false, will execute "Else". So this would result in my light coming on when no one is home?

Link to comment
10 minutes ago, PB11 said:

So PB geofence changing to false, and AP Geofence still at false, will execute "Else". So this would result in my light coming on when no one is home?

Yes.   If EITHER change then ALL are evaluated.

Most of the time if you have AND (or even sometimes OR) in an IF statement you won't want to use the ELSE. (it will run too often since it runs anytime any portion of the IF statement is false.  Instead write a second program with inverted IF logic for what your wanting to put in Else.

Link to comment

BTW... since you're using Locative and the Portal nodeserver, you might want to revisit the wikipage and add the HOME folder node (step 4).   @Javiand I recently corrected Step 4 so that it makes better sense.

Essentially by adding Location, you get a third condition that is True if EITHER of you are Home, and false if NEITHER of you are home. 

image.png.7ff35cf70a90a1777a55b3ca21cce611.png

This greatly simplifies what you're trying to do above.

Link to comment
28 minutes ago, MrBill said:

Instead write a second program with inverted IF logic for what your wanting to put in Else.

 

Really, that easy? And this would cover either of us home and one arriving home.

image.png.7bb0f9affc9aa9c62c47b584964bdcc1.png

20 minutes ago, MrBill said:

BTW... since you're using Locative and the Portal nodeserver, you might want to revisit the wikipage and add the HOME folder node (step 4).

Ok, before I go any further on this, I'll definitely check it out. Thanks very much.

Link to comment

Wait, that wouldn't let me set conditions based on one person already home or me just arriving home.

The "LakeHouse" status would be True when the "If" statement is assessed in either situation. Correct?

I will keep the universal "home" status in mind though. I hadn't considered that.

Link to comment

Archived

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


  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      36.9k
    • Total Posts
      370.2k
×
×
  • Create New...