On door open - Logic problem

So:
when distance < 30 door is open (green LED after 5 seconds)
when distance > 30 door is close (red LED)
?