Arrival/departure if/then or case statement?


#1

1) Give a description of the problem
I want proper updates of who is home. I borrowed this from an example piston and am wondering if this can be simplified with a case statement when either of the presence sensor statuses change?

2) What is the expected behavior?
I want to know when someone is home (who), when both are home and when both are gone. So 4 statuses:

Both Away, I am home, GF is home and Both Home.

3) What is happening/not happening?
I seem to have random and overlapping status.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Can’ tremember who I got this from, but been using it for months and works great!


#3

Thanks. This may work with some modifications to set the proper hub status. What is isn’t taking care of is, I have the presense change of a person to automatically close the garage door and send a message. In the message I delay it and read the actual status of my garage door sensor (real status) to be sure that the door is actually closed.

This running by itself well actually give me good visibility to the status of the presence sensors though via the tiles.

I think I still need something else to handle the departures…


#4

this one is @ady624 that I have also been using for garage door and notifications. Maybe parts of each will help.


#5

this is one my example pistons. glad to hear its working great. :smile:

but it doesnt handle anything other than presence tiles which @kxavier_23 seems to be interested in.


#6

try this one. probably not going to work exactly right the first time but if you try it and give me the feedback i will fix up whatever is not working.

i dont have the same location modes you do so i used:
Away = No one is home
Movie = Only wife is home
Party = Only I am home
Home = both are home

Presence sensor 5 = wife phone
Presence sensor 3 = my phone


#7

This is actually the piston I copied back when I created mine.

Here is my issues:

  1. I am using ady624 presence senor app on my phone, which I am using a smaller arrival geofence. So what happens is my gf, “arrives,” probably 5-10 seconds before I, “arrive”. So this results in a message that she arrived, immediately followed up by, both of us have arrived.

  2. I was able to enable contacts in ST, so I would like to only send arrival/departure messages to the person that arrives or leaves. I would assume I would need anther case or if/then in the Do statement of the PUSH messages.

So as you can see, it is pretty close, but needs a little work.


#8

I haven’t tested this yet, but I changed the departure section to send notifications to a contact based on the current device that left. Is this the right approach?

Would this work for the arrivals?


#9

Sorry for the additional reply, but I took a stab at the contact messages on arrival. I modded ady524s piston again and added the following:

To avoid the presence sensors not updating at the same time, I set a delay of 10 seconds (line 86). Hoping that the second presence change would overwrite the first, then only give me the second values.

I then allowed the log info to be updated. Inside that, I added a case statement to only send a push notification to variable “StringWho,”

The next statement was from the original where I want to turn on the entryway light if my outside multi-sensor’s lux value is below 500. Same as what I am using from your Rooms Manager app :smiley:

See below:


#10

I have the sensor departure portion is working. I am just struggling with the arrivals working as far as updating the Hub Statuses, Me home, GF home, Both home etc. None of the change of presence sensors = presence does not seem to work.

Here is my latest version:


#11

:+1:

instead of using the switch case with whohome after the 10 second wait do 3 ifs

if presence sensor 2 is present
   and
   presence sensor 3 is present
end if
if presence sensor 2 is present
   and
   presence sensor 3 is not present
end if
if presence sensor 2 is not present
   and
   presence sensor 3 is present
end if

and set stringwho and hub status appropriately under each if condition.


#12

I moved that entire statement up as an else if condition after my main if. So:

If - presence sensors leave

else if - presence sensors arrive

This seems to have resolved the lack of statuses updating in some initial tests.

I will have to see how the both arriving and both leaving behaves.

Ideally, I would send a message to both contacts upon arrival or departure.

Thanks for the help !!


#13

So I tried changing this all to location based piston. My hope is to make this work so that I can apply some of the same to my cabin as well since I have another instance of webCoRE installed on that hub.

I seemed to have completely screwed this up now… Can anyone help?

Essentially, I want to shut the garage door when either of our presence sensors leave the location = House.

This seems to still work, although I can’t get it to send us both a message. My phone seems to trigger the piston first, and my gf never gets a message at all.

I also want to change the location mode to one of the following based on who is home:

Both Home
Both Away
GF Home
I am Home

Should I put the location statuses in a separate piston entirely?

I know there are plenty of variables defined that I don’t need, but I was trying to see what was being set.

Thank you.


#14

why not do something like this?

on event from your presence sensor, gf presence sensor currentplace
   if your ps or gf ps current place changes away from 'house'
      close garage door
      send notification to $currenteventdevice
   end if
   if your ps and gf ps current place is 'house'
      set mode to both home
   else
      if your ps current place is 'house'
         set mode to you home
      else
         if gs ps current place is 'house'
            set mode to gf home
         else
            set mode to both away
         end if
      end if
   end if
end on

#15

Ok. I rewrote this as follows.

How does this look?

And is there any way to simulate this to test? i.e. force the currentPlace for either of these devices.


#16

Is Switch 1 the closer for your garage door?

If it is, I have a few free minutes I can take a stab at writing something up for you. Just want to make sure I understand the devices listed and your goals.


#17

This has the basics of what you’re after, but not any of the time restrictions you were trying to work in. Let me know what time restrictions (or scenarios you don’t want you and your girlfriend to receive a text) and I can work something up.

I had to go to standard presence sensors to make this work since I only have one WC presence sensor… but this should be easy enough to follow and switch back to your sensors:


#18

So here is what I want to happen…

I may have to put this in 2 pistons?

When our presence sensors (using ady624’s presence sensor app), leave the, “house”, check to see if the contact sensor on the garage is open. If it is, turn on the momentary switch (switch 1). I wait 15 seconds, then send a message to the user that the garage is closed (closed is really reading the contact sensor again so that if it reads, “open,” I know the garage is really still open).

I had this all working except when we both leave… What happens in reality, is that my presence sensor (9 times out of 10), will trigger the piston. This is causing 2 issues:

  1. Only I get a message that the garage is closed. If we are not in the same car, it would be nice if we both got messages on our phones.

  2. The location status is not updating correctly. Since it picks my current place change first, it typically says she is home, when in reality, she left at the same time which should result in, “both away”.

Attached is another version I had tried. I have have tried case statements around who is actually home etc.

Where I don’t know if I need a separate piston is on arrival, I want to check the status of the entryway light and turn it on if my outside lux sensor is below a value say 1500 lux. I would also like to send a message to the user(s) that arrive to tell them the temp in the house (variable upstairs).

Obviously the same logic on arrival would apply to the location statuses as well.

Both Away
GF home
Me home
Both home

Old piston:


#19

Ok, gotcha. Can you try the version above to see if it does what you want it to? It should - but if I doesn’t I have an idea to make it work.

Alternatively, here’s one for my wife and I that does the same thing you’re after. It works for both of us, every time. It’ll take a little customizing to get it to what you want (really just the adding of the 15 second wait and stripping out the extra garage door controls and holiday messages) but it should serve as a good alternative if the one above doesn’t work for you.


#20

I will test this

I added what I think need to be the opposite on currentPlace changing back to home. Plus, my light on (as long as it is off), then setting the location status.

Think it will work?