How to do nightly safety check on 2 door locks?


#1

1) Give a description of the problem
I’m trying to create a “Nightly Safety Check” piston with 2 door locks. I tested the piston and it correctly sees the status of the kitchen door, but it incorrectly sees the status of the front door?

2) What is the expected behaviour?
The piston should correctly see the status of both door locks.

3) What is happening/not happening?
The front door is unlocked but it sees it as locked?

4) Please ignore line 45, I forgot to delete it. I was trying different code.

5) Attach logs after turning logging level to Full
10/21/2019, 10:09:59 PM +73ms
+1ms ╔Received event [Home].time = 1571717400000 with a delay of -927ms
+600ms ║RunTime Analysis CS > 514ms > PS > 54ms > PE > 32ms > CE
+603ms ║Runtime (41926 bytes) successfully initialized in 54ms (v0.3.110.20191009) (601ms)
+604ms ║╔Execution stage started
+795ms ║║Comparison (time) 79799864 happens_daily_at (time) 79800000 = true (1ms)
+796ms ║║Time restriction check passed
+798ms ║║Cancelling condition #8’s schedules…
+799ms ║║Condition #8 evaluated true (9ms)
+811ms ║║Cancelling statement #8’s schedules…
+817ms ║║Requesting time schedule wake up at Tue, Oct 22 2019 @ 10:10:00 PM MDT
+828ms ║║Comparison (enum) unlocked is (string) unlocked = true (1ms)
+830ms ║║Condition #2 evaluated true (10ms)
+831ms ║║Cancelling condition #1’s schedules…
+832ms ║║Condition group #1 evaluated true (state changed) (41ms)
+834ms ║║Cancelling statement #5’s schedules…
+8303ms ║║Executed physical command [Kitchen Door].lock() (7466ms)
+8305ms ║║Executed [Kitchen Door].lock (7469ms)
+8312ms ║║Calculating (string) NIGHTLY SAFETY CHECK --> + (string) The kitchen door was unlocked so I locked it. >> (string) NIGHTLY SAFETY CHECK --> The kitchen door was unlocked so I locked it.
+8316ms ║║Executed virtual command [Kitchen Door].setVariable (1ms)
+8326ms ║║Comparison (time) 79807393 happens_daily_at (time) 79800000 = false (1ms)
+8328ms ║║Condition #12 evaluated false (9ms)
+8405ms ║║Cancelling statement #12’s schedules…
+8412ms ║║Requesting time schedule wake up at Tue, Oct 22 2019 @ 10:10:00 PM MDT
+8415ms ║║Condition group #11 evaluated false (state did not change) (96ms)
+8417ms ║║Cancelling statement #14’s schedules…
+8423ms ║║Calculating (string) NIGHTLY SAFETY CHECK --> The kitchen door was unlocked so I locked it. + (string) The front door is locked. >> (string) NIGHTLY SAFETY CHECK --> The kitchen door was unlocked so I locked it. The front door is locked.
+8427ms ║║Executed virtual command [Front Door].setVariable (2ms)
+8430ms ║║Cancelling statement #18’s schedules…
+8457ms ║║Executed virtual command sendSMSNotification (20ms)
+8533ms ║╚Execution stage complete. (7929ms)
+8537ms ║Setting up scheduled job for Tue, Oct 22 2019 @ 10:10:00 PM MDT (in 86392.391s), with 1 more job pending
+8545ms ╚Event processed successfully (8545ms)
10/21/2019, 10:09:09 PM +898ms
+1ms ╔Starting piston… (v0.3.110.20191009)
+121ms ║╔Subscribing to devices…
+163ms ║║Subscribing to Kitchen Door…
+164ms ║║Subscribing to Front Door…
+166ms ║╚Finished subscribing (52ms)
+189ms ║Comparison (time) 79750083 happens_daily_at (time) 79800000 = false (1ms)
+191ms ║Cancelling condition #8’s schedules…
+192ms ║Cancelling statement #8’s schedules…
+199ms ║Requesting time schedule wake up at Mon, Oct 21 2019 @ 10:10:00 PM MDT
+209ms ║Comparison (enum) unlocked is (string) unlocked = true (2ms)
+211ms ║Cancelling condition #2’s schedules…
+224ms ║Comparison (time) 79750117 happens_daily_at (time) 79800000 = false (0ms)
+226ms ║Cancelling statement #12’s schedules…
+232ms ║Requesting time schedule wake up at Mon, Oct 21 2019 @ 10:10:00 PM MDT
+242ms ║Comparison (enum) unlocked is (string) unlocked = true (1ms)
+254ms ║Setting up scheduled job for Mon, Oct 21 2019 @ 10:10:00 PM MDT (in 49.849s), with 1 more job pending
+270ms ╚Piston successfully started (270ms)


#2

In my case, the ST hub sees 3 different status.
1 - Locked
2 - Unlocked
3 - Unknown

I tried - ping, refresh etc but it would still see wrong status frequently…
So finally I stopped depending on the STATUS and started locking the door no matter what…


#3

I finally got this to work! If anyone has suggestions how to make the code more efficient or fool-proof, I’m open to suggestions! Thank you


#4

I like your structure in the last piston much better…

(only one trigger, and each ELSE has only a single condition above it)

Nice work @bubblywater !


Pro Tip:
Once you have tested it a few days, an alternative of this can have all ELSE blocks set variable to:
""
(that’s two double parenthesis)

This will effectively clear those variables if the door is locked, so the SMS will only list the doors that are UNLOCKED. :sunglasses:


#5

One more tip:

I might invert all of your logic for safety. In other words, instead of saying:

  • IF Lock is unlocked, then store alert, ELSE, all is clear
    I would write it this way:
  • IF Lock is locked, then all is clear, ELSE, store alert

This has the added benefit of catching & sending an alert, even if there’s an error.
(as @ike2018 mentioned above)


#6

Great! Thanks for the great tip! Can you please explain in simple terms why inverting the logic is safer?

I never understood the Store Alert option when Sending SMS, so I just left it at its default settings.


#7

Sure thing…

Your current code:
IF Lock is UNlocked, then store alert, ELSE, all is clear
will assume “all is clear” if it’s locked, OR if there is an error, OR the lock is unknown, OR jammed

Alternatively, my suggested code:
IF Lock is LOCKED, then all is clear, ELSE, store alert
will only give the “all clear” if the door is locked. All other possibilities you will get an alert.


Another way to say this… The THEN section should be the very specific scenario, and the ELSE block will capture all other possibilities…


#8

Ahhh… that makes PERFECT sense!!! Thank you!