Which ever way, rare earth, ( I would prefer ) or electromagnet, make your magnet, then use Plastidip or something similar to seal the whole thing in plastic. You can seal it as far up the cable as you feel you need. Easy to use, works good for sealing out moistures and cheap
. You can buy it at Wallyworld or Harbor Fright.