A versatile and robust home automation relay server built using the ESP8266 microcontroller. This project provides a flexible solution for controlling electrical appliances remotely through a web interface, operating in two distinct modes: Access Point (AP) and Station (Client) mode.
- Dual Operation Mode:
- Access Point Mode: Creates its own WiFi network for direct connection
- Station Mode: Connects to your existing home WiFi network
- Web-Based Control: Intuitive web interface for relay control
- Multiple Relay Support: Control multiple relays simultaneously
- Secure Operation: Basic authentication protection
- Responsive Design: Works on desktop and mobile devices
- Real-time Status: Live feedback of relay states(coming soon)
- RESTful API: Programmatic control via HTTP endpoints(coming soon)
- OTA Updates: Over-the-air firmware updates(coming soon)
- persistent webinterface:saves the information for monitoring in EEPROM (coming soon)
- ESP8266 NodeMCU
- Relay modules (1-channel or 4-channel)
- Jumper wires
- Breadboard (optional)
- 5V Power supply
- Electrical wiring components (for appliance integration)
- Arduino IDE or PlatformIO
- ESP8266 Board Package
- Required Libraries (listed in dependencies)
| ESP8266 Pin | Relay Module | Description |
|---|---|---|
| D1 | IN1 | Relay 1 Control |
| D2 | IN2 | Relay 2 Control |
| D3 | IN3 | Relay 3 Control |
| D4 | IN4 | Relay 4 Control |
| 3.3V | VCC | Power |
| GND | GND | Ground |
-
Clone the Repository
git clone https://github.com/pakoti/awesome-smart-home cd awesome-smart-home -
Install Dependencies
- Using Arduino IDE:
- Install the following libraries through Library Manager:
- ESP8266WiFi
- ESP8266WebServer
- ESP8266mDNS
- ArduinoJson
- WiFiManager (optional)
- Install the following libraries through Library Manager:
- Using Arduino IDE:
-
Configuration Edit the
config.hfile to customize settings:// WiFi Credentials (for Station Mode) #define STA_SSID "Your_WiFi_SSID" #define STA_PASSWORD "Your_WiFi_Password" // AP Mode Settings #define AP_SSID "Relay_Controller" #define AP_PASSWORD "12345678" // Web Server Settings #define SERVER_PORT 80 #define OTA_PORT 8266 // Relay Pins #define RELAY_1 D1 #define RELAY_2 D2 #define RELAY_3 D3 #define RELAY_4 D4
- ESP8266 creates its own WiFi network
- Connect directly to "Relay_Controller" network
- Default IP:
192.168.4.1 - Perfect for standalone operation or initial setup
- ESP8266 connects to your existing WiFi
- Access via assigned IP address
- Check serial monitor for IP address
- Ideal for integration with home network
- AP Mode: Connect to
Relay_ControllerWiFi and navigate tohttp://192.168.4.1 - Station Mode: Find the IP in serial monitor and navigate to
http://[IP_ADDRESS]
- Dashboard: Overview of all relay states
- Individual Control: Toggle each relay independently
- Group Control: Control multiple relays simultaneously
- Status Indicators: Visual feedback for relay states
- Mode Switch: Toggle between AP and Station modes
- Settings: Configuration options
| Endpoint | Method | Description | Parameters |
|---|---|---|---|
/ |
GET | Web interface | - |
/api/relay/[1-4] |
GET | Get relay status | - |
/api/relay/[1-4] |
POST | Control relay | state=on/off |
/api/relays |
GET | Get all relay status | - |
/api/relays |
POST | Control multiple relays | relay1=on/off&relay2=on/off... |
/api/mode |
GET | Get operation mode | - |
/api/mode |
POST | Change operation mode | mode=ap/station |
# Turn on Relay 1
curl -X POST http://192.168.4.1/api/relay/1 -d "state=on"
# Get status of all relays
curl http://192.168.4.1/api/relays
# Switch to Station mode
curl -X POST http://192.168.4.1/api/mode -d "mode=station"The server provides a RESTful API that can be easily integrated with:
- Home Assistant
- IFTTT
- Custom mobile apps
- Voice assistants (Alexa, Google Assistant)
- MQTT clients
- Basic HTTP authentication
- special password for Doors
- Configurable access credentials
- Network isolation in AP mode
- Secure OTA updates
Edit the RelayController.h file to modify:
- Default relay states
- Timing controls
- Safety features
- Logging behavior
- Update pin definitions in
config.h - Modify web interface in
web_interface.h - Extend API endpoints in
server_routes.h
-
ESP8266 not connecting to WiFi
- Check STA_SSID and STA_PASSWORD
- Verify WiFi signal strength
- Check router MAC filtering
-
Web interface not accessible
- Verify IP address in serial monitor
- Check firewall settings
- Ensure correct port (default: 80)
-
Relays not responding
- Verify wiring connections
- Check power supply to relays
- Confirm GPIO pin assignments
-
OTA update failing
- Ensure stable WiFi connection
- Verify sufficient flash memory
- Check upload speed settings
Enable debug output by setting DEBUG_ENABLED to true in config.h:
[INFO] Starting Relay Server...
[INFO] Mode: Access Point
[INFO] AP SSID: Relay_Controller
[INFO] IP Address: 192.168.4.1
[INFO] Web server started on port 80
- MQTT support for IoT integration
- WebSocket for real-time updates
- Scheduled operations
- Energy monitoring
- Temperature sensor integration
- Voice control compatibility
- Mobile app development
- Dangerous Gas Detection
We welcome contributions! Please feel free to submit pull requests, report bugs, or suggest new features.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details.
- ESP8266 community for extensive documentation
- Arduino community for continuous support
- Contributors and testers
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Search existing GitHub Issues
- Create a new issue with detailed information
- v1.0.0 (2024-10-23)
- Initial release
- Basic relay control
- Dual mode operation
- Web interface
โญ If you find this project helpful, please give it a star on GitHub!
Disclaimer: Always exercise caution when working with electrical components. Ensure proper insulation and follow local electrical safety regulations.
