My wiring and voltage are correct; I’ve tested them with a multimeter. The relay also switches when GPIO02 is connected to a 3.3V source. I’ve also tried GPIO 17, but unfortunately I’ve had the same problem.
You need to format your code using the </> button as the code is not easy to read if unformated. But your code looks fine, and the messages are getting to the esp, so its a wiring issue. How are you wiring it up, if powering the relay from a separate supply the GNDs will need to be connected. I am just guessing here, so tell us a bit more and we might spot the issue.
I’ve discovered that not all the pins on my LilyGo ESP32 TDisplay can be controlled via ESPHome. Only pins 12, 13, 25 and 27. I’ve no idea what the others are used for.