Trigger piston, wait for period of time OR end wait period if switch is turned off

loops
wait
triggers

#1

1) Give a description of the problem
I have a piston that turns on Garage Entrance Lights when vehicle is parked (trigger), then waits for 5 mins before continuing along, unless the light is manually switched off then it stops waiting and continues on. The only way I have successfully made this work is using a for loop and break on if condition. I’ve tried and tried with while and if statements to no avail. The for loop/break method works, but its holding up the piston for intervals of time and not efficient. Can someone please show me how this is done?

2) What is the expected behaviour?
Turn on light, wait for period of time, or if light is turned off at switch stop ‘wait’ and continue piston

3) What is happening/not happening?
I have to use continuous for loop on delay to keep checking for condition of light then break loop to continue or loop ends after count and continues. I’m looking for more efficient method.

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

5) Attach logs after turning logging level to Full


#2

I would add a ‘justParked’ variable in there. That way you can manually use the garage light without triggering the notification, door close, and turning off other lights…


#3

Excellent, thank you. I didn’t even consider using a group in the IF statement. Also, not to make excuses, but even though I use ‘stays’ in many of my pistons, it didn’t occur to me to try that here in conjunction with the ‘OFF’ condition. I guess when you look at a problem long enough it just “Stays On”. Sorry for the logic pun, but I couldn’t resist…

Again Thanks for the solution!


#4

Hum, turns out there is one problem with this method. I just had a case where the car was parked out on the curb because there were things blocking the driveway. So I turned on the ‘Garage Entrance Lights’ and opened the garage door, then took a few minutes to clear the driveway of the things blocking it and pulled the car into the Garage. Immediately when the car parking detector trigger was enabled (ON) the garage door closed behind it without any delay.

Looking at the logs, and tracing the logic, what is apparently happening is that as soon as the ‘Garage Entrance Lights’ or Switch 14 in this case is turned ON the timer is started, regardless of any conditions. So, since it took me more than 5 minutes to clear the driveway, as soon as the parking switch was ON the ‘justParking’ variable was set to ‘true’ and this matched the conditions of the IF statement in line 32. So, if Switch 14 (aka Garage Entrance Lights) is preset and time expires that condition is true because it has been on and stayed on for 5 minutes and so all it needs is the additional AND for the justParked variable to turn ‘true’ and the Garage door closes.

I’m trying to think of a way to make it so Switch 14 timer is only stared when the Piston turns on the light and set the control variable to true.

Any thoughts?


#5

Ok, took some trail and error, but turned out in the end to be an easy fix. I simply removed the AND ‘justParked is true’ condition. Converted the group OR condition (lines 34-36) back to simple OR condition. Then added a ONLY restriction to the IF for ‘justParked is true’.

So, now the IF will not even be evaluated no matter how long Switch 14 (aka Garage Entrance Lights) as been ON unless it was turned ON by the piston as the control variable is being set to True. The timer is also reset when the piston is triggered from vehicleSwitch state change to ON.