The loft hatch is essentially a specialist type of door and we have a specialist kind of door contact sensor on it. It marks the boundary between two zones and we can use it's state to control the lighting in our loft automatically.
For the best possible reliability and performance, we are using a wired sensor. It requires no batteries and also has very low latency, resulting in the best possible user experience.
In our current home we are using a cheap reed switch mounted invisibly in the loft hatch frame and a magnet hidden in the hatch itself. These things are incredibly reliable and will last for decades.
This is connected to our contextual smart home via and Arduino processor.