I'm trying to troubleshoot the same problem. I haven't found and confirmed the solution (or even the culprit for that matter) yet, but my findings may help someone else.
I'm using the native Shelly integration in Home Assistant (not MQTT).
Using the mechanism Home Assistant uses for listening for status updates from Shelly devices, I found out that when there are these open+close state changes in HA, the Shelly DW2 sensor sends a strange update (or multiple) to the COAP server with dwIsOpened parameter set to -1 followed up by another message with a correct value (0/1).
This seems to be always immediately before a normal wakeup event (like "sensor", "temperature", or "button").
Example one - this happened automatically, looks like due to temperature sensor state change.
Der Inhalt kann nicht angezeigt werden, da Sie keine Berechtigung haben, diesen Inhalt zu sehen.
Example two - this happened when I pressed the button on the device.
Der Inhalt kann nicht angezeigt werden, da Sie keine Berechtigung haben, diesen Inhalt zu sehen.
I don't know if this behavior is normal for DW2 and should be handled by the automation system (here Home Assistant) or not, but I know there was a recent large-scope code change in the Shelly integration in Home Assistant - https://github.com/home-assistant/core/pull/52544.
I don't have any proof yet (the Pull Request is really large), but the description suggests it was a change in the integration's internal data types, which in case a boolean type (true/false) was used for the state of the DW2 sensor, a value of -1 could be cast to true an cause exactly what we're seeing. I'll be taking a closer look at this change.
The tool I used to troubleshoot it comes from aioshelly Python package (https://github.com/home-assistant-libs/aioshelly) used by HA to communicate with Shelly devices.
I ran it on the Home Assistant server itself, inside the "homeassistant" Docker container using the following command: python3 example.py -ip 192.168.1.211 .
Please note that in order to run the above I needed to unlock HA debugging and download example.py script from GitHub manually.