Over the decades, we have devoted considerable time and attention to adjusting the reach and travel of the brake levers on Mary’s bike, so I ordered a pair of brake sensors for the Bafang BBS02 motor to mount on the existing hardware:

The sensor is the black block secured to the brake mount (with good outdoor foam tape), with the bar magnet similar secured to the handle. The magnet ended up slightly off-center from the switch due to the overlapping joint between the lever and the mount; I can’t detect any difference from having it centered.
The Bafang switches included cute little disk-shaped neodymium magnets which weren’t suited for the levers and stuck out in all directions without getting particularly close to the sensor. As a result, the least pressure on the brake handle produced a hair-trigger switch activation.
So I harvested two bar-shaped magnets from a defunct Philips Sonicare toothbrush head, reducing the rather large assortment I’ve been saving for just such an occasion by one item. Each brush head contains a pair magnets attached to a steel backing plate, seen here after removing the lower magnet:

I don’t know how Philips attaches the magnets, but a few shots to the steel backing plate with a drift punch breaks the bond without any obvious damage:

Neodymium magnets have a nickel plating to prevent corrosion, but AFAICT the only way to know whether I’ve cracked the plating is waiting to see if the magnet falls apart. If it does, I promise to be more careful with the next toothbrush head.
They’re magnetized through the thinnest section, not along the length like an old-school bar magnet, but the disk magnets are similarly magnetized and I think the net effect is about the same.
The bars fit the brake handles more closely, put more of the magnet closer to the switch, and allow about 5 mm of travel before tripping the switch.
Pending more road testing, the switches seem more usable.
Protip 1: Demagnetize your tools after working with neodymium magnets.
Protip 2: Don’t put a loose magnet anywhere near your bench block, because it will shatter when it snaps onto the block from a surprising distance.
A while ago I got some cheap bicycle brake-lights, so that while riding in a group the people behind would get some warning.
https://www.ebay.com/itm/313110237675 (Link just for the pictures, didn’t order from there)
They’re definitively not bright enough to work as intended, but I like the idea of putting a microswitch into a small enclosure and let the brake line activate it.
I wouldn’t want to use them for disengaging a motor, but I was thinking of using them as brake switches with a different light.
Now I’m on the fence: I like your idea with the magnet, but I also know some influential people who certainly wouldn’t react with cheers of joy, if I glued anything to her brake lever…
The new hotness seems to be a brake light with an accelerometer, but I have my doubts about how it would work on the rough paving around here: filter out the jostling and it’d light up just before I came to a complete stop.
Perhaps you could affix the switches out of sight on the bottom of the levers?
The shift sensor might actually work on a brake cable, although it’d produce a brief pulse (or several pulses?) for each complete pull. Sounds like a project to me!
Also: here we have another $1.50 item shipped halfway around the planet for free. I though that was supposed to be impossible nowadays.