Detecting if switch is closed?
Consider using the HCPL-3700: -



But there are many other opto-coupler solutions that are out there and all give you a safe isolated signal like this one: -



Or the ACPL-K370