How can I make a piston block swapper that isn't flush with a wall?

Solution 1:

This seems to work, tested it with skeletons. It uses a button, but works the same

Tutorial on Youtube: Note: I did not make this redstone and i did not make this video.

Solution 2:

I've just realised there's a far easier solution to what I'm trying to do... feeling pretty silly now. Slime blocks do it all with one piston.

enter image description here enter image description here