How to connect PBI to detect an open door
Security systems normally use a reed switch for this purpose.

It is usually mounted on the strike side at the top of the door to detect even a small opening of the door.

Good luck!