Electric bicycles should turn off the motor during braking. Therefore, I have invented a method to build a switch into a brake lever; the brake lever doesn't have to be replaced and no external switch is needed.
I use Hall effect sensors as switch, because they are reliable, watertight, small, and inexpensive. Used is the SS411P, the same as the one in the PAS sensor, but almost every hall sensor may be used. The 5mm magnet comes from a PAS sensor magnet ring.
As an example, the Shimano Deore XT brake lever is taken:
We can choose between active high or active low output. Just rotate the magnet 180 degrees to change the behaviour: