On door open - Logic problem

Have you considered what would happen if the door is left ajar? What if the distance is exactly 30 cm? What if the draught makes it oscillate just around the 30-cm mark?

HINT: use a reed switch instead of ultrasounds.