Arrival/departure if/then or case statement?


#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?


#21

This is the log from departure:

12/13/2017, 8:29:00 PM +138ms
+1ms ╔Received event [Home].time = 1513218541289 with a delay of -1152ms
+133ms ║RunTime Analysis CS > 23ms > PS > 43ms > PE > 67ms > CE
+137ms ║Runtime (53246 bytes) successfully initialized in 43ms (v0.2.100.20171211) (135ms)
+139ms ║╔Execution stage started
+161ms ║║Cancelling statement #24’s schedules…
+380ms ║║Calculating (string) Renee Presence Sensor + (string) left the house at >> (string) Renee Presence Sensor left the house at
+386ms ║║Calculating (string) Renee Presence Sensor left the house at + (string) 8:29 P.M. >> (string) Renee Presence Sensor left the house at 8:29 P.M.
+392ms ║║Calculating (string) Renee Presence Sensor left the house at 8:29 P.M. + (string) the garage is >> (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is
+396ms ║║Calculating (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is + (string) open >> (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open
+401ms ║║Calculating (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open + (string) , and it is >> (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open, and it is
+406ms ║║Calculating (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open, and it is + (string) 20.1 >> (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open, and it is 20.1
+410ms ║║Calculating (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open, and it is 20.1 + (string) F outside. >> (string) Renee Presence Sensor left the house at 8:29 P.M. the garage is open, and it is 20.1F outside.
+417ms ║║Executed virtual command [Renee Presence Sensor].sendNotification (2ms)
+419ms ║║Condition #5 evaluated true (264ms)
+421ms ║║Condition group #4 evaluated true (state did not change) (266ms)
+423ms ║║Condition #3 evaluated true (270ms)
+424ms ║║Condition group #2 evaluated true (state did not change) (273ms)
+446ms ║║Comparison (string) is (string) House = false (3ms)
+449ms ║║Condition #20 evaluated false (21ms)
+450ms ║║Condition group #9 evaluated false (state did not change) (22ms)
+465ms ║║Comparison (string) is (string) House = false (2ms)
+468ms ║║Condition #17 evaluated false (13ms)
+469ms ║║Condition group #10 evaluated false (state did not change) (16ms)
+483ms ║║Comparison (string) is (string) House = false (2ms)
+485ms ║║Condition #14 evaluated false (12ms)
+486ms ║║Condition group #11 evaluated false (state did not change) (14ms)
+490ms ║║Cancelling statement #12’s schedules…
+527ms ║║Executed virtual command setLocationMode (32ms)
+535ms ║╚Execution stage complete. (397ms)
+537ms ╚Event processed successfully (537ms)
12/13/2017, 8:28:46 PM +102ms
+1ms ╔Received event [Renee Presence Sensor].currentPlace = with a delay of 77ms
+117ms ║RunTime Analysis CS > 15ms > PS > 53ms > PE > 48ms > CE
+120ms ║Runtime (53258 bytes) successfully initialized in 53ms (v0.2.100.20171211) (118ms)
+121ms ║╔Execution stage started
+135ms ║║Comparison (string) changes_away_from (string) House = true (1ms)
+147ms ║║Comparison (enum) open is (string) open = true (1ms)
+149ms ║║Cancelling statement #6’s schedules…
+182ms ║║Executed physical command [Main Garage Door Switch].on() (30ms)
+183ms ║║Executed [Main Garage Door Switch].on (31ms)
+185ms ║║Executed virtual command [Main Garage Door Switch].wait (0ms)
+186ms ║║Requesting a wake up for Wed, Dec 13 2017 @ 8:29:01 PM CST (in 15.0s)
+189ms ║║Condition #5 evaluated true (52ms)
+189ms ║║Condition group #4 evaluated true (state did not change) (52ms)
+191ms ║║Condition #3 evaluated true (64ms)
+191ms ║║Condition group #2 evaluated true (state did not change) (65ms)
+199ms ║║Comparison (string) is (string) House = false (1ms)
+200ms ║║Condition #20 evaluated false (7ms)
+201ms ║║Condition group #9 evaluated false (state did not change) (8ms)
+210ms ║║Comparison (string) is (string) House = false (1ms)
+211ms ║║Condition #17 evaluated false (8ms)
+212ms ║║Condition group #10 evaluated false (state did not change) (9ms)
+217ms ║║Comparison (string) is (string) House = false (1ms)
+218ms ║║Cancelling condition #14’s schedules…
+219ms ║║Condition #14 evaluated false (5ms)
+220ms ║║Cancelling condition #11’s schedules…
+220ms ║║Condition group #11 evaluated false (state changed) (6ms)
+222ms ║║Cancelling statement #12’s schedules…
+273ms ║║Executed virtual command setLocationMode (49ms)
+277ms ║╚Execution stage complete. (157ms)
+278ms ║Setting up scheduled job for Wed, Dec 13 2017 @ 8:29:01 PM CST (in 14.909s)
+287ms ╚Event processed successfully (287ms)
12/13/2017, 8:28:38 PM +380ms
+1ms ╔Received event [Keith Presence Sensor].currentPlace = with a delay of 65ms
+101ms ║RunTime Analysis CS > 18ms > PS > 41ms > PE > 42ms > CE
+104ms ║Runtime (53264 bytes) successfully initialized in 41ms (v0.2.100.20171211) (102ms)
+105ms ║╔Execution stage started
+118ms ║║Comparison (string) changes_away_from (string) House = true (0ms)
+120ms ║║Cancelling condition #3’s schedules…
+128ms ║║Comparison (enum) open is (string) open = true (1ms)
+130ms ║║Cancelling condition #5’s schedules…
+131ms ║║Cancelling statement #6’s schedules…
+348ms ║║Executed physical command [Main Garage Door Switch].on() (214ms)
+349ms ║║Executed [Main Garage Door Switch].on (215ms)
+352ms ║║Executed virtual command [Main Garage Door Switch].wait (0ms)
+353ms ║║Requesting a wake up for Wed, Dec 13 2017 @ 8:28:53 PM CST (in 15.0s)
+355ms ║║Condition #5 evaluated true (234ms)
+356ms ║║Cancelling condition #4’s schedules…
+357ms ║║Condition group #4 evaluated true (state changed) (235ms)
+358ms ║║Condition #3 evaluated true (247ms)
+358ms ║║Cancelling condition #2’s schedules…
+359ms ║║Condition group #2 evaluated true (state changed) (249ms)
+367ms ║║Comparison (string) is (string) House = false (1ms)
+368ms ║║Cancelling condition #20’s schedules…
+369ms ║║Condition #20 evaluated false (8ms)
+370ms ║║Cancelling condition #9’s schedules…
+371ms ║║Condition group #9 evaluated false (state changed) (9ms)
+375ms ║║Comparison (string) is (string) House = false (1ms)
+376ms ║║Cancelling condition #17’s schedules…
+377ms ║║Condition #17 evaluated false (5ms)
+378ms ║║Cancelling condition #10’s schedules…
+379ms ║║Condition group #10 evaluated false (state changed) (6ms)
+386ms ║║Comparison (string) House is (string) House = true (1ms)
+388ms ║║Cancelling statement #15’s schedules…
+443ms ║║Executed virtual command setLocationMode (53ms)
+444ms ║║Condition #14 evaluated true (64ms)
+445ms ║║Condition group #11 evaluated true (state did not change) (65ms)
+449ms ║╚Execution stage complete. (343ms)
+450ms ║Setting up scheduled job for Wed, Dec 13 2017 @ 8:28:53 PM CST (in 14.904s)
+457ms ╚Event processed successfully (457ms)

Here is the log from arrival:

12/13/2017, 9:16:56 PM +666ms
+1ms ╔Received event [Keith Presence Sensor].currentPlace = House with a delay of 67ms
+113ms ║RunTime Analysis CS > 13ms > PS > 43ms > PE > 56ms > CE
+116ms ║Runtime (53481 bytes) successfully initialized in 43ms (v0.2.100.20171211) (114ms)
+117ms ║╔Execution stage started
+130ms ║║Comparison (string) House changes_away_from (string) House = false (0ms)
+132ms ║║Condition #3 evaluated false (9ms)
+132ms ║║Condition group #2 evaluated false (state did not change) (10ms)
+139ms ║║Comparison (string) House changes_to (string) House = true (1ms)
+141ms ║║Cancelling statement #28’s schedules…
+153ms ║║Calculating (string) Welcome home + (string) Keith Presence Sensor >> (string) Welcome home Keith Presence Sensor
+155ms ║║Calculating (string) Welcome home Keith Presence Sensor + (string) . It is >> (string) Welcome home Keith Presence Sensor. It is
+157ms ║║Calculating (string) Welcome home Keith Presence Sensor. It is + (string) 67 >> (string) Welcome home Keith Presence Sensor. It is 67
+159ms ║║Calculating (string) Welcome home Keith Presence Sensor. It is 67 + (string) F upstairs. >> (string) Welcome home Keith Presence Sensor. It is 67 F upstairs.
+164ms ║║Executed virtual command [Keith Presence Sensor].sendNotification (2ms)
+173ms ║║Comparison (integer) 132 is_less_than_or_equal_to (integer) 1000 = true (1ms)
+175ms ║║Cancelling statement #32’s schedules…
+180ms ║║Skipped execution of physical command [House Entryway Light].on([]) because it would make no change to the device. (2ms)
+181ms ║║Executed [House Entryway Light].on (3ms)
+183ms ║║Executed virtual command [House Entryway Light].wait (1ms)
+184ms ║║Requesting a wake up for Wed, Dec 13 2017 @ 9:21:56 PM CST (in 300.0s)
+186ms ║║Condition #31 evaluated true (20ms)
+187ms ║║Condition group #30 evaluated true (state did not change) (21ms)
+196ms ║║Comparison (enum) closed is (string) closed = true (1ms)
+197ms ║║Cancelling condition #49’s schedules…
+199ms ║║Cancelling statement #50’s schedules…
+224ms ║║Executed physical command [Main Garage Door Switch].on() (23ms)
+225ms ║║Executed [Main Garage Door Switch].on (24ms)
+226ms ║║Condition #49 evaluated true (37ms)
+227ms ║║Cancelling condition #36’s schedules…
+227ms ║║Condition group #36 evaluated true (state changed) (38ms)
+232ms ║║Comparison (string) House is (string) House = true (1ms)
+234ms ║║Cancelling statement #47’s schedules…
+282ms ║║Executed virtual command setLocationMode (46ms)
+284ms ║║Condition #46 evaluated true (54ms)
+284ms ║║Condition group #37 evaluated true (state did not change) (55ms)
+286ms ║║Condition #27 evaluated true (153ms)
+287ms ║║Condition group #26 evaluated true (state did not change) (153ms)
+289ms ║╚Execution stage complete. (173ms)
+290ms ║Setting up scheduled job for Wed, Dec 13 2017 @ 9:21:56 PM CST (in 299.894s)
+300ms ╚Event processed successfully (300ms)
12/13/2017, 9:15:34 PM +466ms
+0ms ╔Received event [Renee Presence Sensor].currentPlace = House with a delay of 52ms
+96ms ║RunTime Analysis CS > 16ms > PS > 32ms > PE > 49ms > CE
+99ms ║Runtime (53260 bytes) successfully initialized in 32ms (v0.2.100.20171211) (98ms)
+100ms ║╔Execution stage started
+112ms ║║Comparison (string) House changes_away_from (string) House = false (0ms)
+114ms ║║Cancelling condition #3’s schedules…
+114ms ║║Condition #3 evaluated false (9ms)
+115ms ║║Cancelling condition #2’s schedules…
+116ms ║║Condition group #2 evaluated false (state changed) (10ms)
+122ms ║║Comparison (string) House changes_to (string) House = true (0ms)
+123ms ║║Cancelling condition #27’s schedules…
+125ms ║║Cancelling statement #28’s schedules…
+218ms ║║Calculating (string) Welcome home + (string) Renee Presence Sensor >> (string) Welcome home Renee Presence Sensor
+220ms ║║Calculating (string) Welcome home Renee Presence Sensor + (string) . It is >> (string) Welcome home Renee Presence Sensor. It is
+222ms ║║Calculating (string) Welcome home Renee Presence Sensor. It is + (string) 67 >> (string) Welcome home Renee Presence Sensor. It is 67
+224ms ║║Calculating (string) Welcome home Renee Presence Sensor. It is 67 + (string) F upstairs. >> (string) Welcome home Renee Presence Sensor. It is 67 F upstairs.
+228ms ║║Executed virtual command [Renee Presence Sensor].sendNotification (2ms)
+236ms ║║Comparison (integer) 132 is_less_than_or_equal_to (integer) 1000 = true (1ms)
+238ms ║║Cancelling statement #32’s schedules…
+247ms ║║Executed physical command [House Entryway Light].on() (7ms)
+248ms ║║Executed [House Entryway Light].on (8ms)
+250ms ║║Executed virtual command [House Entryway Light].wait (0ms)
+251ms ║║Requesting a wake up for Wed, Dec 13 2017 @ 9:20:34 PM CST (in 300.0s)
+254ms ║║Condition #31 evaluated true (24ms)
+254ms ║║Condition group #30 evaluated true (state did not change) (24ms)
+263ms ║║Comparison (enum) open is (string) closed = false (1ms)
+264ms ║║Cancelling condition #49’s schedules…
+264ms ║║Condition #49 evaluated false (8ms)
+265ms ║║Cancelling condition #36’s schedules…
+266ms ║║Condition group #36 evaluated false (state changed) (10ms)
+267ms ║║Condition #27 evaluated true (151ms)
+268ms ║║Cancelling condition #26’s schedules…
+268ms ║║Condition group #26 evaluated true (state changed) (152ms)
+271ms ║╚Execution stage complete. (171ms)
+272ms ║Setting up scheduled job for Wed, Dec 13 2017 @ 9:20:34 PM CST (in 299.981s)
+386ms ╚Event processed successfully (387ms)


#22

There are a lot of extra layers in that, especially with the “if true” statements following an IF. I can’t see enough of it to edit on my phone, I can look at it more closely in about 8 hours when work is done.

Can you try the one sample I gave above (not mine, the one based on your piston) and see if that works? If you could provide the full log I can help troubleshoot any issues that arise, or add additional features to it.


#23

Ok, I made another version and think I have everything in your example.

I will have to attach logs later, it’s getting late here.

I still think that I am going to have issues with messages going to both people if we leave at the same time, but in different vehicles (going to work at the same time).


#24

I am really interested in this piston as I am working on something similar with having notification when one person arrives as well as multiple people. I have been taken the example here and am trying to tweak to fit my situation. The one thing that I am wondering about your piston is that you change Location Modes for each person. Why not have a Location Mode for all people. For example, the house is in Home mode when everyone is home or Away mode when everyone has left. Therefore, if one person leaves the house then the house would still be in Home mode. That way when you both leave the house would then go into Away mode and you would both get a notification.


#25

That looks like it should get you close! Since the entire piston is running asynchronous, I’d expect it to message both of you if you left at the same time. If it doesn’t, we’ll figure out from the logs why not and come up with a way to fix it.


#26

I had already saw you were working on something similar :grin: I also started with a piston that @jrfarrar created that supported multiple arrival sensors.

Initially, I only wanted modify that to a location based piston that I could tweak for different locations (house and cabin). It was sort of working on departure, but didn’t work on arrival. I also wanted to perform different actions on arrival vs departure i.e. close garage door upon leaving and turn on lights when people came home.

Maybe I tried to get too much into one piston? i.e. separating arrivals/departures.

The reason I wanted the different location states was because there are extended times when either of us are home. I tend to leave more lights off. I am also using @bangali rooms manager so for example, I wouldn’t necessarily turn my laundry room light or kitchen light on if only I was home, where my gf likes the extra light. Rather than repeating the logic to determine who is home in every other piston, I wanted to get it in a single arrival/departure piston. Hope that explains my reasoning.

I will test this new piston and attach the logs. I still think that I will still have issues with arrival/departure especially with the garage door because our presence sensors arrive at, “Locations”, at different time. Typically within 30 seconds. One more twist, is that I live in MN and it is pretty cold here in the winter. I didn’t want to build in a 1-2 minute delay on closing the door just to accommodate this or I would let all the heat out of the garage.


#27

I feel you there! I live in Ontario Canada and we are at -12 this morn with a wind chill of -26! BRRR!


#28

So here is what is working and what is not working. It is close :smile:

The location modes work great so far.
The garage door closes just fine.

No devices are getting messages though.

How would/should I handle arrivals? Can it ba added onto this piston, or should it be its own?


#29

I didn’t get the logs, but I made some changes to the notifications. It seemed to make sense if one person is home, the other should get the message unless we are both gone. What do you think?

If I get the desired messages, I can remove the original message to the currentEventDevice, that isn’t working right now anyway.


#30

I’ll take a look at this in a little bit. I think the current event device as a target is what might be failing… I’m not certain how sending a message to a presence sensor is handled by webcore. That’s why I wanted to see the logs.

Either way, what you’re saying about the messaging makes sense. We’ll get it to work.


#31

Sorry in the delay, I was on vacation in Cabo for a long time :smile:

Here is the latest version. The status changes work on departure, I just need some help getting them to change back on arrival (location changes to, “Home”)


#32

Nice, hope you enjoyed that trip!

What exactly are you wanting to happen on arrival? Should be easy to add in with the statements you already have.


#33

Basically the exact opposite of what happens when people leave.

Upon presence sensors locations changing to a location, in this case “house”. I assumed with the, location changes to?

GF home
Me home
Both Home


#34

The easiest would be to create a new IF statement by clicking the “add new statement” option that will appear where the red box is when editing (so it’s outside your IF statement for departures):

IF Any of Keith’s or Renee’s presence changes to home
Then
IF All of Keith’s and Renee’s presence are Home (no change triggers here - the piston was already triggered so just checking state)
Then Both Home
Else
If
Renee’s presence is home, then Renee Home
Else
Keith Home


#35

Think this will work?


#36

You’re getting there! That should work the way it’s written, I think. One change I would make is illustrated below.

Since you’re whole block is conditioned on “someone changes to home”, you know at least one person needs to be there. The first IF/Then works if it’s both of you, the second result is only Keith… if neither of those are true then the only option left is Renee is home. So I’d only have ELSE Set mode to Renee Home and push message…

Make sense?


#37

I think so.

Is this what you meant?


#38

Yup, I think that should work! Let me know if you have any issues and we’ll clean it up… but you should be done or close to it!