I previously used headlights meant for strapping directly to your head with a headband, and wrapped it through the holes in my helmet. But this adds risk of injury in a crash if the lights or band get caught in something. So I decided to make my own breakaway lights using magnets.
I took a pair of Topeak Headlux lights, removed the rubber cup, filled it with polyurethane Seam Grip, stuck a 20x3mm neodymium magnet into the wet urethane, let it dry overnight, and then taped it over.
However, the magnets became loose after a few weeks. It seems that the urethane shrunk and formed a concave surface, which detached itself from the magnet. Or else the urethane doesn't really stick to metal. Although it did help form a socket. I cleaned the magnet with alcohol, and then put 2 component epoxy glue into the socket, reinserted the magnets, and let the glue dry overnight. Hopefully the magnets won't fall out again.
For a few times, I accidentally placed the magnets in my hand near metal objects, and they quickly flew into my fingers. Luckily, I had kept the knives and scissors far away beforehand. I wanted a way to store the lights safely when they're off the helmet, so I 3D printed thick plastic cups, with male and female chamfered edges to keep them from sliding off each other. It forms a 10mm gap around the magnets. Small and light metal objects still have a slight magnetic attraction, but the force is very weak.
If you want the 2 lights to attract each other, you'll need to have one magnet with north facing down, and the other magnet with south facing down (polar opposites). Otherwise if both magnets have the same polarity, they'll repel each other.
On the helmet, I also used Seam Grip to attach 24mm diameter washers to areas that were directly above voids in the helmet that aren't in direct contact with my skull (in case the lights smash through the helmet). I then used some Tenacious Tape over the washers, but duct tape probably works too. Since urethane doesn't really work with metal, the washers will probably detach in the future. When they do, I'll just use double sided tape, applied with concentric layering in order to achieve a sort of dome shape to adhere to the convex surface of the helmet.
The washers need to be larger than the magnets, otherwise the magnets will not center themselves to the washers. If the washers are smaller, then the magnets will move to the edge of the washers.
Although the magnets are rated at around 4kg perpendicular pull force, it's more like 1kg vertically, and 250g horizontally. If I orient the helmet sideways and place a 300g saddle on the edge of the lights, the magnets will slide off. It's probably weakened from the 0.5mm gap from the 2 layers of tape, and maybe the hole in the middle of the washer (not sure about this). It's not as strong as I would like, but the lights haven't fallen off yet during rides. If I shake the helmet lightly, the magnets will not detach. However, if I grab the helmet in my hands above my head and throw it very hard toward the ground without letting go, the magnets will slide off.
I could increase the magnetic force by double stacking 2 magnets together, but there is a higher risk of injuring my fingers against sharp metal objects that become attracted to the stronger magnetic force. So I decided to use only 1 magnet per light.
One way to increase the sideways break force is to make the 3D printed cups with protruding lips that surround the edges of the washers, to capture the washer. But I didn't want to peel back the tape that I already placed on the washers, which help to keep them from detaching from the urethane. I also didn't want the residual solvent from the urethane to seep into my hair when it rains.
Attaching anything to the outside of your helmet has a risk of injury or death. I am not endorsing it. You do so at your own risk.