Control a WiFi power socket switch from an ESP32 used as access point
This example demonstrates how to connect a WiFi power socket switch to an ESP32 working as a WiFi access point and as HTTP client. A button connected to the ESP32 toggles the switch state variable, which is indicated by a LED connected to the ESP32. When the button is pressed, the ESP32 sends an HTTP request to the power socket switch to change its state accordingly.
This should work with any power socket switch running Tasmota. Tested with Delock 11826.
You can implement your own logic to control the switch, e.g. based on a sensor value.
Multiple WiFi devices can connect to the ESP32's access point - this allows you to extend this sketch to control multiple power socket switches.
Warning
Assess the risks of controlling a power switch via a potentially unreliable and insecure WiFi connection. Read the MIT License.
- The ESP32 provides a WiFi access point (SoftAP)
- Configure your WiFi power socket switch to connect to the ESP32's access point (see SSID and password in the sketch)
- Configure the URLs for the power socket switch in the sketch
- If available, use the ESP32 dev board's user button, otherwise connect a button to a GPIO pin
- If available, use the ESP32 dev board's built-in LED, otherwise connect a LED to a GPIO pin
- Wait until the power socket switch has connected to the access point
- When the button is pressed, the switch state variable and the LED state are toggled and an HTTP request is sent to the power socket switch to turn it on or off