Wait 30sec before run piston again?


#1

1) Give a description of the problem
Piston runs every time door opens and I would like it to happen only once in 30sec period.

2) What is the expected behaviour?
When door opens Google assistant says “door was opened”. If door sensor reports door open twice or 3 times (it sometimes do even though door was opened just once) I do not want it to repeat “door was opened” 3 times. I just want it happen once in 30sec.

3) What is happening/not happening?
Tried to limit piston by adding “never cancel tasks” to all IFs. In the end of the piston there is “wait 30sec”. If door opens in that 30sec waiting time it still runs piston again and repeats “door was opened”.

**4) Post a Green Snapshot of the piston![image|45x37]![image|690x254]


#2

There are MANY ways to do this. I have not had my coffee yet so this is untested. I would suggest the following :

IF Open Close Dining Room Door's contact changes to open
  THEN
    IF Time is between 9 AM and 8 PM  (set TCP to NEVER here)
      THEN
        Set variable {command}....
        Make a POST
        Wait 30 seconds
    END IF
END IF

#3

I have gotten where I try to avoid putting waits in commands if possible. They seem to cause many issues, YMMV.

You could create a time variable and set it to $now each time you send the message, then add something like this to your logic.

IF $now > addminutes(variable ,30)
do message here


#4

Maybe there are many ways… but yours did not work :slight_smile: get some coffee. Piston does exactly the same but in a different order. I opened door = “door opened”. I closed the door and opened it again after 5 seconds = “door opened”.


#5

Variables are something that I do not fully understand. Isn’t there easier way to get piston to really wait 30 seconds before it’s ran again. I thought that task cancelation process purpose is to not cancel piston until it is 100% ready (including that 30sec wait).


#6

Try moving the TCP to the very first IF and report back. :slight_smile:


#7

Did not help :frowning:


#8

I agree with @Terminal, TCP and WAITS can be tricky. I will take another look…


#9

Thanks!! :pray:


#10

Can you give me a trace of your above piston please?


#12

I am still not sure why your above piston did not work…hmmmmm, maybe someone else can chime in
here… @WCmore , @ike2018 thoughts?


#13

@Pantheon your suggestions were so dead on so I wasn’t even following this post… thank you for the tag…

When a piston doesn’t work for no reason (no reason to me:)))) i’d go simple…
Just brainstorming:

1 - how many seconds your open close sensor remains ON even after the door closed? (i’m curious if any delays on registering)
2 - I’d suggest to get rid of all the variables first, just to test the system and timing etc. Once that’s working you can introduce variables back.
3 - try without the time restriction (just to keep it simple for now)

And here is a weird workaround,

IF open close sensor changes to OPEN
Then
Speak text "Dining room door opened"
Set volume to zero
Wait 30 seconds
Set volume to 60

#14

made a dummy piston:
image

It still has same problem. Sensor does not have delay. It’s closing and opening almost immediately…maybe 1 sec off max.

Took some log:
28.12.2019 klo 19.27.18 +114ms
+0ms ╔Received event [Koti].time = 1577554039935 with a delay of -1822ms
+77ms ║Runtime (36612 bytes) successfully initialized in 41ms (v0.3.110.20191009) (76ms)
+78ms ║╔Execution stage started
+79ms ║╚Execution stage complete. (1ms)
+80ms ╚Event processed successfully (80ms)

28.12.2019 klo 19.26.52 +738ms
+1ms ╔Received event [Open Close Sensor Front Door].contact = closed with a delay of 84ms
+49ms ║Runtime (36622 bytes) successfully initialized in 20ms (v0.3.110.20191009) (46ms)
+50ms ║╔Execution stage started
+60ms ║╚Execution stage complete. (11ms)
+61ms ╚Event processed successfully (61ms)

28.12.2019 klo 19.26.49 +831ms
+1ms ╔Received event [Open Close Sensor Front Door].contact = open with a delay of 117ms
+51ms ║Runtime (36628 bytes) successfully initialized in 24ms (v0.3.110.20191009) (49ms)
+52ms ║╔Execution stage started
+98ms ║║Executed virtual command sendPushNotification (34ms)
+102ms ║║Executed virtual command wait (1ms)
+103ms ║║Requesting a wake up for Sat, Dec 28 2019 @ 7:27:19 PM EET (in 30.0s)
+109ms ║╚Execution stage complete. (58ms)
+111ms ║Setting up scheduled job for Sat, Dec 28 2019 @ 7:27:19 PM EET (in 29.994s)
+122ms ╚Event processed successfully (122ms)

28.12.2019 klo 19.26.43 +168ms
+1ms ╔Received event [Open Close Sensor Front Door].contact = closed with a delay of 125ms
+80ms ║Runtime (36623 bytes) successfully initialized in 39ms (v0.3.110.20191009) (78ms)
+81ms ║╔Execution stage started
+94ms ║╚Execution stage complete. (12ms)
+95ms ╚Event processed successfully (95ms)

28.12.2019 klo 19.26.38 +967ms
+1ms ╔Received event [Open Close Sensor Front Door].contact = open with a delay of 104ms
+54ms ║Runtime (36628 bytes) successfully initialized in 27ms (v0.3.110.20191009) (52ms)
+55ms ║╔Execution stage started
+82ms ║║Executed virtual command sendPushNotification (15ms)
+85ms ║║Executed virtual command wait (1ms)
+86ms ║║Requesting a wake up for Sat, Dec 28 2019 @ 7:27:09 PM EET (in 30.0s)
+91ms ║╚Execution stage complete. (35ms)
+92ms ║Setting up scheduled job for Sat, Dec 28 2019 @ 7:27:09 PM EET (in 29.995s)
+103ms ╚Event processed successfully (102ms)

If I understand this right piston resets when sensor is closed. Are you guys understanding this same way or do you see other weird shit in it?


#15

Yeah it seems straight forward but I found often it is not. I have had many simple pistons with a wait that got many waiting at semphore. So if I can find a way to do it without a wait I use that approach first.

Also I had addminutes but I just realized you wanted 30 seconds so the function to use would be addseconds

It would only add a couple of lines to your piston. Define a datetime variable. Add the if in my above post and replace the wait with set date time variable to $now.

As others said there are many ways to do it, so do what seems the easiest to you.


#16

what is the problem you are having with this simple dummy piston?


#17

Im trying to make piston (run longer) wait that 30sec before it runs again so that those false sensor open / close reports are not repeated through my google home assistant.
I would like my piston to announce only once when door is open even though sensor reports that door was opened three times in a row.

In that simple dummy piston I get push notification every time door opens even when piston should be still waiting that 30sec.


#18

I see, that makes sense. I missed the part that piston executes all over everytime the door is opened my bad.

Ok here is another one then…

IF door changes to open 
AND
IF dooropen variable is TRUE
Then 
With speaker
Say "Door is opened"
Then
With dooropen variable set to = FALSE
Wait 30 seconds
With dooropen variable set to = TRUE

if i’m not mistaken (Sorry traveling, can’t test my draft)

even if door is opened again, it wont trigger the speak text because the variable is TRUE.
The door will announce something only IF it was closed 30 seconds. (this draft won’t work if the door is constantly used like an office entry door etc.)


#19

Im not able to test it today but tomorrow I am.
Is that piston now like it should be?


#20

is your TCP set to never?


#21

This piston will not run correctly unless you initialize the Dooropen variable to true. I THINK that boolean values are initialized by default to false (at least in my testing). Therefore, your Dooropen will initially be false and will never be set to true.