Skip to content

gitos-h/ESP8266-Temperature_Control

Repository files navigation

ESP8266 Temperature Control System

Overview

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.


Features

  • 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.

🌡️ Core Temperature Control

  • 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

⚡ Relay Control

  • Flexible Relay Operation
    • 433 MHz RF relay control (supporting both ON/OFF and toggle modes)
    • Configurable pulse duration for relay control
    • Manual override capability

🌐 Web Interface

  • 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

🤖 MQTT Integration (Home Assistant Compatible)

  • Seamless Smart Home Integration
    • Publish temperature updates at configurable intervals
    • Remote control via MQTT commands
    • Secure authentication support

MQTT Topics

  • 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
      }
  • 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

⏰ Smart Scheduling

  • Time-based Control
    • Automatic daylight saving time adjustment
    • NTP time synchronization

🔄 System Management

  • Persistent Configuration
    • EEPROM storage for settings
    • WiFiManager for easy WiFi configuration
    • System status monitoring

🚀 Getting Started

1. Hardware Setup

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

2. Software Setup & Upload

This project is configured for PlatformIO.

  1. Clone the Repository:
    git clone <repository-url>
    cd ESP8266-Temperature_Control
  2. Open in VS Code: Open the project folder in Visual Studio Code with the PlatformIO extension installed.
  3. 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.

3. WiFi Configuration

  • 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.

4. Usage

  • 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.

Dependencies

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).

Code Structure

  • 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.

Security

  • 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.

Customization

  • 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 other RCSwitch parameters for your specific 433 MHz relay.
  • Timezone: Change the TZ_INFO string for your local timezone.

🔌 Home Assistant Integration

To integrate this device as a generic_thermostat in Home Assistant, you can use a package file.

  1. Create a file named thermostat_package.yaml in your Home Assistant packages directory.
  2. Add the following content to the file, updating MQTT topics if you changed them.
  3. Include the package in your configuration.yaml:
# filepath: configuration.yaml
homeassistant:
  packages:
    thermostat: !include thermostat_package.yaml

License

This project is open source and provided as-is, without warranty.
Feel free to modify and adapt it to your needs!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published