This PlatformIO project implements a web-based temperature control system using an ESP8266 microcontroller. It is designed to monitor temperature via a DS18B20 sensor and control a 433 MHz relay switch for heating or cooling. The system features a modern web interface for configuration, automatic/manual relay control, persistent settings, and NTP time synchronization. It is compatible with Home Assistant via MQTT and can be easily integrated into any smart home system.
-
Temperature Sensing:
Reads temperature from a DS18B20 sensor. -
Relay Control:
Controls a 433 MHz relay (for heating or cooling) with both automatic (temperature/time-based) and manual modes. -
Web Interface:
- Modern, responsive interface accessible from any browser.
- Toggle between Auto and Manual control modes.
- In Auto mode, relay is controlled by temperature and time schedules.
- In Manual mode, relay can be toggled directly by the user.
- Settings for temperature setpoint, delta, frost protection, and on/off schedules.
- Displays current temperature, relay status, and relay switch history (last ON/OFF times and ON duration).
-
Persistent Settings:
Stores user configuration in EEPROM, minimizing writes to extend EEPROM lifespan. -
Time Synchronization:
- Synchronizes time with NTP servers.
- Handles daylight saving time for Berlin timezone.
- Periodically resynchronizes every 6 hours.
-
WiFi Management:
Uses WiFiManager for easy and secure WiFi setup.
- Precise Temperature Monitoring
- DS18B20 digital temperature sensor with ±0.5°C accuracy
- Configurable temperature setpoint and hysteresis (delta)
- Frost protection with adjustable threshold
- Temperature filtering for stable readings
- Flexible Relay Operation
- 433 MHz RF relay control (supporting both ON/OFF and toggle modes)
- Configurable pulse duration for relay control
- Manual override capability
- Modern, Responsive UI
- Real-time temperature display
- Toggle between Auto/Manual modes
- Configure temperature settings and schedules
- View system status and connection information
- Mobile-friendly design
- Seamless Smart Home Integration
- Publish temperature updates at configurable intervals
- Remote control via MQTT commands
- Secure authentication support
- Command Topic:
home/temperature_control/set
- Send JSON payloads to control the device:
{ "state": "ON", "target_temp": 22.5, "delta_temp": 0.5, "frost_protection": 5.0 }
- Send JSON payloads to control the device:
- State Topic:
home/temperature_control/state
- Current device state in JSON format
- Temperature Topic:
home/temperature_control/temperature
- Current temperature readings
- Availability Topic:
home/temperature_control/status
- Reports "online" or "offline" status
- Time-based Control
- Automatic daylight saving time adjustment
- NTP time synchronization
- Persistent Configuration
- EEPROM storage for settings
- WiFiManager for easy WiFi configuration
- System status monitoring
Wire the components as shown below. A 4.7kΩ pull-up resistor is required between the DATA
and VDD
pins of the DS18B20 sensor.
ESP8266 (NodeMCU) DS18B20 433MHz Transmitter
=============== ====== ===============
3.3V VDD (Red) VCC
D4 (GPIO2) DQ (Yellow) DATA
GND GND (Black) GND
Required Hardware:
- ESP8266 (NodeMCU, Wemos D1 Mini, etc.)
- DS18B20 Waterproof Temperature Sensor
- 433MHz RF Transmitter Module
- 433MHz Relay Switch
- 4.7kΩ Resistor
- Breadboard and jumper wires
- 5V Micro-USB Power Supply
This project is configured for PlatformIO.
- Clone the Repository:
git clone <repository-url> cd ESP8266-Temperature_Control
- Open in VS Code: Open the project folder in Visual Studio Code with the PlatformIO extension installed.
- Build & Upload: Use the PlatformIO controls to build and upload the firmware to your ESP8266. All dependencies listed in
platformio.ini
will be downloaded automatically.
- On the first boot, the ESP8266 will create a WiFi Access Point named
ESP-Temp-Control-AP
. - Connect to this AP with your phone or computer. A captive portal should open automatically.
- Select your home WiFi network (SSID), enter the password, and save.
- The device will restart and connect to your network. The IP address will be printed to the Serial Monitor.
- Find the ESP8266’s IP address from your router or the Serial Monitor.
- Open the IP address in a web browser to access the control interface.
- Use the web UI to configure temperature setpoints, schedules, and control modes.
This project is built using the PlatformIO framework. All required libraries are managed via the platformio.ini
file and will be downloaded automatically during the build process.
- Framework:
arduino
- Libraries:
OneWire
&DallasTemperature
— For the DS18B20 sensor.RCSwitch
— For 433 MHz RF communication.WiFiManager
— For easy WiFi configuration.PubSubClient
— For MQTT integration.- Core ESP8266 libraries (
ESP8266WiFi
,ESP8266WebServer
,EEPROM
,time.h
).
src/main.cpp
: The main application logic.setup()
: Initializes hardware, loads settings from EEPROM, connects to WiFi (using WiFiManager on first run), sets up NTP, and starts the web server.loop()
: Handles web server clients, periodically reads the temperature, executes control logic (auto/manual), and handles NTP resynchronization.
- Web Handlers: Functions like
handleRoot()
,handleSettings()
, etc., respond to HTTP requests. - Control Logic: The core logic for temperature and schedule-based relay control resides within the
loop()
. - EEPROM Management: Functions to read and write settings, designed to minimize wear.
- The web interface is not password-protected by default. If the device is accessible from an untrusted network, it is recommended to implement authentication for the web server.
- Pin Assignments: Modify the pin definitions at the top of
src/main.cpp
for different hardware layouts. - Relay Protocol: Adjust
RELAY_CODE_ON
,RELAY_CODE_OFF
, and otherRCSwitch
parameters for your specific 433 MHz relay. - Timezone: Change the
TZ_INFO
string for your local timezone.
To integrate this device as a generic_thermostat
in Home Assistant, you can use a package file.
- Create a file named
thermostat_package.yaml
in your Home Assistantpackages
directory. - Add the following content to the file, updating MQTT topics if you changed them.
- Include the package in your
configuration.yaml
:
# filepath: configuration.yaml
homeassistant:
packages:
thermostat: !include thermostat_package.yaml
This project is open source and provided as-is, without warranty.
Feel free to modify and adapt it to your needs!