WiFi Programmable Thermostat

 

Introduction

The goal of this project was enabling smart management of my home comfort from anywhere. This is monitoring or adjusting heating temperatures via computer, smartphone or tablet, so being able to check the heating status, change target temperature or the daily and weekly programming using a user-friendly interface. A secondary, but equally important goal of the project was the thermostat exterior design and the solution engineering. I wanted the electronic circuit to fit the size of a masonry wall box and the human interface (display and commands) to fit the shape and the size of some civil series. The final result is the following:

Project components

The thermostat is based on the well-known ESP8266 which includes a built-in Wi-Fi controller and very good computational capabilities with 80Mhz clock CPU, 80Kb of RAM and 4Mb flash storage for program code and data.

The project hardware includes a sensor to monitor ambient temperature and humidity) and a subminiature power latching relay to switch heating on or off.

The thermostat human interface includes a small 1.3″ OLED display to show the basic information like temperature, humidity, working mode and status. A small 5-way joystick is used to interact with the thermostat local interface for example to change the working mode and modify various thermostat configuration options.

A small SMPS provides the regulated 3.3v source required to operate the ESP8266 and all the other components.

Other than the local interface, the thermostat can be monitored and configured remotely using a web application interface. Advanced configuration options like changing the daily and weekly temperature programming are only available using the web interface.

Thermostat block diagram

Following picture shows the thermostat block diagram:

The I2C bus connects the temperature/humidity sensor, the OLED display and the 5-way joystick to the CPU. The latching relay is connected directly to the CPU using two control pins (to switch the relay contact ON or OFF – double coil relay) and a feedback pin. The feedback pin is used to check the relay status at system startup and verify that the latching relay contact is switched on the correct position (see “Latching Relay Status Feedback Management” section later on for details).

The thermostat features are the following:

  • Operating mode:
    • Auto: the thermostat automatically switches the heating system on or off comparing the ambient temperature and the target temperature set by the user.
    • Away: the thermostat normal status is off but it switches on the heating system if ambient temperature goes below the freezing temperature which is set to 5 degrees Celsius.
    • Cleaning: the thermostat switches off for 3 hours from the moment this mode is activated and then reverts back to the Auto mode. This is especially useful to avoid the heating system to switch on in winter time when opening windows during housekeeping time.
    • Manual: the thermostat is activated manually setting the target temperature to the desired value.
    • Off: the thermostat is switched off.

When is Auto mode, the target temperature is set according to a program of the day which defines the target temperature with a resolution of 30 minutes. There are up to three different programs that can be set and associated with the days of the week. Usually, just two programs are used one for Monday to Tuesday and the second program for the weekend. A third program is available for different needs.

User interface

The thermostat is connected to internet through the home Wi-Fi connection. Programming the thermostat can be done either by the local interface (thermostat joystick on the right hand side of the display) or the remote web interface. The local interface allows the user to switch between the different operating modes and change main settings of the thermostat. The web interface allows the user to monitor the thermostat status, change the operating mode or modify the weekly programming used by the Auto mode. Web interface interaction with the thermostat make use of the long polling technique (see “Remote Interface Interaction” section below for details).

Some features are only avaliable by the local or remote interface, here is the list:

FeatureLocal InterfaceWeb Interface
Change operating modeXX
Set target temperature in manual modeXX
Change weekly programsX
Associate Weekly program to DaysX
Adjust thermostat internal configuration parametersX
Monitor ambient temperatureXX
Monitor ambient humidityX
Advanced monitoring of temperature/humidity history (day/week/month/year)X
Set target end of time in cleaning modeXX
Table 1. Local vs. Web Interface

The local interface has two pages:

  • Main screen: here you have the time on the upper left corner, then some icons showing the heating status (on/off), the Wi-Fi connection status. The target temperature is on the upper right corner while current temperature is at the center of the display. Finally, on the bottom you can see the operating mode.
  • Settings screen: here you can change the internal configuration of the thermostat. These include:
    • Hysteresis: this is the minimum difference between the target temperature and current temperature that must exist to switch heating on again after the target temperature has been reached.
    • Contrast: the display brightness
    • Temp. ADJ: this is the temperature adjustment offset from -2 to 2 degrees Celsius used for temperature sensor fine tuning.
    • Reset WiFi: to restart Wi-Fi and put the thermostat in hotspot mode. This way, you can connect a smartphone or tablet to the thermostat and enter Wi-Fi connection parameters (ssid, key).
    • Language: the local and remote interface display language. English and Italian are supported, more to come.
    • Relay Test: used to force the heating relay on or off for testing purposes.
    • Reset: to restart the thermostat.

To enter the settings page from the main page you need to keep the joystick button pressed for more than 3 seconds.

On the settings page you can browse the configuration options up and down using the joystick. Once you have selected the desired option you can enter into the change mode moving the joystick in the right direction. When the option value is highlighted you can change its value moving the joystick up and down. To leave the change mode just move the joystick in the left direction.

To go back to the main page keep the joystick pressed again for more than 3 seconds.

Here are the screenshots of the display pages:

Main display page
Settings display page

The web interface has three tabs:

  • Home: here you can set the operating mode, check ambient temperature and humidity, explore their trend through an interactive graph (pan/zoom) over the last day/week/month/year
  • Week: here you can switch the program associated to the days of the week
  • Programs: here you can change the daily program setting the desired temperature for each time of the day. You can set up to three programs and the time resolutiin is 30 minutes.

Here are the screenshots of the tabs:

Home tab

The operating mode is selected using the button on the upper left side. When the operating mode is manual, the slider can be used to set the target temperature.

On the center of the page you have the heating status (on/off) and ambient temperature and humidity. On the bottom of the page, the temperature and humidity graph is interactive. You can select the reference period using the button below the graph and then pan and zoom on the time axis to refine the analysis window.

Week tab

The week tab is very simple you can select the program applied to each day of the week.

Programs tab

On the top of the page you can select the program to be configured. The bar graph allow you to set the target temperature at every time of the day. You can focus a specific period of the day using the buttons below the graph, then you can pan and zoom on the time axis to focus on specific hours of the day. Finally, clicking on the graph you can adjust the target temperature.

Thermostat internals

The thermostat is composed by the controller board, the i/o board which embeds the temperature and humidity sensor and the OLED display.

Following picture shows the main board in a early stage of the assembly. The size of the board is 68mm x 48mm:

Main components of the board are the (1) AC-DC SMPS converter (Hi-Link HLK-PM03 – see ref. [1]) that provides 3.3v regulated output, (2) the ESP 12-F WiFi module based on ESP8266 CPU (see ref. [2]) and (3) the latching relay that provides NO/NC contacts to switch the heating system on or off.

Latching relay is the subminiature dip relay HFD2-003-S-L2 (see ref. [3]) which has double coil and a nominal voltage of 3v. It can switch 125Vac/1A resistive load while the maximum rating is 220Vac/250Vdc at 3A. This is more than enough to drive typical heating system switching contact that is usually either a mechanical or solid-state relay. This latching relay offers two contacts, the second one is used to check the status of the relay and detect possible switching failures.

The I/O interface is composed by the joystick and the temperature sensor. This is connected to the main board using the I2C interface. The joystick has five contacts, one for the push button and four for the move directions. The joystick contacts are connected to the I2C bus using PCF8574 Remote 8-Bit I/O Expander (see ref. [4]). The temperature sensor is the well-known Bosh BME280 (see ref. [5]) which provides a native I2C bus connection. Here is a picture of the I/O board.

I/O board front view
I/O board back view

The back side of the board hosts the PCF8574 IC and two I2C connectors, one is used to connect the I2C bus to the main board and the other one is used as I2C bridge to the OLED display. Please, note that the I2C connector to the main board has an additional interrupt pin to notify a change of the joystick status and avoid polling for I/O changes. This is provided directly by the PCF8574 IC.

Finally, the display is an 1.3″ monochrome OLED with I2C bus interface based on SSD1306 IC (see ref. [6]) that can be found for a few coins on many e-commerce sites:

1.3″ Monocrome OLED display

Remote Web Interface and local interface Interaction

Following diagram shows the interconnections between a remote web interface (operated by the Smart Client), the local thermostat interface and the central components (API Server, Web Server and configuration database):

The pages of the remote web interface are provided by the Web Server. The API Server exposes web services to update the thermostat configuration parameters, read the current configuration and poll for configuration changes. Configuration is stored both remotely in the configuration database and in the local thermostat flash storage. Web pages downloaded bu the Smart Client embed the JavaScript code that interact with API Server to read the current configuration, check for configuration changes or update the configuration in case the user changes thermostat parameters (e.g. the operating mode or the target temperature). Configuration changes can be originated either from the Smart Client via the web interface or from the Chrono Thermostat via the local interface. In both cases, the new configuration is first sent via the API Server to the configuration database and then propagated to the other party.

To check for configuration changes both the remote web interface and the thermostat local interface make use of the Long Polling technique. Basically, the client makes an asynchronous call to the API Server which lasts up to 10 seconds (maximum polling interval). In case the configuration doesn’t change during the polling interval, a “no configuration change” response code is sent to the client at the end of the interval. If a configuration change is detected during the polling interval a “configuration changed” is immediately returned to the client along with the new configuration. This way, the frequency of the polling is highly reduced with respect to the continuous polling techniques (in case of no configuration changes, the frequency will be 6 pools for minute with 10 seconds polling interval), while the client is notified almost immediately when the configuration changes.

Next Steps

Possible evolutions of this project include:

  • Using Web Sockets in place of Long Polling for remote interface interaction will remove the need of the central configuration database. In this scenario, the remote interface would interact directly with the thermostat.
  • Adding a 868/433Mhz radio module (e.g. LoRa Ra-02 or similar) would allow the thermostat to act as a central hub for peripheral automation modules. For example, controlling thermal actuators, additional temperature/humidity monitoring devices, irrigation valves, and so on. Using low power radio will allow the peripheral devices to be battery powered.
  • At present, the thermostat retrieves current time from NTP servers once it is connected to internet. It does not startup until current time is set. In case of temporary power outage, if the internet connection is not reestablished, the thermostat will not work. Adding a RTC (Real Time Clock) module with a backup battery to keep time synchronized would solve this problem.
  • In addition to multi-language support, it would be useful adding some localization features like Celsius vs. Fahrenheit and different time formats

References

[1] HiLink. HLK-PM03 3.3V 3W Power module description and Datasheet. , 2020 rev. 1.01.
[Bibtex]
@hlk_pm03{hlk_pm03,
author = "HiLink",
title = "{HLK-PM03 3.3V 3W Power module description and Datasheet}",
year = "2020 rev. 1.01"
}
[2] Ai-Thinker Technology. ESP-12F WiFi module. , 2018.
[Bibtex]
@hlk_pm03{esp_12f,
author = "Ai-Thinker Technology",
title = "{ESP-12F WiFi module}",
year = "2018"
}
[3] HONGFA. HFD2 Subiminiature DIP Relay. , 2020 rev. 1.01.
[Bibtex]
@hfd2_003_S_L2{hfd2_003_S_L2,
author = "HONGFA",
title = "{HFD2 Subiminiature DIP Relay}",
year = "2020 rev. 1.01"
}
[4] Texas Instruments. PCF8574 Remote 8-Bit I/O Expander for I2C-Bus. , 2015 rev. J.
[Bibtex]
@pcf8574{pcf8574,
author = "Texas Instruments",
title = "{PCF8574 Remote 8-Bit I/O Expander for I2C-Bus}",
year = "2015 rev. J"
}
[5] Bosch. BME280 Combined humidity and pressure sensor. , 2018 rev. 1.6.
[Bibtex]
@bme280{bme280,
author = "Bosch",
title = "{BME280 Combined humidity and pressure sensor}",
year = "2018 rev. 1.6"
}
[6] Solomon Systech. 128×64, Dot Matrix OLED/PLED Segment/Common Driver with Controller. , Sep. 2019.
[Bibtex]
@ssd1306{ssd1306,
author="Solomon Systech",
title = "{128x64, Dot Matrix OLED/PLED Segment/Common Driver with Controller}",
year = "Sep. 2019"
}

Solar Heating Controller

It is a solution for the integrated management of a solar thermal system and a gas boiler for the production of domestic hot water. It allows you to optimally manage the flow of hot water produced by the solar thermal panels, to limit or exclude the intervention of the gas boiler in the summer time and use the gas boiler just to integrate the thermal panels when the solar radiation is not enough to guarantee the minimum temperature required for the consumption of sanitary water. It is composed by a sensor, positioned near the solar tank, which measures the water temperature and transmits it to a central unit located near the gas boiler. The central unit, depending on the exchange temperature configured by the user, decides whether to deviate the flow of hot water from the solar tank directly to the sanitary consumption or send it through the boiler to integrate the thermal energy and therefore the water temperature at the desired level. A three-way valve is used to deviate the flow of the water and works in two positions:

  • Bypass position: when the temperature of the solar storage tank is higher than the exchange temperature, the flow of hot water from the solar tank “bypasses” the boiler which remains inactive for the production of sanitary water
  • Integration position: when the temperature of the solar storage tank is lower than the exchange temperature, the flow of water (preheated) coming from the solar tank is passed through the boiler which raises the water temperature to the desired level.

The sensor is powered by a solar cell and a backup battery and transmits data to the central unit via radio at the frequency of 433Mhz.

The central unit controls the exchange valve and decides the direction of the hot water flow comparing the temperature of the water in the solar tank received by the sensor and the exchange temperature configured by the user.

In addition, the central unit collects external environmental information such as temperature and humidity and checks the filling status of the tank used to collect the condensate produced by the gas boiler (in case of condensing boilers without free drain).

The central unit can be connected to the home WiFi network to transmit the system operating information to the Internet for remote monitoring purposes.

Sensor

Here follows the block diagram of the sensor:

Sensor block diagram

Diagram includes:

  • Central Processing Unit (CPU)
  • 433Mhz radio communication module with antenna
  • External temperature sensor (to measure the water temperature in the tank)
  • Internal temperature sensor
  • Battery current and voltage sensor
  • Backup battery
  • 5v regulated output UPS module
  • 3.3v voltage regulator

The sensor is hosted inside a waterproof box with a transparent cover. A photo voltaic module is placed just below the cover and generates the electricity required by the electronic board. A UPS module and a backup battery complete the power supply section to ensure that the sensor can continue to transmit data for several days even in the absence of sufficient solar radiation.

The temperature of the water in the solar tank is measured by a probe based on the Dallas DS18B20 sensor.

The temperature data as well as other internal operating parameters of the sensor (battery level, charge / discharge current, internal temperature of the box), are transmitted to the central unit using the radio module with a transmission frequency of 433Mhz.

The following figure shows the sensor electronic board.

The component (1) is the heart of the board and is based on the Atmel ATmega328p microcontroller produced by Microchip Technology (ref. [1]). The component (2) is the LoRa Ra-02 data transmission module produced by AI-Thinker and based on the SX1278 chip (ref. [2]) working at the frequency of 433MHz. The component (3) is the UPS module connected to the photo voltaic module and to the backup battery, providing the 5V regulated power source required by the electronic board.

The board is also equipped with two optional components: the first (4) is an instrumental amplifier used to measure the current flowing to and from the backup battery. Current intensity and direction are used to to determine the State of Charge (SoC) of the backup battery. The intensity of the battery charge current is also a good indicator of the intensity of solar radiation and can be used for environmental monitoring. The second optional component is a temperature sensor, based on the MCP9700 active thermistor produced by Microchip Technology (ref. [4]) that can measure temperature in a wide range going from -40 to 125 ° C with good accuracy in the typical operating range of this device (-10 to 50 ° C). This sensor is used to measure the internal temperature of the box hosting the electronic components to check the operating limits and adjust the sensor operating parameters according to the temperature.

The following figure shows the housing of the electronic components inside the box.

Figure 2. Sensor box – internal components disposition

In the electrical box, in addition to the sensor control board described above, there is the backup battery (1). This is placed inside a cylindrical aluminum container anchored to the electrical box by PVC clips and is connected to the control board through a protection circuit to prevent excessive charge / discharge of the battery (2). The temperature sensor (3) is inserted inside a waterproof capsule and connected to the control board by an electric cable. The cable outside the box is protected by a steel coating tube. Here, a simple shower hose was used to protect the integrity of the cable from the external agents (rain, ice, snow, UV radiation, …).

The battery is kept on charge by a photo-voltaic panel placed below the transparent lid of the box (figure 3).

Figura 3. Pannello solare per la ricarica della batteria

Inside the box, under the photo-voltaic panel, an MDF panel suitably shaped and sealed with silicone at the edges, creates a sort of interspace between the photo-voltaic panel and the lower part of the box hosting the electronics (figure 4).

Figure 4. Lower side of the box cover.

Not visible in the figure, the interspace has been filled with foam to obtain a thermal insulation between the lid and the lower part of the box to limit the temperature rise in summer time when the solar radiation is very intense.

In the final assembly, the sensor box is positioned on the roof next to the hot water tank. The capsule with the temperature sensor is inserted in a cockpit placed on one side of the tank (generally hot water tanks are equipped with a cockpit for analog temperature probes – in this case the analog probe can be removed and replaced with the digital probe).

Central unit

The central unit is the heart of the solution. Here follows the block diagram:

Central unit block diagram

The diagram includes:

  • Central processing unit (CPU)
  • 433Mhz radio transmission module and antenna
  • 2.4GHz WiFi connection module and antenna
  • 16×2 characters LCD Display module
  • Relay module used to control the flow switch valve
  • External humidity and temperatyre sensor
  • Weight sensoe
  • Multifunctional push button
  • Status/Power leds
  • 5v and 3.3v voltage regulators
  • 12v exernal power supply

The following figure shows the front panel of the control unit:

Figure 5. Central unit front panel

The electronic components are hosted inside a PVC electrical box. The front panel embeds the LCD display (1) for viewing working parameters and the operating status, the multifunctional button (2) is used to browse the different views of the display and operate the basic commands to configure and adjust the unit operating parameters, the knob used to regulate the exchange temperature (3), the indicator LEDs that allow you to quickly check the health status of the device: these are from left to right the power on indicator (4), the health of the radio link with the sensor (5), the status of the connection to the WiFi network (6). The following figures show the external sides of the unit.

Figure 6. External sides of the central unit: the left hand side, lower side and right hand side


On the left hand side there is the WiFi antenna (1), on the lower side there are the connection cable to the sensor for the ambient temperature and humidity (2) and the the auxiliary connector (3). This is used in this project by the weight sensor to measure the level of the condensate in the tank which is produced by the gas boiler. On the right hand side there are the 12V / 1A power supply connector (4) and the connector needed to drive the flow switch valve (5).

The main electronic board is placed inside the box (Figure 7) and includes the following components: (1) it is the CPU that is based on the Atmel ATmega328p microcontroller (ref. [1]), (2) it is the WiFi module for the connection to the internet that is based on the ESP8266 chip, (3) is the LoRa Ra-02 data transmission module (ref. [2]). The WiFi module model is the well-known ESP-07S produced by Ai-Thinker (ref. [3]) which is equipped with an external connector for the external WiFi antenna.

Figure 7. Inside the central unit box – main board

Under the main electronic board there is an auxiliary board (Figure 58) which hosts a pair of relays (1) required to drive the three-way flow exchange valve. In addition, the image reveals the HX711 module (2) located on the rear face of the main board. This module represents the interface with the sensor that measures the weight and therefore the level of condensate in the tank placed under the boiler.

Figure 8. Inside the central unit box – auxiliary board

The tank for collecting the condensate rests on a weight scale made of two parallel plates interconnected by a torsion element (load cell) which represents the weight sensor (see ref. [5] for further details).

IoT and Monitoring

As mentioned above, the central unit has an ESP8266 module used to connect to home WiFi network. In this solution, the internet connection is used to send overall status information to an API service which saves it into a database. A web interface is then used to monitor the status of the controller from any device and location over the internet. Following picture shows the simple architecture of the API and monitoring service:

The API gateway exposes an API called directly from the central unit (IoT device) and stores status data to a MySQL database. The web server exposes a web page (php) that shows the latest status information using the graphical representation shown below:

Two images of the monitoring page: on the left hand side picture, the tank water temperature is above the switching temperature (38 celsius degrees) and hence the gas boiler is bypassed; on the right side picture, the tank water temperature is below the switching temperature and hence the gas boiler heats up the water coming from the solar tank.

Status information shown in the picture includes:

  • Flow status
  • Solar tank water temperature
  • Sensor battery charging level and status
  • External temperature and humidity
  • Filling status of the tank for condensate placed below the gas boiler

In addition, the page can show various health monitoring alerts like:

  • The communication health status between the central unit and the sensor
  • The condensate tank level above 90%

References

[1] Atmel ATmega328p microcontroller – Microchip Technology

[2] Ai-Thinker LoRa Ra-02 radio transmission module

[3] Ai-Thinker ESP07-S WiFi Module

[4] MCP9700 linear thermistor for temperature measurement

[5] Article: Building an electronic weight scale using a load cell sensor