EDIT: this first post was about a prototype magnetic contact sensor for a sliding patio door LOCK. See post Prototype contact sensor for sliding patio door LOCK - #8 by John_Land below for my 2nd (improved) prototype based on a water leak sensor.
Below are pictures of a prototype of a patio sliding door contact sensor apparatus for detecting a locked-unlocked condition (this is different from determining door open or closed). This was inspired by another user's solution for a Pella slider that allows a different approach.
The first picture shows the locking mechanism of the slider door in the "locked position". In the unlocked position, the "hook" drops down and retracts into the door.
The second picture shows a standard pencil with a magnet hot-glued to the non-eraser end, while the eraser end is placed within the raised latch channel that the "hook" engages when locked. O-rings are used to limit travel in both directions, and a plastic cable/wire guide is used to hold and guide the pencil.
The magnetic sensor is an Aqara Zigbee unit with a bit of loop material glued to the back, which engages a 3M hook strip adhered to the door frame. Using hook-and-loop materials allows resettable positioning of the Aqara unit. The Aqara sensor is the smallest and thinnest magnetic contact sensor that I've come across and JUST fits depth-wise within the channel of the slider door frame.
The upper O-ring prevents the magnet from pulling too close to the sensor (and sticking to it) by hitting the bottom edge of the guide. The weight of the pencil helps to pull the magnet away from the sensor when the door is unlocked (so no spring needed).
This works tolerably well, but the spacing of magnet and sensor is touchy. There appears to be a bit of hysteresis in the spacing engagement, with the magnet having to move further away from the sensor to register open then the magnet had to move to register closed (e.g., 1/8" closer from rest to be CLOSED, but 1/4" away from the CLOSED position to be OPEN). The door "hook" provides just about 1/4" of upward travel so the spacing can be set to work.
The Aqara sensor sits in an aluminum channel and the face of the slider door frame is steel, so the signal is weak. I have 2 Zigbee in-wall switches just inches from the sensor, so I do get a signal.
I'm hoping that this jury-rigged setup will inspire some other solutions (including commercial solutions). I think a micro-switch plunger protruding into the latch channel and integrated into a small housing with a Zigbee radio (maybe with an external antenna wire?) would be a more elegant and reliable solution.