Create an Off/On Action after n Minutes Only if Switch Still On


1) Give a description of the problem
As title suggests I want to cycle a switch off then on after a period of time (to defeat a plugged in fixture’s inbuilt off timer).

2) What is the expected behavior?
If a switch is turned on by any means I want to start a timer for 345 minutes then when that timer runs out turn the switch off then on but only if the switch is still on at the expiry of 345 minutes. Each time the switch is turned on (even if not by this piston) the timer should restart.

3) What is happening/not happening?
I have so far not been able to figure out the ‘only if switch still on’ part which is killing me as I know this should be simple.


Well, the piston will cancel if it is turned off, since that is a conditional state change. I also don’t understand why you’d need that restriction. If the switch is off, you can’t turn it off again. It’s off. So, what difference does it make? Maybe you need a better description of what you’re trying to accomplish or post a piston snapshot.


Reading your reply I see your point and I now see my error.

I had TCP set to never (hold over from some testing I was doing). I remember watching the trace and seeing the piston registering the switch being turned off by other means and I thought the timer was cancelling too as the counter disappears in the trace (until it runs down). I didn’t test throughly enough to notice the timer was in fact still running due to the TCP setting.

All good now.

Now I shouldn’t wake up at 3am to a 6 foot nutcracker delivering an LED light show in my house.


I think this should be what you are looking for.

Change the wait time to your desired time.

The Boolean variable is there to detrmine if the piston wait is active. If it is, it will turn the light back on and wait will reset. If it is not, the light will shut off and not come back on. Also, if the light was off and the Boolean variable is false and the light turns on, the process starts over.



This doesn’t do what I need though. I want the piston to cycle the switch off then at the end of the timer. If the switch is turned off separately then that should end the timer/cancel the wait.

I am currently using this simple approach although last night I think the timer canceled somehow as it went off after 345 minutes and did NOT come back on. As noted above, if the switch is turned off outside of this then the piston simply cancels which is the desired result. Note, the 5 seconds wait is there simply to give ST enough time to register the status change of the switch.


I might have over-simplified it, but I think this will do what you’re after:


I’m giving it a whirl. Thanks.

Unfortunately this and my other attempts occasionally hiccup when ST does not update status quickly and the piston thinks the switch is still on so the on after the off does not fire. I know I can switch off Command Optimization but that’s at the piston level and I don’t want that for the rest of the piston so I’m going to move this out to it’s own piston.


I went with the below in the end. The problem I was having as I mentioned earlier is ST has been slow updating status for this switch. With Command Optimization set to off it doesn’t help as even though the webCoRE generated ON after OFF will be forced, if the switch does not actually turn OFF then back ON it won’t reset the timer on the attached device. So, by making the piston effectively wait for the switch status to actually show OFF I get what I need.


Good way of doing it!