Why doesn't stay open retrigger


#1

1) Give a description of the problem
i have a piston that is checking if door stays open… the first time it runs it works correctly. The next time it runs it seems to not check if stays open is still valid ,…almost as if it can only do once

2) What is the expected behaviour?
I want it to execute the piston the second time and beyond like the first time

3) What is happening/not happening?
its not evaluating true the check of if still open

**4)

5) Attach logs after turning logging level to Full

 Dads Home \ webCoRE (v0.3.110)

## kitchen door

## Status

This piston is currently active and humming happily.

Pause »

Piston Category

Uncategorized Uncategorized

## Quick Facts

Piston state: true

Last executed: 1/15/2020, 9:40:00 AM

Next scheduled: never

Subscriptions: 1 event, 5 controls

Devices used: 6

Memory used: 33% (33075 bytes)

External URL: [(click to open/execute)](https://graph-na04-useast2.api.smartthings.com/api/token/3e354e3f-9c1b-4ea6-ac72-b2c24e9df73a/smartapps/installations/3e8cbc81-3cf9-4a04-8aea-26b06ab101cf/execute/:8b4767770f5755ac1d8337f708cc5e27:)

## Automatic Backup

Automatic backup enabled.

Click the box to reveal your backup bin code. Make a note of this code as you may use it later to restore a deleted piston.

s0i7w

**Do NOT share this code with anyone.**

### Script

Edit Test    

TraceTrace

 Delete

/**************************************************************//* kitchen door *//**************************************************************//* Author : tjo *//* Created : 1/4/2020, 10:28:29 PM *//* Modified : 1/15/2020, 1:19:13 AM *//* Build : 12 *//* UI version : v0.3.110.20191009 *//**************************************************************/ +0msstart/* Trace started on 1/15/2020, 9:40:00 AM (about 4 minutes ago) */ definedynamic intemp; /* 76 */dynamic outtemp; /* 19 */dynamic senttext = 0;end define; execute+387ms21ms

if /* #1 */

Kitchen Door's contact stays open for 1 minute /* #2 */

then

with /* #3 */Smart Bulbdo

 Flash on 700 milliseconds / off 700 milliseconds for 8 times; /* #4 */

end with;

 Wait 3 seconds; /* #26 */

if /* #20 */

Any of Basement Door's, Front Door's, Kitchen Door's, or Outside Garage Door's contact is open /* #21 */

then

with /* #22 */Smart Bulbdo

 Turn on; /* #23 */

end with;

end if;

 Set variable {intemp} = Kitchen Door's temperature; /* #7 */

 Set variable {outtemp} = {$twcweather.conditions.temperature}; /* #8 */

with /* #5 */Echo - Anne's Echo Dotdo

Speak text "Please close the kitchen door the outdoor temperature is {outtemp} and the indoor temperature is {intemp}"; /* #9 */

end with;

if /* #10 */

{senttext} is equal to 0 /* #11 */

then

 Send SMS notification "Kitchen door is open" to 5073196891 and store in Messages; /* #13 */

 Send SMS notification "Kitchen door is open" to 4149756518 and store in Messages; /* #16 */

 Set variable {senttext} = 1; /* #17 */

end if;

+407ms▼ ▼ ▼ Wait 3 minutes; /* #19 */

else

 Set variable {senttext} = 0; /* #15 */

end if;

+408msdoneend execute; +423msstop/* Trace ended on 1/15/2020, 9:40:00 AM */

Edit Test    

TraceTrace

 Delete

### Logs

1/15/2020, 9:40:00 AM +548ms
+0ms ╔Received event [Dads Home].time = 1579102801412 with a delay of -865ms
+383ms ║Runtime (42703 bytes) successfully initialized in 292ms (v0.3.110.20191009) (382ms)
+384ms ║╔Execution stage started
+409ms ║╚Execution stage complete. (25ms)
+410ms ╚Event processed successfully (410ms)
1/15/2020, 9:36:54 AM +122ms
+0ms ╔Received event [Dads Home].time = 1579102611936 with a delay of 2185ms
+144ms ║Runtime (42702 bytes) successfully initialized in 56ms (v0.3.110.20191009) (142ms)
+145ms ║╔Execution stage started
+3544ms ║║Executed virtual command wait (0ms)
+3548ms ║║Waiting for 3000ms
+6575ms ║║Executed [Smart Bulb].on (3ms)
+6585ms ║║Executed virtual command setVariable (3ms)
+6816ms ║║Executed virtual command setVariable (3ms)
+7230ms ║║Executed [Echo - Anne's Echo Dot].playText (397ms)
+7267ms ║║Executed virtual command sendSMSNotification (24ms)
+7279ms ║║Executed virtual command sendSMSNotification (8ms)
+7283ms ║║Executed virtual command setVariable (1ms)
+7289ms ║║Executed virtual command wait (0ms)
+7290ms ║║Requesting a wake up for Wed, Jan 15 2020 @ 9:40:01 AM CST (in 180.0s)
+7293ms ║╚Execution stage complete. (7148ms)
+7294ms ║Setting up scheduled job for Wed, Jan 15 2020 @ 9:40:01 AM CST (in 179.996s)
+7305ms ╚Event processed successfully (7306ms)
1/15/2020, 9:36:46 AM +199ms
+0ms ╔Received event [Dads Home].time = 1579102607375 with a delay of -1177ms
+94ms ║Runtime (42708 bytes) successfully initialized in 42ms (v0.3.110.20191009) (93ms)
+95ms ║╔Execution stage started
+141ms ║║Executed virtual command [Smart Bulb].flash (33ms)
+142ms ║║Requesting a wake up for Wed, Jan 15 2020 @ 9:36:57 AM CST (in 11.3s)
+5048ms ║╚Execution stage complete. (4953ms)
+5051ms ║Setting up scheduled job for Wed, Jan 15 2020 @ 9:36:51 AM CST (in 1s), with 9 more jobs pending
+5067ms ╚Event processed successfully (5068ms)
1/15/2020, 9:35:47 AM +244ms
+0ms ╔Received event [Dads Home].test = 1579102547243 with a delay of 0ms
+108ms ║Runtime (42699 bytes) successfully initialized in 42ms (v0.3.110.20191009) (106ms)
+109ms ║╔Execution stage started
+141ms ║║Executed virtual command setVariable (1ms)
+154ms ║╚Execution stage complete. (46ms)
+162ms ║Setting up scheduled job for Wed, Jan 15 2020 @ 9:36:47 AM CST (in 59.97s)
+170ms ╚Event processed successfully (170ms)
1/15/2020, 8:50:14 AM +203ms
+10313ms ║Piston waited at a semaphore for 10143ms

Clear

Medium   Nothing selected  None  Minimal  Medium  Full 

Logging level 

### Variables

Local variables

dynamicintemp 76

dynamicouttemp 19

dynamicsenttext0

Global variables

(no variables defined)

System variables

dynamic$argsnull

integer$day15

integer$dayOfWeek3

string$dayOfWeekNameWednesday

device$deviceLocation

device$devicesLocation

integer$hour9

integer$hour249

string$httpContentType

integer$httpStatusCode

boolean$httpStatusOk

integer$iftttStatusCode

boolean$iftttStatusOk

dynamic$incidentsnull

decimal$index

dynamic$jsonnull

datetime$localNow1579081457634

device$locationLocation

string$locationModeHome

integer$mediaSize0

string$meridianAM

string$meridianWithDotsA.M.

datetime$midnight1/15/2020, 12:00:00 AM

integer$minute44

integer$month1

string$monthNameJanuary

string$namekitchen door

datetime$nextMidnight1/16/2020, 12:00:00 AM

datetime$nextNoon1/15/2020, 12:00:00 PM

datetime$nextScheduledTimeInvalid Date

datetime$nextSunrise1/16/2020, 7:42:00 AM

datetime$nextSunset1/15/2020, 4:58:00 PM

dynamic$nflnull

datetime$noon1/15/2020, 12:00:00 PM

datetime$now1/15/2020, 9:44:17 AM

dynamic$placesnull

decimal$random0.47495381538043835

string$randomColor#ADD8E6

string$randomColorNameDeep Pink

integer$randomHue180

integer$randomLevel54

integer$randomSaturation54

dynamic$responsenull

integer$second17

boolean$shmTrippedfalse

string$state(not set)

datetime$sunrise1/15/2020, 7:42:00 AM

datetime$sunset1/15/2020, 4:58:00 PM

string$temperatureScaleF

string$time9:44 A.M.

string$time249:44

dynamic$twcweathernull

datetime$utc1579103057685

string$versionv0.3.110.20191009

dynamic$weathernull

integer$year2020

### Evaluation Console

ValueExpression

### StatisticsPreformatted text

**REMOVE BELOW AFTER READING**
If a solution is found for your question then please mark the post as the solution.

#2

I think the issue here is that you are using the “stays open” trigger. Once that has ran the first time and the door remains open, it no longer stays open again. If that makes sense. If you want to repeat the piston while the door is open you have to put in a repeat loop for it to reference the stays open again at the very least.

That being said I feel there is a better way to accomplish your task without having to repeat the whole piston. Something along the lines “if door stays open” then “repeat this set of statements.”


#3

try this,

IF kitchen door CHANGES TO OPEN
Then 
WAIT 1 minute (TCP set to never)
    (Here all other stuff you have)

(final IF block)
IF kitchen door CHANGES  TO CLOSE
then 
Cancel All Pending Tasks

#4

If you only want a few backup reminders, you can just add a couple of triggers right below line 24:

IF 
    Sensor 3's contact stays open for 1 minute
    or
    Sensor 3's contact stays open for 2 minutes  <-- new trigger
    or
    Sensor 3's contact stays open for 3 minutes  <-- new trigger
    Then
        (current code here)

When the door closes, it will not execute any lingering timers.
When the door opens again, all three timers begin anew.

This is a great way to avoid looping.


pic

This piston runs (at most) three times per door open…


#5

The logs are a little spartan but seem to show ‘stays open’ working as expected. When you hit ‘test’ the ‘stays’ condition sees the contact is open and sets a wake up for one minute and immediately returns false and runs the else condition. As the contact stays open the piston wakes up after a minute and now executes the ‘then’ block, executing a flash and scheduling a wake up for after it finishes. It wakes up, does a busy wait of 3 seconds, does some more stuff, schedules a wake up in 3 minutes, wakes up and finishes.

So what exactly is the failure mode?

The 3 minute wait at the end intrigues me. Are you expecting the piston to just run again by itself? It will only run when the contact changes state or you manually run it. Only asking because there are plenty of webCoRE users who misunderstand what a trigger actually is.


#6

Now that is rather elegant and neatly demonstrates how ‘stays’ really behaves.


#7

I admit, STAYS threw me the first time I used them…

What I now realize is:
IF Sensor 3's contact stays open for 1 minute
will fire once, (and only once), exactly one minute after the contact has opened.


#8

It doesn’t even need the contact to have just opened. Although it is a trigger it evaluates identically to ‘is open’. That’s how it worked for the OP using the TEST button. It also returns false immediately, as well as scheduling a wake up for 1 minute and then acting as if it had returned true.


#9

wow, you are all rock stars !!

orangebucket … the 3 min wait was yes because I thought it would sit there for 3 mins and then be eligible to retrigger if the top trigger was true.
I guess once the stays open for N minutes only triggers once

the multiple stays open if VERY elegant …but I kinda want it to keep repeating
I wish there was a way to reset that first “stays open”

what about having a variable for stayopen (see pic)…although i’m somehow not incrementing it properly as the number does not increase


#10

Ah right. The key thing to understand is that your piston code is run in response to selected SmartThings events. Those events are simple things like changes in device attributes, timers, and a few webCoRE generated events like the TEST button being pressed. Basically something has happened that might affect the piston so it is executed. It is down to the piston itself to provide all the logic and decide what to do. A CONDITION like ‘contact is open’ looks to see if the contact is open or not (!). It doesn’t matter why the piston ran. A TRIGGER like ‘contact changes to open’ looks to see if the piston is running because the contact has changed state, the new state is open, and the old state is not open. So if you used the TEST button it will not evaluate as true.

The ‘stays open’ is a special case known as a ‘timed trigger’. It is classed as a TRIGGER but actually evaluates like a CONDITION. So it can do something in response to the TEST button.

There is nothing out there constantly evaluating trigger comparisons. If a piston has a trigger saying ‘temperature rises above 30C’, it runs because the device has reported a new temperature reading. It doesn’t matter what the new reading is. The piston itself decides if it has risen above 30C or not.


#11

Might I suggest something simple like

If contact sensor changes to open       <-- trigger 
  or
   contact sensor is open                      <-- condition
then
    while contact is open
         wait 2 minutes
         send message
    end while
end if

the tigger/condition pair will start the process and allow repeat as long as the door stays open and the while will keep the process executing. I use this for a door open chime to warn me if the grandkids go out towards the pool.


#12

orangebucket
thanks for the detailed explanation…it takes a lot of info for my brain to comprehend
and as an engineer I love to understand how something works so that was very helpful

guxdude… i will give your approach a try… thanks!