A hall sensor or reed switch and a magnet. You just have to figure out where you can position them and how to fix them in place
For a hall sensor, you need three wires: two to power it (5v and 0v), which you can splice from the throttle or PAS, or you can get them from spare pads on the controller pcb. The third wire is the signal that switches on/off with the changing magnet position.
The reed switch just requires two wires. It connects them when the magnet comes close.
The sensor on a bicycle computer is a reed switch, so you can cut one off and use it as a brake switch on the back brake. You cable-tie it to the cross-bar where the brake cable is bare, and fix the wheel magnet to the cable so that it moves to the sensor when you apply the brake.