Join two sets of OR variables with an AND?


#1

I have two variables for location status of myself or my girlfriend. I have two variables for time of day. I’m trying to figure out how to write a statement that says if she OR I changes location AND the time time of day is one OR the other…

Obviously I know how I want it to function, I just can’t seem to find a way to get a webcore statement to allow it the way I want. Which statement should I be using?


#2

I am thinking something like:

IF SensorA or SensorB's presence changes  <-- Trigger
Then
    IF Time is between W & X              <-- Condition
        Then Do cool stuff
    END IF
END IF

#3

Well, yes. I suppose I could use a second IF statement nested like that. That’s about the only way I have figured out to do it. I had just assumed there might be a more elegant way than doing it as a double nested IF statement like that. I have my time of day defined by another piston so that at specific times it sets a variable as morning, afternoon, evening, or night.

I ended up just writing the same code twice in the same piston, once for each presence sensor:

IF SensorA changes to home
AND
Time of day is evening OR night
Etc

and then

IF SensorB changes to home
AND
Time of day is evening OR night
Etc

Both ways use two IF statements, but I feel like splitting them up is a little easier because it isn’t as nested. Who knows, maybe it wouldn’t matter?


#4

Both triggers run thru the code top to bottom…
so if you are asking for elegance, my vote is on the nested IF.

But hey, if you are happy, then I am happy. :sunglasses:


Note:

Your method allows for more customization…
My method allows for less typing and internal checks

I use both methods… Depending on the circumstance.


#5

Thanks. I put this together real fast, and I think I see what you mean. Top to bottom, doesn’t matter. It still checks the true/false of it all, and since I’m doing the same functions, I bet this would be easier and work just as well while saving storage space.


#6

Yes, perfect example of elegance… Well done!