That will not work, the distance sensor is ultrasonic (sound based) so any obstruction to sound will cause invalid readings. If you are DIY’able I have a customized firmware that supports switch or magnetic based sensors instead of the onboard ultrasonic which would make this doable, but I would not expect any official support on that configuration.
If you use a different sensor you will have to change the firmware to support that sensor. The ultrasonic distance sensor has a very particular way to read distance value, this is generally different from other sensors.
You can certainly drill a hole on the enclosure to expose the ultrasonic sensor. But I am worried that you mentioned you want to use it outdoors, so that probably won’t work as it’s not waterproof.