Set a global variable to true if Anyone is home, and false if no one is home


#1

1) Give a description of the problem
Now that I’ve been using webcore for a little while, I’m looking to optimize some of my older pistons. I have a few pistons that run, but only for the 1st person who comes home. Like turning on lights after dark. I was thinking that a simple global variable might be easier to use

2) What is the expected behavior?
Just looking for a simple piston to set a global variable to true if any presence sensor is present, but then set it to false if both are gone. I need it to work if both come home or leave together as well. That is where I think I’m getting hung up

Is there any downsides to doing this, anything to consider with global variables?

Thanks


#2

I have exactly that - a global variable for @HouseOccupied, and background piston that updates it when presence changes.

If any presence sensor changes, then reevaluate the variable. If any are true, then the variable is true.

(Ignore the variables defined, they are leftover from when I stripped this out of another piston; you also don’t need the "or if isempty"bit - that’s so the piston would fire when I used the Test button.)

Since I always know if the house is occupied from this variable, I can use @HouseOccupied changes as a trigger for other pistons.

milhouse


#3

This looks good. I’m just confused by the OR isempty variable in the if logic. What is the goal?

Also has this been rock solid. Any issues with two people arriving or leaving at the same time?


#4

Using that logic got me to set this, The screen caputre does not show which IF statements are ANY and which are all, but Does this look like it would work

Line 18 says if ANY of my presence sensors change
Line 20 says if ALL are not present

Line 25 and line 27 are also ANY.

You’re logic got me thinking, Hows it look? Any gotchas I’m missing?


#5

I have the following piston that lets me know how many people (out of 2) are home. If my @occupancy is zero, I know the house is empty and can treat lighting accordingly.

What this also lets me do is light things differently if someone comes home but one person is already home. If my wife is watching TV for example, I don’t want to light the house up surface-of-the-sun style… but if one or both of us are arriving to an empty house, I can light it up.


SHM and a temporary disarm during certain hours
#6

I like this. Nice and simple. I’m gonna run this and the other piston I created which just sets true/false and see if they both work. I could see possibilites with both.

Thanks


#7

The “IsEmpy” bit was a leftover from some earlier testing when I had more actions in the piston. Testing pistons is hard because they may not have a trigger and actually run. This forced it to run - like the variables, it was from an earlier iteration of the piston when it actually did stuff. Now it does nothing but set that variable. Sorry for the confusion.

Your logic looks like it’ll do what you want. I used an expression because I try to avoid nested if statements. Mine is shorter, but has a hard to read expression. Yours looks longer but it’s quite clear what it does. Except that ANY/ALL bit that you can’t see from this window.

Nicely done.


#8

I love this community. I started not being sure what to do, and how have three valid options. I’ve tested and all work.