Arrival/departure if/then or case statement?


#41

So how can I build a delay in my piston?

I think I had a start on it with setting a variable (which I am currently not using).

if( ([Renee Presence Sensor : currentPlace] == ‘Home’) && (age([Renee Presence Sensor : currentPlace])/60000 < 5) , 1, 0)

and

if( ([Keith Presence Sensor : currentPlace] == ‘Home’) && (age([Keith Presence Sensor : currentPlace])/60000 < 5) , 2, 0)

I just am not sure of the formatting etc.


#42

Without writing it in an expression box to verify, that looks like it should work.

What is your piston doing (or has done) that you’re trying to build in a delay to fix? If I understand the problem there might be a different way to approach it.


#43

So watching the logs and reading in the webCoRE application, the GPS accuracy may go to 100-150 meters. Since the roads I drive on are within that 100-150 meters, my current location changes momentarily from NULL to House. Looking at my ST logs, this is typically 10-20 seconds. It sounds like there is no way to ignore those updates, so it looks like I need to build some sort of delay in the piston to accommodate this.

Something like, don’t recognize the currentPlace = house unless it stays that way for say 15 seconds. I could then experiment with the delay so that I am not getting false piston execution.


#44

Gotcha! In that case, you should be able to save yourself some complex conditions and use a trigger that says:


#45

If the above results in repeating triggers (it shouldn’t, but I suppose it’s possible) then this statement would eliminate it:

image


#46

I saw the, “stays,” trigger.

I suppose I could play with the settings and try to sort of filter out my false alarms.

I still wish there was a way in the webCoRE app to set your accuracy filters.


#47

So something like this?


#48

I’d try that for a bit and see if it works. Your arrives and stays home condition would be beaten to the punch for a few activities (setting lights and home/away modes) because your first block of code would have set it already.

There are some redundant conditions in there now - if I get some time this evening I’ll see if I can confirm they’re redundant and clean it up a little bit. Need a little more time to look at it and I’m ready to get out of the office!


#49

So I think I got it to ignore the false arrivals.

Can you explain what the below examples mean?

Does the, “within,” look back that value (green)? Say 10 seconds. Then look to see if it, “stayed away from,” my value house for 10 minutes?

Also, do you know what Loose, Strict and Negated do?


#50

The green “within” box defines the timer for the 2nd condition to become true after the first condition is evaluated.

For example, if we had:

IF
Garage door opens
Followed within 1 minute by
Kitchen door opens

Then
Close garage door
Turn garage lights off
etc.

The within 1 minute would be set in the green box you’re pointing at.

For the matching methods, I have some guesses but I’m afraid that’s all they would be. Probably better to get one of the minions to chime in on that one. Since @bangali was in this thread earlier, hopefully he won’t mind me tagging him back in. :slight_smile:


#51

at its root webcore is about event processing. each of those if conditions are checking the current event for a match. here that group of if condition is looking for a match between 2 events one followed by another.

suppose the event sequence received by that piston is as following:

  1. presence event from keiths phone
  2. motion event from hallway motion sensor
  3. presence event from renees phone

(somehow those names seem familiar … i vaguely remember some piston and that if condition … anyways …)

when you set the matching method to:

  • loose = the motion event is ignored so when processing event #3 if condition will evaluate as true
  • strict = the condition is reset when a non-matching event #2 is processed. so when processing event #3 that will become the first matching event for the condition and since there is no following presence event the if will evaluate as false
  • negated = this evaluates as true when following event #1 event #3 is not recieved within 10 seconds

for more fun tag me on a thread when i have never been in it :wink:


#52

Thanks for the info. Here is what I am trying to accomplish.

I am having issues with the webCoRE presence sensor (assuming the GPS accuracy is higher then 50-100m). In my picture above, what I am seeing is that my currentPlace is momentarily changing to, “House,” for about 10 seconds when I drive past my geofence. What I am trying to accomplish is, don’t trigger the arrival/departure statements unless my currentPlace changes to, “House,” and stays that way for at least 10 seconds. I can adjust the 10 seconds if I am seeing it is not long enough.

Would this be written in the following way?

IF
Any of the presence sensors currentPlace changes to "House"
followed (Strict, Loose or Negated?) within 10 minutes by
Any of the presence sensors currentPlace stays “House” for 10 seconds

If I literally read that it looks like we are looking back 10 minutes to see if any of the presence sensors currentPlace has stayed, “House,” for 10 seconds.


#53

I think the way wecCoRE’s ‘stay’ works, you can reduce the number of statements to one. WebCoRE seems to subscribe to events for stay, so it will automatically trigger the piston on state change (negating the need for ‘if currentplace changes to house’).

Try just using:
IF presence sensor currentPlace stays House for 10 seconds.

The only problem I can see with the Stay clause, is now you could start seeing duplicate notifications. For example, if Renee was home, and then you came home an hour later - Renee also would have “stayed” home for 10 seconds.

You might need to add in a “has not changed in the last XX seconds” condition to work around that.


#54

I assume this is what you meant.

Changing the, "changes to, “House”, to stays, “House,” for 10 seconds.


#55

Yep, that was it! Hopefully that filters our your false arrivals.


#56

Well, that change broke both the departure and arrivals. I was a good test where we both left at the same time. Typically, my presence will trigger a few seconds before hers will. Maybe you can see what is happening from the logs?

Arrival logs:

1/4/2018, 7:57:05 PM +319ms
+0ms ╔Received event [Home].time = 1515117426781 with a delay of -1463ms
+227ms ║RunTime Analysis CS > 62ms > PS > 59ms > PE > 107ms > CE
+262ms ║Runtime (58080 bytes) successfully initialized in 59ms (v0.2.101.20171227) (261ms)
+263ms ║╔Execution stage started
+267ms ║║Cancelling condition #2’s schedules…
+294ms ║║Fast executing schedules, waiting for 1170ms to sync up
+1543ms ║╚Execution stage complete. (1280ms)
+1545ms ╚Event processed successfully (1545ms)
1/4/2018, 7:56:56 PM +603ms
+1ms ╔Received event [Renee Presence Sensor].currentPlace = House with a delay of 115ms
+145ms ║RunTime Analysis CS > 12ms > PS > 39ms > PE > 94ms > CE
+151ms ║Runtime (58087 bytes) successfully initialized in 39ms (v0.2.101.20171227) (148ms)
+151ms ║╔Execution stage started
+165ms ║║Comparison (string) House stays (string) House = true (1ms)
+167ms ║║Comparison (string) House stays (string) House = true (1ms)
+177ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+179ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+181ms ║║Condition #83 evaluated false (24ms)
+181ms ║║Cancelling statement #2’s schedules…
+182ms ║║Cancelling condition #2’s schedules…
+183ms ║║Condition group #2 evaluated false (state changed) (27ms)
+194ms ║║Comparison (string) House stays (string) House = true (1ms)
+195ms ║║Comparison (string) House stays (string) House = true (1ms)
+197ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+199ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+201ms ║║Condition #82 evaluated false (15ms)
+203ms ║╚Execution stage complete. (52ms)
+205ms ║Setting up scheduled job for Thu, Jan 4 2018 @ 7:57:06 PM CST (in 9.974s), with 3 more jobs pending
+215ms ╚Event processed successfully (214ms)
1/4/2018, 7:56:29 PM +831ms
+0ms ╔Received event [Home].time = 1515117390872 with a delay of -1041ms
+177ms ║RunTime Analysis CS > 15ms > PS > 55ms > PE > 107ms > CE
+182ms ║Runtime (58076 bytes) successfully initialized in 55ms (v0.2.101.20171227) (181ms)
+183ms ║╔Execution stage started
+190ms ║║Cancelling condition #2’s schedules…
+234ms ║║Fast executing schedules, waiting for 833ms to sync up
+1113ms ║╚Execution stage complete. (930ms)
+1114ms ╚Event processed successfully (1114ms)
1/4/2018, 7:56:20 PM +626ms
+2ms ╔Received event [Keith Presence Sensor].currentPlace = House with a delay of 130ms
+214ms ║RunTime Analysis CS > 22ms > PS > 79ms > PE > 113ms > CE
+221ms ║Runtime (58085 bytes) successfully initialized in 79ms (v0.2.101.20171227) (218ms)
+223ms ║╔Execution stage started
+242ms ║║Comparison (string) House stays (string) House = true (1ms)
+244ms ║║Comparison (string) stays (string) House = false (1ms)
+246ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+248ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+251ms ║║Cancelling statement #83’s schedules…
+252ms ║║Condition #83 evaluated false (21ms)
+253ms ║║Cancelling statement #2’s schedules…
+254ms ║║Condition group #2 evaluated false (state did not change) (24ms)
+269ms ║║Comparison (string) House stays (string) House = true (1ms)
+270ms ║║Comparison (string) stays (string) House = false (1ms)
+272ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+274ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+274ms ║║Cancelling statement #82’s schedules…
+275ms ║║Condition #82 evaluated false (19ms)
+277ms ║╚Execution stage complete. (55ms)
+279ms ║Setting up scheduled job for Thu, Jan 4 2018 @ 7:56:30 PM CST (in 9.968s), with 1 more job pending
+287ms ╚Event processed successfully (287ms)

Departure logs:

1/4/2018, 6:09:29 PM +351ms
+1ms ╔Received event [Home].time = 1515110970075 with a delay of -724ms
+204ms ║RunTime Analysis CS > 22ms > PS > 55ms > PE > 127ms > CE
+210ms ║Runtime (58070 bytes) successfully initialized in 55ms (v0.2.101.20171227) (208ms)
+211ms ║╔Execution stage started
+212ms ║╚Execution stage complete. (1ms)
+214ms ╚Event processed successfully (213ms)
1/4/2018, 6:09:22 PM +197ms
+1ms ╔Received event [Keith Presence Sensor].currentPlace = with a delay of 124ms
+183ms ║RunTime Analysis CS > 16ms > PS > 62ms > PE > 106ms > CE
+188ms ║Runtime (58085 bytes) successfully initialized in 62ms (v0.2.101.20171227) (187ms)
+189ms ║╔Execution stage started
+206ms ║║Comparison (string) stays (string) House = false (1ms)
+208ms ║║Comparison (string) stays (string) House = false (1ms)
+210ms ║║Cancelling any timed trigger schedules for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+211ms ║║Cancelling statement #83’s schedules…
+211ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+212ms ║║Cancelling statement #83’s schedules…
+213ms ║║Condition #83 evaluated false (17ms)
+213ms ║║Cancelling statement #2’s schedules…
+214ms ║║Condition group #2 evaluated false (state did not change) (20ms)
+224ms ║║Comparison (string) stays (string) House = false (1ms)
+225ms ║║Comparison (string) stays (string) House = false (1ms)
+227ms ║║Cancelling any timed trigger schedules for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+228ms ║║Cancelling statement #82’s schedules…
+228ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+229ms ║║Cancelling statement #82’s schedules…
+230ms ║║Condition #82 evaluated false (13ms)
+232ms ║╚Execution stage complete. (43ms)
+233ms ╚Event processed successfully (234ms)
1/4/2018, 6:09:19 PM +843ms
+1ms ╔Received event [Renee Presence Sensor].currentPlace = with a delay of 75ms
+206ms ║RunTime Analysis CS > 17ms > PS > 66ms > PE > 123ms > CE
+210ms ║Runtime (57929 bytes) successfully initialized in 66ms (v0.2.101.20171227) (209ms)
+211ms ║╔Execution stage started
+228ms ║║Comparison (string) House stays (string) House = true (1ms)
+230ms ║║Comparison (string) stays (string) House = false (1ms)
+232ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+233ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+234ms ║║Cancelling statement #83’s schedules…
+235ms ║║Condition #83 evaluated false (16ms)
+236ms ║║Cancelling statement #2’s schedules…
+236ms ║║Cancelling condition #2’s schedules…
+237ms ║║Condition group #2 evaluated false (state changed) (20ms)
+248ms ║║Comparison (string) House stays (string) House = true (1ms)
+250ms ║║Comparison (string) stays (string) House = false (1ms)
+252ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+254ms ║║Cancelling any timed trigger schedules for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+254ms ║║Cancelling statement #82’s schedules…
+255ms ║║Cancelling condition #82’s schedules…
+256ms ║║Condition #82 evaluated false (16ms)
+258ms ║╚Execution stage complete. (47ms)
+260ms ║Setting up scheduled job for Thu, Jan 4 2018 @ 6:09:30 PM CST (in 9.973s), with 1 more job pending
+278ms ╚Event processed successfully (277ms)

Piston:


#57

Don’t make any changes based on results today. My presence sensor didn’t work today either… and it seems we’re not alone:


#58

I saw the update that everything should be working, but the piston is still not working with the screenshot above. I did turn on debugging in the presence app. Logs below:

Then here are the logs when I left:

1/5/2018, 11:05:16 AM +796ms

+1ms ╔Received event [Home].time = 1515171917258 with a delay of -462ms
+190ms ║RunTime Analysis CS > 21ms > PS > 69ms > PE > 99ms > CE
+197ms ║Runtime (58073 bytes) successfully initialized in 69ms (v0.2.101.20171227) (196ms)
+198ms ║╔Execution stage started
+204ms ║║Cancelling condition #2’s schedules…
+242ms ║║Fast executing schedules, waiting for 239ms to sync up
+527ms ║╚Execution stage complete. (329ms)
+528ms ╚Event processed successfully (528ms)

1/5/2018, 11:05:07 AM +41ms

+2ms ╔Received event [Keith Presence Sensor].currentPlace = with a delay of 272ms
+189ms ║RunTime Analysis CS > 25ms > PS > 56ms > PE > 108ms > CE
+195ms ║Runtime (58089 bytes) successfully initialized in 56ms (v0.2.101.20171227) (193ms)
+196ms ║╔Execution stage started
+212ms ║║Comparison (string) stays (string) House = false (2ms)
+213ms ║║Comparison (string) House stays (string) House = true (1ms)
+215ms ║║Cancelling any timed trigger schedules for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+216ms ║║Cancelling statement #83’s schedules…
+216ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+218ms ║║Condition #83 evaluated false (17ms)
+219ms ║║Cancelling statement #2’s schedules…
+220ms ║║Cancelling condition #2’s schedules…
+220ms ║║Condition group #2 evaluated false (state changed) (19ms)
+231ms ║║Comparison (string) stays (string) House = false (1ms)
+233ms ║║Comparison (string) House stays (string) House = true (0ms)
+234ms ║║Cancelling any timed trigger schedules for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+235ms ║║Cancelling statement #82’s schedules…
+236ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+237ms ║║Condition #82 evaluated false (14ms)
+240ms ║╚Execution stage complete. (43ms)
+241ms ║Setting up scheduled job for Fri, Jan 5 2018 @ 11:05:17 AM CST (in 9.976s), with 1 more job pending
+250ms ╚Event processed successfully (249ms)

And when I arrived:

1/5/2018, 11:48:51 AM +577ms

+1ms ╔Received event [Home].time = 1515174532689 with a delay of -1112ms
+192ms ║RunTime Analysis CS > 17ms > PS > 58ms > PE > 117ms > CE
+198ms ║Runtime (58080 bytes) successfully initialized in 58ms (v0.2.101.20171227) (197ms)
+200ms ║╔Execution stage started
+208ms ║║Cancelling condition #2’s schedules…
+265ms ║║Fast executing schedules, waiting for 848ms to sync up
+1308ms ║╚Execution stage complete. (1109ms)
+1310ms ╚Event processed successfully (1310ms)

1/5/2018, 11:48:42 AM +475ms

+2ms ╔Received event [Keith Presence Sensor].currentPlace = House with a delay of 135ms
+188ms ║RunTime Analysis CS > 24ms > PS > 53ms > PE > 111ms > CE
+194ms ║Runtime (58089 bytes) successfully initialized in 53ms (v0.2.101.20171227) (191ms)
+195ms ║╔Execution stage started
+210ms ║║Comparison (string) House stays (string) House = true (1ms)
+211ms ║║Comparison (string) House stays (string) House = true (1ms)
+213ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 83
+215ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 83
+217ms ║║Condition #83 evaluated false (16ms)
+217ms ║║Cancelling statement #2’s schedules…
+218ms ║║Cancelling condition #2’s schedules…
+219ms ║║Condition group #2 evaluated false (state changed) (18ms)
+227ms ║║Comparison (string) House stays (string) House = true (1ms)
+229ms ║║Comparison (string) House stays (string) House = true (1ms)
+230ms ║║Adding a timed trigger schedule for device :a33e14a1d9fbc2eb5253c7c8cbcc0dc1: for condition 82
+232ms ║║Adding a timed trigger schedule for device :949dab343e304a0ed7093bd8803ae97e: for condition 82
+234ms ║║Condition #82 evaluated false (13ms)
+236ms ║╚Execution stage complete. (41ms)
+238ms ║Setting up scheduled job for Fri, Jan 5 2018 @ 11:48:52 AM CST (in 9.977s), with 3 more jobs pending
+335ms ╚Event processed successfully (334ms)


#59

That’s hard to discern what is happening when it wakes up 10 seconds later.

What about it isn’t working? Presence in SmartThings is right? Presence in webCoRE? Arrival departure messages not triggering?

If we can answer all those we’ll have some direction for what is or isn’t working. it might be helpful to turn on Trace and force it to execute… see what part(s) of the piston are run when you first arrive and when it wakes up 10 seconds later to see if you’re still there. I’d change “on events from presence sensor” to something easy to trigger while you’re at the computer, like a light.


#60

With the new, "currentPlace stays “House”, nothing works. No messages, not status changes.

I have the trace on and ran it. This is the result:

1/5/2018, 3:05:51 PM +43ms
+2ms ╔Received event [Home].test = 1515186351040 with a delay of 2ms
+166ms ║RunTime Analysis CS > 16ms > PS > 35ms > PE > 114ms > CE
+172ms ║Runtime (58074 bytes) successfully initialized in 35ms (v0.2.101.20171227) (169ms)
+176ms ║╔Execution stage started
+181ms ║╚Execution stage complete. (7ms)
+185ms ╚Event processed successfully (185ms)