Logic with Virtual Presence and Vacation Sensors


#1

Hi all,

I currently have a piston that changes my SHM status automatically each night and morning. This all works fine but it uses phone virtual presence sensors.

I’d like to add another layer to this. I created a virtual switch for each household member called "Vacation - ". Basically, if a household member has their Vacation switch set to ON, then we should ignore the fact that their presence sensor reads “not present”.

I figured I’d make a separate piston called “Everybody Home” that evaluates to true if all members of the household are home that are not marked as “Vacation: On”, and use that as a Global Variable in my other pistons.

I’m a programmer but am having trouble wrapping my head around the best approach to this logic besides a whole bunch of nested IF statements. Doing this for one member is simple but there may also be cases where more than one household members are not home.

Another approach might be to create separate pistons for each household member that evaluates to true if not present and vacation switch is on.

Has anyone done this sort of thing?


#2

One approach would be to set up a global device @onVacation variable that will contain any on vacation devices.

The piston that will update this global variable would just watch for events from the vacation switches.

If any of vacSwitch1, vacSwitch2, and vacSwitch3 changes to on
  with Location
    @onVacation = @onVacation + $currentEventDevice

If any of vacSwitch1, vacSwitch2, and vacSwitch3 changes to off
  with Location
    @onVacation = @onVacation - $currentEventDevice

Now in your piston with the SHM stuff, you can add a statement to see if count(@onVacation) > 0.