A small maget can be used to move apart or force together electrical contacts. This can be placed inside a protective case as long as the case material doesn't block the magnetic field. These small "Reed" Relays can be very low cost, and reliable, if used propery.
Doug LaRue says:
The magnets are supposed to be positioned with their poles parallel to the direction of the reed switch. Everything I'd seen and understood over the years had one pole of the magnet pointed at the reed switch body and that is wrong. With the poles parallel to the switch body/leads it will trigger and release reliably in the same location. If you recall what I said previously, I was finding the reed switches to trigger and release at different positions.
Making a reed relay latch on or off with a few simple
components:
https://www.youtube.com/watch?v=wVxWFcHRK2I