Here is what I did. Take esp 8266 solder the first pin on the chip to reset so it can go to deep sleep and be woken up via an interupt. An inturupt is nothing but some Ground or Negetive voltage from battery to Reset pin.
Now once that is done, connect a battery preferably a LiPo to + and - and a magnetic reed switch to the ground of the battery and Reset of the esp.
In your sketch do everything in the setup part and nothing on the loop part. In the last line of the setup part put esp to sleep for infinity.
So now what happens is when the magnetic switch is closed there will be power going to reset pin however since its not an interuption after a while esp will go to sleep and consume very low power, but once door is open it power will get cut off and this acts like a interupt. So the sketch will load do its thing and go to sleep.
In my experience a 1000mah batter didn’t last more than 3 weeks in this setup.
You can easily revese the system to detect closing by adding one more reed switch with and gluing a magnet behind the switch so it becomes reverse.