This project allows you to manage an ESP32 (or similar) microcontroller by triggering specific actions in Home Assistant or by sending simple GET requests when a button is pressed.
The code for the ESP32 can be found here: Switch Controller code for ESP32.
Disclaimer: This project was built for private use, so the code might not be the cleanest.
To communicate with the Switch Controller, the ESP32 needs to send HTTP POST requests. Below are examples of how to trigger different switch actions.
# Trigger switch 1 (short press)
POST http://localhost:8080/esp
Content-Type: application/json
{
"uuid": "bd4a6037-0864-4b0e-80e1-8d1c87bf9aa0",
"friendly_name": "Küche hinten",
"ip": "192.168.101.181",
"action": "switch_1_short"
}
# Trigger switch 1 (long press)
POST http://localhost:8080/esp
Content-Type: application/json
{
"uuid": "bd4a6037-0864-4b0e-80e1-8d1c87bf9aa0",
"friendly_name": "Küche hinten",
"ip": "192.168.101.181",
"action": "switch_1_long"
}
# Trigger switch 2 (short press)
POST http://localhost:8080/esp
Content-Type: application/json
{
"uuid": "bd4a6037-0864-4b0e-80e1-8d1c87bf9aa0",
"friendly_name": "Küche hinten",
"ip": "192.168.101.181",
"action": "switch_2_short"
}
# Trigger switch 2 (long press)
POST http://localhost:8080/esp
Content-Type: application/json
{
"uuid": "bd4a6037-0864-4b0e-80e1-8d1c87bf9aa0",
"friendly_name": "Küche hinten",
"ip": "192.168.101.181",
"action": "switch_2_long"
}
This project is not intended for production use; it is meant for testing purposes only.
However, if you still wish to package it for deployment, you can run:
./mvnw clean package -Pproduction
To build and run the application inside a Docker container:
mvn clean package -Pproduction
docker build . -t switchcontroller:latest
Once the Docker image is built, you can run it using:
docker run -p 8080:8080 switchcontroller:latest