well this is off the top of my head and maybe too convoluted (but honestly kinda fun, I love making these type of switches), you can set the switch to dissolving material which will send a ball falling which has a proximity switch on it and will fall through the field of the switch which is connected to your piston. Time the fall/speed of the piston perfectly and it'll only go as far as you want it to and then stop.
edit: Kitler has found the right way to do it, but my way will look cooler. You could even put a rocket in there somewhere.
...









