
I will show here the configuration and operation of the window / door opening sensor in OpenBeken , realized without TuyaMCU, i.e. based on the deep sleep of the WiFi module. The sensor implemented in this way connects to WiFi only when you need to send a state change to the MQTT server, otherwise it "falls asleep" and disconnects from the network, entering a state of very low power consumption. Only events on the pins, i.e. pressing the configuration button or changing the state of the door/window, can wake it up from this state.
Configuration in OpenBeken
The configuration here is intended for sensors of this type (photo from the user):
miroww1 wrote:
Everything is run automatically, the user only needs to set the role of the sensor pin to DoorSensorWithDeepSleep . In addition, we set the role for the configuration button button . For the door sensor, set the channel, e.g. the first one, for the button the second channel.

You don't need anything else.
After reboot we will see:

The sensor will "go to sleep" after this time:
Door: time until deep sleep: 11
Changing the door state resets this time, the countdown starts again.
The sensor can wake up both the change of the door status and pressing the button.
Starting an OTA (WiFi update) also blocks sleep.
Lack of connection with MQTT also blocks sleep, but only for 300 seconds (the value will be changed in the configuration):

The delay is to ensure that the sensor has time to report its status to the MQTT before bedtime.
Current consumption during WiFi operation (occasionally ranges from 50mA to 150mA):

Power consumption while sleeping:

Presentation of the action on the video
I do not have this type of sensor, so I simulated it by connecting a switch.
The video shows the WiFi module, a switch (simulating a door opening sensor), an ammeter and a telephone, where you can see how the page counts down the time until sleep is turned on.
Wakeup works in both cases - both when "door is closed" and when "door is open".
The video also shows how the power consumption changes, I recommend enlarging the video.
And what does the sensor based on TuyaMCU look like?
It is worth noting that the sensor based on TuyaMCU has already been described. The description is here:
https://www.elektroda.com/rtvforum/topic3914412.html (English)
https://www.elektroda.pl/rtvforum/topic3914412.html (Polish)
Such a sensor is characterized by the presence of the MCU on the PCB:

In his case, the TuyaMCU (microcontroller) handles the power supply of the WiFi module and the WiFi module is completely turned off through the transistor. He cuts off his power. This is different than the sensor from the topic. Here we see two different Tuya approaches to saving energy. One uses low power MCU and the other uses deep sleep on the WiFi module itself.
Both approaches are supported by OpenBeken.
Home Assistant setup
Make sure this flag is checked:

Set MQTT data in Config:

If the device wants to turn off during setting, then either turn off the door controller with the command stopDriver DoorSensor or simulate door opening/closing.
Do a Discovery here:

The device will add itself to Home Assistant if there is already an MQTT connection.


Configuration summary
To sum up, to configure such a sensor you should:
1. Upload OpenBeken to it
https://github.com/openshwprojects/BK7231GUIFlashTool
2. Configure WiFi and MQTT data
3. Set the Button role for the configuration button, channel 1, and the DoorSensor role for the door sensor, channel 0 (you can also try the nPup version, i.e. without the pull up resistor)
4. Perform MQTT discovery:
https://www.youtube.com/watch?v=pkcspey25V4&ab_channel=Elektrodacom
Ready! Now you just need to remember that if you don't want the sensor to go to sleep during configuration, you have to either change the door state, or press the button, or send it the "stopDriver DoorSensor" command.
Summary
The deep sleep mode with waking up by changing the pin state is necessary in window/door opening sensors implemented without TuyaMCU. Without this mode, the battery would probably discharge in less than a day, maybe the dynamic energy saving mode (PowerSave 1 command) would help a little, but probably not much.
One downside to deep sleep is that the door sensor must first connect to WiFi and MQTT before reporting its status, but I don't know what to do about that. The delay is acceptable.
The configuration of such a sensor in OpenBeken is very simple, you do not need to write any scripts, and Home Assistant Discovery helps you connect it with Home Assistant just as easily.
PS: The topic was created, among others. on user requests from these topics:
https://www.elektroda.com/rtvforum/topic3959677.html
https://www.elektroda.com/rtvforum/viewtopic.php?p=20450113#20450113
Cool? Ranking DIY