Piston that triggers only when a switch is turned off after being on for a certain amount of time?


#1

Hi again everyone!
I’ve been fiddling with this idea for the past weeks and cannot seem to let it go :stuck_out_tongue:. I want a piston that sends a notification only when a switch is turned off after having been on for a certain amount of time.

I tried this

IF Switch changes to OFF
IF Switch was on for at least 2 hours
Send notification

I also tried

IF Switch was ON for 30 seconds
followed within 1 minute by
Switch changes to OFF
Send notification

But it doesn’t work. I believe it is because in the moment the switch is turned off, it’s not considered that it has been on anymore. Not sure about this though, but my tests didn’t work. I did many tests with 15 seconds, 15 minutes and 2 hours and different setups.

I tried to understand the “followed by” logical operator and the “while loop” with no success. I read examples but in those examples there are many switches involved and the one that triggers the action doesn’t change.

I was already successful with a piston that sends the notification when the device has been on for a certain amount of time (IF switch changes to on, wait 15 minutes, IF switch is still on, send notification) but I’d really like to have one that reacts at the end of the process “looking back” at the time it was on.

I know I could use variables for this but I see there are so many tools here that I hope there is a simpler way of doing this, so I’m open to suggestions and new ideas :wink:

Thanks!
Rodrigo


#2

Hmmmm I think I made it work… The trick was the “only when”.


#3

Does anyone know if it’s safe to replace all the “ifs” with “only when” restrictions when the “elses” are not used?


#4

I would not do that.
IF’s can be triggers, but ONLY WHEN’s are more like blockades, and are unable to actually trigger pistons.


#5

Yea, totally. I actually meant in those scenarios when you’re using the IF as a “filter”.

I had this piston, you see that in lines 27 and 30 it had IFs that were only acting as restrictions.

And I changed it to this, using actual restrictions.

I just want to understand if it makes sense to use restrictions in these cases or if it could cause any other problems.

I had this other idea that I mentioned in the first post and I was only able to make it work the way I intended by using the “only when” restriction. I tried many recommendations with limited or no success, so I really liked it for these cases.

R.