Help with detecting switch position


#1

I have a piston that will turn on a light, wait for 15 minutes, turn off a light for 350 milliseconds, then back on, then wait for 1 minute, then turn off the light.

The intent of this is to warn someone that the light will turn off in one minute. What I am hoping to do is add logic that if the user presses the switch for the light to the ON position during the last 1 minute that the automatic off will be cancelled. I’m not sure how to approach this. Any help would be appreciated!


#2

The only way you could do this is if your switch reports to SmartThings if it’s turned “on” when it’s already on.

To do this, your piston needs to be subscribed to the switch you want to use (basically means the piston monitors the switch for changes and the piston executes whenever the switch reports a change).

First, you’ll need to fix line 57 in your snapshot above. You don’t want to monitor Switch 8 $status, you want to monitor the switch parameter and use the default on or off options (not capitalized, that won’t evaluate correctly).

Next, to make the piston subscribe, to that switch, click on the statement you just edited for switch 8 and in the upper right corner of your screen you’ll see Subscription Method - change that to Always.

If you’ve got it right so far, after you save your piston and look at it in the viewer (not the edit screen) the line for Switch 8’s switch will have an orange lightning bolt next to it. That means your piston is subscribed.

Now for the test…

Enable full logging (at the bottom of the piston viewer screen). Simply turn your light from off to on. You should see an entry in your logs starting with [HubName].switch. That means your switch reported its change and your piston saw it.

Now, with the light already on, go ‘turn the light on’ again. Check your logs to see if a 2nd [HubName].switch event is processed. My suspicion is it won’t show a 2nd time.

If it does, we can edit your piston to cancel the timer by pushing the switch “on” for the lights that are about to be turned off.

If it doesn’t we can still accomplish your goal but only by turning the lights off, and then back on.

Let me know if any of this is unclear, and post back with your results!


#3

Sorry it took me so long to get back to you but my house had a leak in the kitchen and I’ve had to move out for some time.

I’ve changed the line you pointed out! Thank you. There is also a statement above it for when the contact sensor opens that was also using the $status incorrectly that I had to fix. I’ve enabled full logging as well. I’m not sure if it is doing what we need to or not.

12/12/2018, 4:26:37 PM +108ms
+1ms +Starting piston… (v0.3.108.20180906)
+344ms ¦+Subscribing to devices…
+402ms ¦¦Subscribing to Shed Door.contact…
+423ms ¦¦Subscribing to Shed Door.$status…
+440ms ¦¦Subscribing to Shed Overhead.switch…
+598ms ¦+Finished subscribing (262ms)
+797ms ¦Comparison (enum) on is (string) off = false (2ms)
+799ms ¦Cancelling condition #17’s schedules…
+801ms ¦Cancelling condition #15’s schedules…
+825ms ¦Comparison (boolean) true is (boolean) true = true (2ms)
+828ms ¦Cancelling condition #20’s schedules…
+829ms ¦Cancelling condition #19’s schedules…
+864ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 12802.03s), with 3 more jobs pending
+877ms +Piston successfully started (876ms)
12/12/2018, 4:23:38 PM +2ms
+130ms +Stopping piston…
+283ms +Piston successfully stopped (152ms)
12/12/2018, 4:22:55 PM +521ms
+2ms +Received event [Shed Door].contact = closed with a delay of 817ms
+105ms ¦RunTime Analysis CS > 35ms > PS > 33ms > PE > 37ms > CE
+108ms ¦Runtime (41697 bytes) successfully initialized in 33ms (v0.3.108.20180906) (105ms)
+109ms ¦+Execution stage started
+132ms ¦¦Comparison (enum) closed changes_to (string) open = false (0ms)
+134ms ¦¦Condition #14 evaluated false (6ms)
+135ms ¦¦Condition group #13 evaluated false (state did not change) (8ms)
+139ms ¦+Execution stage complete. (30ms)
+142ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13024.338s), with 3 more jobs pending
+153ms +Event processed successfully (153ms)
12/12/2018, 4:22:27 PM +855ms
+2ms +Received event [Shed Overhead].switch = on with a delay of 835ms
+85ms ¦RunTime Analysis CS > 21ms > PS > 33ms > PE > 30ms > CE
+88ms ¦Runtime (41690 bytes) successfully initialized in 33ms (v0.3.108.20180906) (85ms)
+89ms ¦+Execution stage started
+114ms ¦¦Cancelling condition #14’s schedules…
+115ms ¦¦Condition #14 evaluated false (9ms)
+116ms ¦¦Cancelling condition #13’s schedules…
+118ms ¦¦Condition group #13 evaluated false (state changed) (12ms)
+123ms ¦+Execution stage complete. (35ms)
+126ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13052.02s), with 3 more jobs pending
+139ms +Event processed successfully (139ms)
12/12/2018, 4:22:27 PM +277ms
+2ms +Received event [Shed Door].contact = open with a delay of 829ms
+85ms ¦RunTime Analysis CS > 17ms > PS > 35ms > PE > 34ms > CE
+88ms ¦Runtime (41697 bytes) successfully initialized in 35ms (v0.3.108.20180906) (85ms)
+89ms ¦+Execution stage started
+110ms ¦¦Comparison (enum) open changes_to (string) open = true (1ms)
+112ms ¦¦Cancelling condition #14’s schedules…
+114ms ¦¦Condition #14 evaluated true (7ms)
+115ms ¦¦Cancelling condition #13’s schedules…
+116ms ¦¦Condition group #13 evaluated true (state changed) (11ms)
+140ms ¦¦Comparison (enum) off is (string) off = true (2ms)
+142ms ¦¦Condition #17 evaluated true (23ms)
+143ms ¦¦Condition group #15 evaluated true (state did not change) (24ms)
+146ms ¦¦Cancelling statement #23’s schedules…
+153ms ¦¦Executed virtual command setVariable (3ms)
+157ms ¦¦Cancelling statement #25’s schedules…
+178ms ¦¦Executed physical command [Shed Overhead].on() (17ms)
+180ms ¦¦Executed [Shed Overhead].on (19ms)
+188ms ¦+Execution stage complete. (99ms)
+191ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13052.533s), with 3 more jobs pending
+202ms +Event processed successfully (202ms)
12/12/2018, 4:22:23 PM +872ms
+1ms +Received event [Shed Door].contact = closed with a delay of 826ms
+109ms ¦RunTime Analysis CS > 21ms > PS > 48ms > PE > 40ms > CE
+112ms ¦Runtime (41697 bytes) successfully initialized in 48ms (v0.3.108.20180906) (109ms)
+113ms ¦+Execution stage started
+134ms ¦¦Comparison (enum) closed changes_to (string) open = false (1ms)
+136ms ¦¦Condition #14 evaluated false (6ms)
+138ms ¦¦Condition group #13 evaluated false (state did not change) (8ms)
+142ms ¦+Execution stage complete. (30ms)
+145ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13055.984s), with 3 more jobs pending
+171ms +Event processed successfully (170ms)
12/12/2018, 4:22:22 PM +412ms
+1ms +Starting piston… (v0.3.108.20180906)
+387ms ¦+Subscribing to devices…
+445ms ¦¦Subscribing to Shed Door.contact…
+464ms ¦¦Subscribing to Shed Door.$status…
+483ms ¦¦Subscribing to Shed Overhead.switch…
+600ms ¦+Finished subscribing (232ms)
+777ms ¦Comparison (enum) off is (string) off = true (2ms)
+804ms ¦Comparison (boolean) false is (boolean) true = false (3ms)
+833ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13056.757s), with 3 more jobs pending
+848ms +Piston successfully started (847ms)
12/12/2018, 4:21:33 PM +981ms
+2ms +Starting piston… (v0.3.108.20180906)
+216ms ¦+Subscribing to devices…
+277ms ¦¦Subscribing to Shed Door.$status…
+290ms ¦¦Subscribing to Shed Overhead.switch…
+384ms ¦+Finished subscribing (172ms)
+584ms ¦Comparison (enum) off is (string) off = true (3ms)
+612ms ¦Comparison (boolean) false is (boolean) true = false (3ms)
+641ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13105.379s), with 3 more jobs pending
+654ms +Piston successfully started (652ms)
12/12/2018, 4:21:31 PM +224ms
+106ms +Stopping piston…
+309ms +Piston successfully stopped (204ms)
12/12/2018, 4:21:26 PM +957ms
+1ms +Received event [Shed Overhead].switch = off with a delay of 178ms
+196ms ¦RunTime Analysis CS > 146ms > PS > 22ms > PE > 28ms > CE
+199ms ¦Runtime (41546 bytes) successfully initialized in 22ms (v0.3.108.20180906) (197ms)
+200ms ¦+Execution stage started
+223ms ¦¦Condition #14 evaluated false (5ms)
+225ms ¦¦Condition group #13 evaluated false (state did not change) (6ms)
+229ms ¦+Execution stage complete. (29ms)
+232ms ¦Setting up scheduled job for Wed, Dec 12 2018 @ 8:00:00 PM PST (in 13112.812s), with 3 more jobs pending
+244ms +Event processed successfully (244ms)