Sorry man, I didn’t explain it in a proper way.
Firstly I was not using the sensor as I said. I came here asking for help and Yilmazyurdakul gave a tip about adding a piece of code. I did it and somehow my circuit started working without problem for 12 hours. I turned it off and went to sleep. On the next day I added the sensor and the circuit started acting weird again, turning off right after I turn it on. So I assumed that sensors were the problem this time.
Secondly, I didn’t realize that the code was different. I was coping and pasting parts of the code from my file to this post. When I was doing this I wrote the code here without the duplicated line without realizing it.
Finally my wirings from my sensors were ok and I finally realized what I was doing wrong. As Alexis said, I started to monitor the serial. I realized that it wasn’t just the relays that were turning off, but the esp32 was turning off and on as well. I made a dumb mistake and just got it today.
My relay board has two 5v pins and a power supply born. After all I WASN’T using this power supply born. I was powering the relay board through one of those 5v pins. I was also powering the esp32 on the another 5v pin on the relay board. It comes out that those 5v pins are outputs, so I shouldn’t be powering the relay board through them. I’m now powering it properly, as well as the esp32. I’m going to leave it on as long as possible to be sure it will not turn off.