This compact and affordable door sensor mechanism uses a Hall-effect sensor fixed at the corner of the door frame and a standard bar magnet fixed on the door panel close to the Hall-effect sensor.
When looking to automate your home, a lot of the hype revolves around motion sensors and other devices, but I believe HomeKit door sensors are still some of the best devices to add to your Home ...