Advance Piston not working as intended


#1

1) Give a description of the problem
When my Wife leaves the house, I get a notification as well.

2) What is the expected behavior?
When my wife leaves or comes home (John Doe 1, Presence Sensor 3) she should get a random message. right now we both get them for some reason?

3) What is happening/not happening?
See Question 2

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
11/28/2017, 3:47:10 PM +885ms +1ms ╔Received event [Kaitlyn].presence = present with a delay of 93ms +108ms ║RunTime Analysis CS > 12ms > PS > 42ms > PE > 55ms > CE +118ms ║Runtime (63673 bytes) successfully initialized in 42ms (v0.2.0fe.20171109) (117ms) +119ms ║╔Execution stage started +161ms ║║Comparison (time) 56831010 is_between (time) 18000000 .. (time) 1511870820000 = false (7ms) +162ms ║║Condition #2 evaluated false (37ms) +163ms ║║Condition group #1 evaluated false (state did not change) (38ms) +177ms ║║Comparison (time) 56831051 is_between (time) 1511870820000 .. (time) 1511905500000 = true (8ms) +178ms ║║Time restriction check passed +179ms ║║Condition #12 evaluated true (13ms) +180ms ║║Condition group #11 evaluated true (state did not change) (15ms) +189ms ║║Comparison (enum) present is (string) present = true (1ms) +191ms ║║Condition #17 evaluated true (8ms) +191ms ║║Condition group #13 evaluated true (state did not change) (9ms) +193ms ║║Cancelling statement #18's schedules... +203ms ║║Executed virtual command setAlarmSystemStatus (7ms) +230ms ║║Executed virtual command setLocationMode (24ms) +244ms ║║Comparison (time) 56831119 is_between (time) 1511905500000 .. (time) 73800000 = false (8ms) +245ms ║║Condition #80 evaluated false (12ms) +246ms ║║Condition group #69 evaluated false (state did not change) (13ms) +257ms ║║Comparison (time) 56831134 is_between (time) 73800000 .. (time) 82800000 = false (6ms) +259ms ║║Condition #22 evaluated false (9ms) +259ms ║║Condition group #21 evaluated false (state did not change) (11ms) +270ms ║║Comparison (time) 56831147 is_between (time) 82800000 .. (time) 18000000 = false (6ms) +272ms ║║Condition #32 evaluated false (10ms) +273ms ║║Condition group #31 evaluated false (state did not change) (10ms) +275ms ║║Cancelling statement #63's schedules... +281ms ║║Calculating (string) Home - Day + (string) was initiated on >> (string) Home - Day was initiated on +283ms ║║Calculating (string) Home - Day was initiated on + (string) Tue, Nov 28 2017 @ 3:47:11 PM EST >> (string) Home - Day was initiated on Tue, Nov 28 2017 @ 3:47:11 PM EST +286ms ║║Executed virtual command setState (1ms) +294ms ║║Condition #95 evaluated false (6ms) +295ms ║║Condition group #90 evaluated false (state did not change) (6ms) +297ms ║║Cancelling statement #91's schedules... +312ms ║║Executed virtual command sendNotificationToContacts (7ms) +318ms ║║Comparison (enum) present changes_to (string) not present = false (1ms) +319ms ║║Cancelling condition #101's schedules... +320ms ║║Condition #101 evaluated false (5ms) +321ms ║║Cancelling condition #96's schedules... +321ms ║║Condition group #96 evaluated false (state changed) (7ms) +323ms ║║Cancelling statement #97's schedules... +338ms ║║Executed virtual command sendNotificationToContacts (6ms) +340ms ║╚Execution stage complete. (221ms) +348ms ╚Event processed successfully (348ms) 11/28/2017, 3:42:35 PM +509ms +1ms ╔Received event [Kaitlyn].presence = not present with a delay of 83ms +424ms ╚Event processed successfully (424ms) 11/28/2017, 2:18:08 PM +718ms +1ms ╔Starting piston... (v0.2.0fe.20171109) +309ms ║Subscribing to Chris.presence... +319ms ║Subscribing to Kaitlyn.presence... +780ms ╚Piston successfully started (779ms) 11/28/2017, 2:06:24 PM +896ms +0ms ╔Received event [Home].test = 1511895984892 with a delay of 4ms +620ms ╚Event processed successfully (619ms) 11/28/2017, 2:06:14 PM +97ms +0ms ╔Starting piston... (v0.2.0fe.20171109) +236ms ║Subscribing to Chris.presence... +244ms ║Subscribing to Kaitlyn.presence... +798ms ╚Piston successfully started (798ms) 10/26/2017, 10:51:03 PM +445ms +170ms ╔Stopping piston... +255ms ╚Piston successfully stopped (86ms) 10/26/2017, 10:50:28 PM +955ms +1ms ╔Starting piston... (v0.2.0fa.20171011) +392ms ║Subscribing to Chris.presence... +404ms ║Subscribing to Kaitlyn.presence... +973ms ╚Piston successfully started (972ms) 10/26/2017, 10:48:54 PM +484ms +1ms ╔Starting piston... (v0.2.0fa.20171011) +239ms ║Subscribing to Chris.presence... +252ms ║Subscribing to Kaitlyn.presence... +654ms ╚Piston successfully started (654ms) 10/26/2017, 10:48:30 PM +755ms +0ms ╔Starting piston... (v0.2.0fa.20171011) +256ms ║Subscribing to Chris.presence... +266ms ║Subscribing to Kaitlyn.presence... +679ms ╚Piston successfully started (679ms) 10/26/2017, 10:44:58 PM +406ms +1ms ╔Received event [Home].test = 1509072298401 with a delay of 5ms +463ms ╚Event processed successfully (463ms) 10/26/2017, 10:44:52 PM +957ms +1ms ╔Starting piston... (v0.2.0fa.20171011) +220ms ║Subscribing to Chris.presence... +228ms ║Subscribing to Kaitlyn.presence... +1303ms ╚Piston successfully started (1303ms)


Setting modes based on time of day and presence
#2

For a start and to make life a lot easier , put the messages in a completely separate piston as time triggers will also be triggering your messages (the whole piston is evaluated on every run so the messages in the ‘else’ sections will fire).

You are getting messages to everyone because when person 1 changes to present, person 2 is showing as not changed. Therefore person 1 will get the arrived message and person 2 will get the departed message.

Try using ‘on event’ to isolate the different people (on events do not run with the rest of the piston and live in their own little worlds)

On events from person 1 motion
If person 1 IS present
then
send arrival message
else
send depart message

On events from person 2 motion
If person 2 IS present
then
send arrival message
ese
send depart message


#3

@Robin Does this new Piston look correct?


#4

Maybe… hard to tell without testing…

Suggest you setup a couple of simulated presence sensors to save you having to test physically.

If you use the ‘on event’ function and IS it separates things and may work better.


#5

@Robin

Not sure what you mean by ‘on event’ and IS, can you elaborate or provide an example?


#6

‘On event’ is an advanced trigger option… click options and then ‘show advanced statements’.

Now when you click ‘add a statement’ you get loads more choices, including ‘on event’


#7

Gotcha, Thank you for the assistance.

On a side note my wife got home today and Smartthings picked up that she was present but the house didn’t switch from Away - Day to Home - Day for some reason. Not sure why though, any ideas?

Here is the latest log, she got home at 13:58
’11/29/2017, 1:58:10 PM +565ms
+1ms ╔Received event [Kaitlyn].presence = present with a delay of 102ms
+169ms ║RunTime Analysis CS > 22ms > PS > 36ms > PE > 112ms > CE
+182ms ║Runtime (54179 bytes) successfully initialized in 36ms (v0.2.0fe.20171109) (181ms)
+183ms ║╔Execution stage started
+242ms ║║Comparison (time) 50290754 is_between (time) 18000000 … (time) 1511957280000 = false (7ms)
+243ms ║║Condition #2 evaluated false (54ms)
+244ms ║║Cancelling statement #2’s schedules…
+251ms ║║Requesting time schedule wake up at Thu, Nov 30 2017 @ 5:00:00 AM EST
+253ms ║║Condition group #1 evaluated false (state did not change) (64ms)
+269ms ║║Comparison (time) 50290822 is_between (time) 1511957280000 … (time) 1511991840000 = true (9ms)
+270ms ║║Time restriction check passed
+272ms ║║Condition #12 evaluated true (15ms)
+273ms ║║Cancelling statement #12’s schedules…
+281ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 4:44:00 PM EST
+283ms ║║Condition group #11 evaluated true (state did not change) (27ms)
+293ms ║║Comparison (enum) not present is (string) present = false (2ms)
+295ms ║║Comparison (enum) present is (string) present = true (1ms)
+297ms ║║Cancelling condition #17’s schedules…
+298ms ║║Condition #17 evaluated true (13ms)
+299ms ║║Cancelling condition #13’s schedules…
+300ms ║║Condition group #13 evaluated true (state changed) (14ms)
+302ms ║║Cancelling statement #18’s schedules…
+314ms ║║Executed virtual command setAlarmSystemStatus (10ms)
+357ms ║║Executed virtual command setLocationMode (40ms)
+372ms ║║Comparison (time) 50290926 is_between (time) 1511991840000 … (time) 73800000 = false (8ms)
+374ms ║║Condition #80 evaluated false (12ms)
+375ms ║║Cancelling statement #80’s schedules…
+381ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 4:44:00 PM EST
+384ms ║║Condition group #69 evaluated false (state did not change) (23ms)
+396ms ║║Comparison (time) 50290952 is_between (time) 73800000 … (time) 82800000 = false (7ms)
+397ms ║║Condition #22 evaluated false (10ms)
+399ms ║║Cancelling statement #22’s schedules…
+403ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 8:30:00 PM EST
+405ms ║║Condition group #21 evaluated false (state did not change) (19ms)
+417ms ║║Comparison (time) 50290974 is_between (time) 82800000 … (time) 18000000 = false (7ms)
+419ms ║║Condition #32 evaluated false (11ms)
+420ms ║║Cancelling statement #32’s schedules…
+425ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 11:00:00 PM EST
+428ms ║║Condition group #31 evaluated false (state did not change) (19ms)
+431ms ║║Cancelling statement #63’s schedules…
+437ms ║║Calculating (string) Home + (string) was initiated on >> (string) Home was initiated on
+440ms ║║Calculating (string) Home was initiated on + (string) Wed, Nov 29 2017 @ 1:58:10 PM EST >> (string) Home was initiated on Wed, Nov 29 2017 @ 1:58:10 PM EST
+442ms ║║Executed virtual command setState (0ms)
+449ms ║╚Execution stage complete. (266ms)
+453ms ║Setting up scheduled job for Wed, Nov 29 2017 @ 4:44:00 PM EST (in 9948.983s), with 4 more jobs pending
+470ms ╚Event processed successfully (471ms)
11/29/2017, 1:57:11 PM +349ms
+1ms ╔Received event [Home].test = 1511981831342 with a delay of 7ms
+159ms ║RunTime Analysis CS > 13ms > PS > 30ms > PE > 116ms > CE
+171ms ║Runtime (54176 bytes) successfully initialized in 30ms (v0.2.0fe.20171109) (169ms)
+172ms ║╔Execution stage started
+228ms ║║Comparison (time) 50231527 is_between (time) 18000000 … (time) 1511957280000 = false (9ms)
+229ms ║║Condition #2 evaluated false (51ms)
+230ms ║║Cancelling statement #2’s schedules…
+241ms ║║Requesting time schedule wake up at Thu, Nov 30 2017 @ 5:00:00 AM EST
+244ms ║║Condition group #1 evaluated false (state did not change) (66ms)
+258ms ║║Comparison (time) 50231595 is_between (time) 1511957280000 … (time) 1511991840000 = true (8ms)
+259ms ║║Time restriction check passed
+261ms ║║Condition #12 evaluated true (14ms)
+263ms ║║Cancelling statement #12’s schedules…
+271ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 4:44:00 PM EST
+274ms ║║Condition group #11 evaluated true (state did not change) (28ms)
+285ms ║║Comparison (enum) not present is (string) present = false (1ms)
+288ms ║║Comparison (enum) not present is (string) present = false (1ms)
+289ms ║║Condition #17 evaluated false (13ms)
+290ms ║║Condition group #13 evaluated false (state did not change) (14ms)
+304ms ║║Comparison (enum) not present is (string) not present = true (2ms)
+306ms ║║Comparison (enum) not present is (string) not present = true (2ms)
+308ms ║║Comparison (enum) not present is (string) not present = true (1ms)
+310ms ║║Condition #85 evaluated true (17ms)
+310ms ║║Condition group #14 evaluated true (state did not change) (18ms)
+311ms ║║Cancelling statement #14’s schedules…
+334ms ║║Executed virtual command [Bathroom Fan, Bathroom Heat, Bathroom Light, Bedroom Light, Bedroom Light 2, Bedroom Scentsy, Dining Room Light, Flood Lights, Hallway Light, Kitchen Lights, Living Room Lights, Living Room Scentsy, Mud Room Light, Nursery Lamp, Nursery Light, TV Lightstrip].wait (4ms)
+336ms ║║Requesting a wake up for Wed, Nov 29 2017 @ 2:02:11 PM EST (in 300.0s)
+354ms ║╚Execution stage complete. (182ms)
+359ms ║Setting up scheduled job for Wed, Nov 29 2017 @ 2:02:11 PM EST (in 299.982s), with 5 more jobs pending
+374ms ╚Event processed successfully (374ms)
11/29/2017, 7:12:58 AM +140ms
+0ms ╔Received event [Home].time = 1511957579873 with a delay of -1734ms
+173ms ║RunTime Analysis CS > 25ms > PS > 31ms > PE > 117ms > CE
+185ms ║Runtime (54165 bytes) successfully initialized in 31ms (v0.2.0fe.20171109) (183ms)
+186ms ║╔Execution stage started
+281ms ║║Executed virtual command [Bathroom Fan, Bathroom Heat, Bathroom Light, Bedroom Light, Bedroom Light 2, Bedroom Scentsy, Dining Room Light, Flood Lights, Hallway Light, Kitchen Lights, Living Room Lights, Living Room Scentsy, Mud Room Light, Nursery Lamp, Nursery Light, TV Lightstrip].setAlarmSystemStatus (43ms)
+334ms ║║Executed virtual command [Bathroom Fan, Bathroom Heat, Bathroom Light, Bedroom Light, Bedroom Light 2, Bedroom Scentsy, Dining Room Light, Flood Lights, Hallway Light, Kitchen Lights, Living Room Lights, Living Room Scentsy, Mud Room Light, Nursery Lamp, Nursery Light, TV Lightstrip].setLocationMode (51ms)
+339ms ║║Skipped execution of physical command [Bathroom Fan].off([]) because it would make no change to the device. (3ms)
+340ms ║║Executed [Bathroom Fan].off (5ms)
+459ms ║║Executed physical command [Bathroom Heat].off() (116ms)
+460ms ║║Executed [Bathroom Heat].off (118ms)
+466ms ║║Skipped execution of physical command [Bathroom Light].off([]) because it would make no change to the device. (3ms)
+466ms ║║Executed [Bathroom Light].off (5ms)
+477ms ║║Executed physical command [Bedroom Light].off() (9ms)
+478ms ║║Executed [Bedroom Light].off (9ms)
+487ms ║║Executed physical command [Bedroom Light 2].off() (7ms)
+488ms ║║Executed [Bedroom Light 2].off (9ms)
+493ms ║║Skipped execution of physical command [Bedroom Scentsy].off([]) because it would make no change to the device. (3ms)
+494ms ║║Executed [Bedroom Scentsy].off (4ms)
+498ms ║║Skipped execution of physical command [Dining Room Light].off([]) because it would make no change to the device. (2ms)
+499ms ║║Executed [Dining Room Light].off (4ms)
+505ms ║║Skipped execution of physical command [Flood Lights].off([]) because it would make no change to the device. (3ms)
+506ms ║║Executed [Flood Lights].off (5ms)
+511ms ║║Skipped execution of physical command [Hallway Light].off([]) because it would make no change to the device. (3ms)
+512ms ║║Executed [Hallway Light].off (5ms)
+530ms ║║Executed physical command [Kitchen Lights].off() (15ms)
+530ms ║║Executed [Kitchen Lights].off (16ms)
+535ms ║║Skipped execution of physical command [Living Room Lights].off([]) because it would make no change to the device. (3ms)
+536ms ║║Executed [Living Room Lights].off (4ms)
+541ms ║║Skipped execution of physical command [Living Room Scentsy].off([]) because it would make no change to the device. (2ms)
+541ms ║║Executed [Living Room Scentsy].off (4ms)
+546ms ║║Skipped execution of physical command [Mud Room Light].off([]) because it would make no change to the device. (3ms)
+547ms ║║Executed [Mud Room Light].off (5ms)
+551ms ║║Skipped execution of physical command [Nursery Lamp].off([]) because it would make no change to the device. (2ms)
+552ms ║║Executed [Nursery Lamp].off (4ms)
+557ms ║║Skipped execution of physical command [Nursery Light].off([]) because it would make no change to the device. (3ms)
+558ms ║║Executed [Nursery Light].off (5ms)
+563ms ║║Skipped execution of physical command [TV Lightstrip].off([]) because it would make no change to the device. (2ms)
+564ms ║║Executed [TV Lightstrip].off (4ms)
+622ms ║║Comparison (time) 25978708 is_between (time) 1511991840000 … (time) 73800000 = false (10ms)
+624ms ║║Condition #80 evaluated false (56ms)
+625ms ║║Cancelling statement #80’s schedules…
+633ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 4:44:00 PM EST
+635ms ║║Condition group #69 evaluated false (state did not change) (68ms)
+648ms ║║Comparison (time) 25978779 is_between (time) 73800000 … (time) 82800000 = false (7ms)
+649ms ║║Condition #22 evaluated false (11ms)
+651ms ║║Cancelling statement #22’s schedules…
+655ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 8:30:00 PM EST
+658ms ║║Condition group #21 evaluated false (state did not change) (19ms)
+670ms ║║Comparison (time) 25978801 is_between (time) 82800000 … (time) 18000000 = false (7ms)
+672ms ║║Condition #32 evaluated false (10ms)
+673ms ║║Cancelling statement #32’s schedules…
+678ms ║║Requesting time schedule wake up at Wed, Nov 29 2017 @ 11:00:00 PM EST
+680ms ║║Condition group #31 evaluated false (state did not change) (20ms)
+683ms ║║Cancelling statement #63’s schedules…
+689ms ║║Calculating (string) Home - Dawn + (string) was initiated on >> (string) Home - Dawn was initiated on
+692ms ║║Calculating (string) Home - Dawn was initiated on + (string) Wed, Nov 29 2017 @ 7:12:58 AM EST >> (string) Home - Dawn was initiated on Wed, Nov 29 2017 @ 7:12:58 AM EST
+695ms ║║Executed virtual command setState (1ms)
+701ms ║╚Execution stage complete. (516ms)
+705ms ║Setting up scheduled job for Wed, Nov 29 2017 @ 4:44:00 PM EST (in 34261.156s), with 4 more jobs pending
+723ms ╚Event processed successfully (722ms)


#8

It’s being reported on the ST forum that modes are not reporting / changing properly, even with native apps like routines and smart lighting… haven’t seen issues myself but might be that.


#9

Also, can you post your latest piston (green snapshot) as the version you posted at the top of this thread does not appear to be subscribing to the presence events whereas the logs look like it is.


#10

@Robin Here is the latest version of the Piston.


#11

Youre not subscribing to the presence sensors properly… anyway, your piston could be wayyyyyyy more efficient, I’ll knock something up.


#12

@Robin that would be great, I pulled the Piston I have now from the Advance Samples page on the wiki and I always thought it seemed a bit complicated.


#13

Try this (untested but should be good):

In addition to when presence toggles between any present and all away, the timers at the bottom will trigger the piston at the various times to move the mode along when presence hasn’t changed.

Edit, this only fires for presence change, not time. Fixed and more condensed piston in my next post.


#14

@Robin Thank you! I will test this when I get home from work this evening and let you know how it works out.


#15

Because I like a good challenge… here’s the same thing simplified even further :smile: :

Also, the example I showed in post 13 doesn’t fully work, ‘every day’ does not fire the whole piston, only what’s within that statement, whereas ‘time happens daily’ does fire the rest of the piston (which is what is needed).

So this example is subscribed to presence changes AND the 5 different times of day.


#16

@Robin So I was trying to use your latest example but it is asking me for custom modes, didn’t know what it wanted so hit cancel and now not sure where to enter those values at? I also evaluate the “timeOfDayHome” variable and it is returning sleep at 8:30PM which isn’t correct, it should be “Home - Night”

Also I noticed that when in sleep mode it doesn’t currently set SHM to Armed/Stay like my original piston did, I’m sure that is an easy fix though :slight_smile:

Latest update: Home - Night evaluated true at 10:26pm. Get up at 6:10AM this morning and mode is still on Sleep. Seems the time is off in the string variable somehow?


#17

I’ll take a look, appears I didn’t test it as thoroughly as I maybe should have.


#18

It appears the 20s delays I put in the timers wasn’t enough (needed to be over 1 minute)… $time24 is formatted as hh:mm whereas the specific times and presets are hh:mm:ss.

The 20 seconds past 5am trigger tests the ternary operator as follows: 05:00 (should be 05:00:20) <= 05:00:00 (should return false), with the missing ss on the left the ss on the right gets ignored, so its testing 05:00 <= 05:00 and incorrectly returns true which in turn returns the wrong mode.

Anyway, I’ve changed the logical operator to < (less than) which should solve the problem.

In regards to the import wizard asking you to select ‘custom modes’… just hit cancel, then go into lines 37 and 44 and select the variables ‘timeOfDayHome’ and ‘timeOfDayAway’ respectively, as shown in the screenshot.


#19

@Robin Thanks for the quick responce, the only remaining issue I have with this Piston is it isn’t setting the SHM mode to Arm/STAY when sleep time arrives. Any chance that is a quick fix/add?


#20

This should work:

Instead of set SHM to value Disarmed I used the following expression:

(timeOfDayHome == ‘Sleep’ ? ‘Armed/Stay’ : ‘Disarmed’)

This is the same as:

IF timeOfDayHome IS Sleep
THEN
Set SHM to Armed/Stay
Else
Set SHM to Disarmed