Hi, great code.
I implemented your solution and the MQTT goes to the "will" message after some seconds, I believe this is due to the usage of deepsleep.
You connect with a will message (closed), send an open message and then go to deepsleep forever. Deepsleep disables Wifi, so after some seconds the MQTT will use the will (closed) message.
How are you managing this ? is your automation based on the first open message and not of the actual current state of the window/door ?