Hall effect switch with small magnet or if there is magnetic field around solenoid coil that the hall effect device can sense