previousAge maximum value


#1

1) Give a description of the problem
I’m using previousAge of a presence sensor to ignore open triggers if they happen in quick succession. Sometimes it doesn’t work. Is there a maximum value of previousAge after which it resets to 0 and starts counting again?

2) What is the expected behavior?
If the sensor opens then change a virtual presence status.
If it opens again within 20s then do nothing - the door probably went closed / open / closed when swinging shut.

3) What is happening/not happening?
Sometimes when the sensor opens it does not change the status despite it being more than 20s since it last opened. From the logs it looks like the value of previousAge has reset:

Comparison (long) 1365 is_greater_than_or_equal_to (integer) 20000 = false (1ms)

(This entry was around 59 mins after the last time presence sensor opened.

**4) Post a Green Snapshot of the piston

5) Attach any logs (From ST IDE and by turning logging level to Full)

4/30/2018, 2:05:50 AM +87ms
+1ms ╔Received event [Cat Flap].contact = open with a delay of 1169ms
+173ms ║RunTime Analysis CS > 20ms > PS > 42ms > PE > 111ms > CE
+176ms ║Runtime (44963 bytes) successfully initialized in 42ms (v0.3.104.20180323) (174ms)
+177ms ║╔Execution stage started
+184ms ║║Comparison (enum) open changes_to (string) open = true (1ms)
+185ms ║║Cancelling condition #10’s schedules…
+186ms ║║Condition #10 evaluated true (5ms)
+187ms ║║Cancelling condition #1’s schedules…
+187ms ║║Condition group #1 evaluated true (state changed) (6ms)
+199ms ║║Comparison (long) 1365 is_greater_than_or_equal_to (integer) 20000 = false (1ms)
+200ms ║║Cancelling condition #11’s schedules…
+201ms ║║Condition #11 evaluated false (11ms)
+201ms ║║Condition group #2 evaluated false (state did not change) (12ms)
+207ms ║║Comparison (enum) open changes_to (string) closed = false (1ms)
+208ms ║║Cancelling condition #18’s schedules…
+209ms ║║Condition #18 evaluated false (5ms)
+210ms ║║Condition group #17 evaluated false (state did not change) (6ms)
+211ms ║║Condition group #14 evaluated false (state did not change) (6ms)
+215ms ║║Comparison (string) null executes (string) toggleWallace = false (1ms)
+216ms ║║Condition #27 evaluated false (3ms)
+217ms ║║Condition group #20 evaluated false (state did not change) (5ms)
+219ms ║╚Execution stage complete. (42ms)
+220ms ╚Event processed successfully (220ms)

4/30/2018, 1:06:35 AM +289ms
+1ms ╔Received event [Cat Flap].contact = open with a delay of 479ms
+200ms ║RunTime Analysis CS > 23ms > PS > 54ms > PE > 122ms > CE
+202ms ║Runtime (44957 bytes) successfully initialized in 54ms (v0.3.104.20180323) (200ms)
+203ms ║╔Execution stage started
+211ms ║║Comparison (enum) open changes_to (string) open = true (0ms)
+212ms ║║Cancelling condition #10’s schedules…
+212ms ║║Condition #10 evaluated true (4ms)
+213ms ║║Cancelling condition #1’s schedules…
+214ms ║║Condition group #1 evaluated true (state changed) (7ms)
+226ms ║║Comparison (long) 8464870 is_greater_than_or_equal_to (integer) 20000 = true (2ms)
+227ms ║║Condition #11 evaluated true (11ms)
+228ms ║║Condition group #2 evaluated true (state did not change) (12ms)
+235ms ║║Comparison (enum) not present is (string) present = false (1ms)
+237ms ║║Cancelling condition #7’s schedules…
+237ms ║║Condition #7 evaluated false (8ms)
+238ms ║║Cancelling condition #2’s schedules…
+239ms ║║Condition group #2 evaluated false (state changed) (10ms)
+241ms ║║Cancelling statement #3’s schedules…
+279ms ║║Executed physical command [null].arrived() (37ms)
+280ms ║║Executed [Wallace].arrived (38ms)
+290ms ║║Calculating (string) Came in on + (string) Mon >> (string) Came in on Mon
+292ms ║║Calculating (string) Came in on Mon + (string) at >> (string) Came in on Mon at
+294ms ║║Calculating (string) Came in on Mon at + (string) 01:06 >> (string) Came in on Mon at 01:06
+297ms ║║Executed virtual command [Wallace].setState (0ms)
+304ms ║║Comparison (enum) open changes_to (string) closed = false (1ms)
+305ms ║║Cancelling condition #18’s schedules…
+306ms ║║Condition #18 evaluated false (5ms)
+307ms ║║Condition group #17 evaluated false (state did not change) (6ms)
+307ms ║║Condition group #14 evaluated false (state did not change) (7ms)
+313ms ║║Comparison (string) null executes (string) toggleWallace = false (2ms)
+314ms ║║Condition #27 evaluated false (4ms)
+315ms ║║Condition group #20 evaluated false (state did not change) (5ms)
+317ms ║╚Execution stage complete. (114ms)
+318ms ╚Event processed successfully (318ms)


#2

There’s no overflow value that I’m aware of for previousAge, but someone familiar with the backend would have to confirm. Since epoch time doesn’t overflow or reach a max value, it doesn’t seem like there would be any limit at all. However, I can say for absolute certain that an hour or so is NOT exceeding any limit for previousAge.

The fact it’s comparing to 1365 means it was in its previous state for 1.365 seconds. That seems more like it changed states a couple times quickly but nothing showed up in your logging.

Your better option might be to use a variable at the top of your piston, LastExecuted or something like that. When your piston fires and your contact is Open, set that variable to $now.

Then next time your piston runs and detects a contact is open, see if $now - LastExecuted is > 20000. That way anything that happens too quickly in ST for webCoRE to process it doesn’t result in errors in your piston execution.

If that doesn’t make sense, let me know and I’ll post up a sample piston in a few minutes.


#3

Thanks, I’ve set that up and I’ll try it over the next couple of days. I appreciate the help.

(lastExecuted - $now) gave me a datetime answer so I cast it to int and that seems to be working. Do you see any reason not to do that?


#4

No problem! I think casting to int should work perfectly fine.


#5

I’ve been running this for a few days and so far it works perfectly. Thanks for your help.