Here is one that I’m currently working on for a cable brake set up, but it‘s the same for hydraulic brakes. In this case I made a small clamp for the sensor so it’s less likely to come loose. The magnets are just hot glued at the moment, so I can get the position right.
The biggest issue is trying to find a flat enough surface on the brake assembly to glue the sensor in place.
It works ok, but I’m not particularly happy with it and I will probably rework it when I can think of a better solution.
You can buy magnets with a hole in the middle so they can be secured with an M3 screw, but I don’t have any more of them.