Need help with a, should be, easy piston


#1

1) Give a description of the problem
Is there a better way to do this? Lights turn on fine but it is getting them to turn off.

2) What is the expected behavior?
When door opens, turn lights on.
When a door shuts and all the doors stay shut for 5m, turn lights off.

3) What is happening/not happening?
Lights not turning off after a lot of activity with doors.

**4) Post a Green Snapshot of the piston!

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS)


#2

Get rid of the “any contact changes” in your off statement and just leave the closed for 5 minutes. I’d also move that out so it’s a unique statement, not a nested else if for the first one.


#3

Here is one I use to turn on my outside lights when door opens. Works good. All you need to do is change time, if you want
Mike


#4

Thanks.
What do you mean move it out so it is a unique statement.


#5

If you follow the blue bars from your first IF statement, do hih see how the second IF is part of your first one? It’s part of the “else” statement, expected only if the first is false.

If you move it using the triangles near your piston line numbers, you can drag it below the other IF statement and it’ll be independent.


#6

So like this?


#7

Exactly! Now I think you just need to click in your second IF statement and change ANY to ALL so lights only turn off when all doors stay closed.

Let me know if this works?


#8

Good catch - thank you.
Let me try this out.


#9

It might be easier to roll your after and before statements into one.
i.e.
Time is between Sunset and Sunrise.


#10

But I have different tasks with each one. I have an extra switch on sunset.


#11

Oops. Missed the extra device.


#12

Since the IFs are not “async,” does the first IF need to trigger to check the next IF statement?
Or if the contacts are closed for 5m, it would trigger the second IF regardless if a door opened?

Would there a problem if I made them both async IFs? I guess I don’t fully understand the difference.
I know IFs run in sequence and async can run at the same time. But if the first IF is never triggered, it would never check second IF statement - is how I’m thinking about it.


#13

Any trigger will run the whole piston, top-to-bottom. You could make them asynch but I don’t think there would be any benefit to it in this case.


#14

Does it matter if this piston is sync vs async?


#15

No, async only matters if you could need to evaluate two conditions in parallel. In that one, either one is true or the other is… There’s no need to evaluate them asynchronously.


#16

Do you have any example pistons where async would be necessary vs sync?
I tried to find one on the wiki page but couldn’t.
I don’t know why I am having a hard time understanding this.


#17

It’s more for parallel execution of complex IF statements. I don’t have a specific example, but think of something along these lines:

IF door#1 opens
Then if someone’s presence changed to away, then turn off a bunch of lights and close a garage door
Then if someone’s presence changed to present and time is between sunset and sunrise, then turn on a bunch of lights and open a garage door, else open a garage door, and if time is after 6pm Turn TV on in the family room
etc.

IF door#2 opens
Then turn on a light

If the two are run synchronously, when Door#2 opens it will trigger the piston to execute top-to-bottom, burning up time on the first IF block. By the time the lights are turned on from the Door#2 block, there would be a perceivable delay.

If the two are run asynchronously, when Door#2 opens it will only execute “Then turn on a light”. Furthermore, if Door#2 is opened while the IF block is already running for Door#1, it will execute immediately rather than waiting for the other IF block to complete.

Hope that didn’t make it even more confusing?! lol


#18

Thanks, I think of getting it.
Is this a better example?

If door #1 opens
Then notify me with push notification

If door #2 opens
Then Turn lights on, wait 10m, and turn lights off

If door #3 opens
Then turn lights on and turn TV on

So if running in sync and door #2 opens, then door #1 or #3 opens 5m later.
The 1st and 3rd IF won’t run because the piston is stuck on the wait 10m?

If running in sync, does it also mean:

If door #1 is open
Then turn lights on

If door #1 changes to open
Then shut garage

Since the first IF is a condition and the second is a trigger, when the door changes to open, noth IFs would execute? If running in async, only the second runs?


#19

One thing you have to consider is how the Piston actually started. What you’ve built there in your last example is a Piston that is “subscribed” to three different door sensors. The piston is going to basically hum along and watch those three sensors and if ANY of them Open it will execute the ENTIRE piston.

The only difference between what you’ve got there and how it will operate with SYNC or ASYNC is going to be when you open Door 2…and the difference will be WHEN the IF for Door 3 is evaluated. If you open Door 2 with Sync ON then the piston will wait for 10 minutes, turn the lights off and then check on Door 3. If you put ASYNC on, then it will still evaluate all 3 IF blocks but it won’t wait 10 minutes before checking on Door 3.

The opening of any of those doors will run the entire piston. So if you open Door 2, then wait 5 minutes and open Door 3 (regardless of SYNC or ASYNC) the entire piston will run again and it will evaluate all the IF blocks again.

But know that with SYNC ON after the 5 minute Wait after opening Door 2 it’s going to check on Door 3. Essentially you’ll have the Piston running twice. Once because you opened Door 2 and it’s waiting to check on Door 3 and once because you opened Door 3 which causes it to run the whole piston again (starting by checking Door 1, then 2, then 3).


#20

Thanks for the response.
So is it best to make all three IFs ASYNC or make 3 separate pistons?