I fixed this today. I took the switch off the wall again and noticed that one of the wires had actually become very weak. I took the sheath off it and found it was about to fall apart, and the wire was all dark. So I clipped it back and rewired. It works now.