The idea is to create a system for controlling heating and domestic hot water in a domestic environment. The system will be built with opensource hardware and software and will allow integration with home automation currently on the market.
In the heating system it is possible to include a boiler, a solar system with storage, radiators, radiant system and domestic hot water.
The system focuses first on temperature and consumption monitoring and then on a control focused on reducing consumption and above all waste caused by a poorly calibrated system.

Read more: https://github.com/mastroalex/TCS
System architecture

Several sensors read environmental information, mainly temperature. The data is stored on a remote server and is used to control the heating system.
In addition to temperature differences and heat losses, the system also takes into account environmental conditions and weather forecasts. In the initial phase, boiler management is not considered but its shutdown can be forced only on the basis of weather information (using solar power). The management of the boiler is left to the solar control unit.
This first phase involves a study of temperatures and thermal dispersions and a recording of the data. The data is collected and stored both with the platform SinricPro and a private remote database, which can be viewed from the page web with interactive graphics.
Each sensor also has its own webserver, reachable only from the local network, which allows the sensors to be read. In a second step, the actual control system will also be added. The management of heating multiple rooms with radiators and the management of air conditioners via an RF control will also be added.
The system also provides for the creation of chronothermostats and sensors for environmental well-being and comfort. Thermal safety devices and methane (or LPG) detectors will also be added. Finally, after a long period of testing, the system will also replace the solar control unit.
Typical plant structure
The heating system includes a solar system with storage. A boiler that heats the storage and the radiators. The domestic hot water system also includes a recirculation pump.
This article is considered in this article but the sensory system is easily extensible to each thermal system by scaling the number of sensors required. Clearly the control system requires an ad hoc study and what has been created has been studied and tested for the reference thermal system.

Sensors
Temperature and humidity
The temperature is read by DHT22 (with which the previous DHT11 have been replaced) for the environments. So the DS18B20 is used for wells and wherever a waterproof sensor is required.

Furthermore, the advantage of the DS18B20, beyond the great precision, is linked to the communication protocol that allows you to easily read several, connected on a single data line.
It is possible to create an ad hoc library by implementing the configuration and reading of different sensors. The tempvec vector contains the values of different sensors.
#include
#include
const int oneWireBus = D5; // GPIO where the DS18B20 is connected to
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
int numberOfDevices;
float tempvec[] = {0, 0, 0, 0}; // set zero for all the sensor
DeviceAddress tempDeviceAddress;
…
void dsaggiornamento() {
for (int i = 0; i < numberOfDevices; i++) {
// Search the wire for address
if (sensors.getAddress(tempDeviceAddress, i)) {
// Output the device ID
Serial.print("Temperature for device: ");
Serial.println(i, DEC);
// Print the data
float tempC = sensors.getTempC(tempDeviceAddress);
Serial.print("Temp C: ");
Serial.println(tempC);
tempvec[i] = tempC;
}
}
}
…
void ds_set() {
sensors.begin(); // Start the DS18B20 sensor
numberOfDevices = sensors.getDeviceCount();
// Loop through each device, print out address
for (int i = 0; i < numberOfDevices; i++) {
// Search the wire for address
if (sensors.getAddress(tempDeviceAddress, i)) {
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: ");
printAddress(tempDeviceAddress);
Serial.println();
} else {
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address. Check power and cabling");
}
}
}

By implementing the reading and the webserver we can read the values by accessing the ip address of the device.


Electricity consumption
Power consumption can be measured using CT sensors. It can be useful to understand if devices such as pumps, fans, etc. are on or not.
Flow
The flow sensors used are based on the Hall sensor which provides a signal proportional to the rotation. Each rotation represents 2.25 mL of flow.
Actuators
Different devices can be used.
Definitely dry contacts will be used to control relays.
Data-management
The data is read using an MCU Name ESP8266.
Web server
The web server allows you to easily read the sensor from the LAN.
Moreover, the page is made up of containers that contain the updated value from the sensors.
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"</i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°C</sup>
</p>
The value is continuously updated.
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
Remote server
By connecting the device to the internet it is possible to send data to a remote server. This is done with an HTTP POST request.
String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(temp1) + "&value2=" + String(temp2) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
Then the data is received from a php page which, after verifying the security criteria, saves the data in the database.
A second page takes care of reading the database and loading the charts. The Highcharts libraries are used by providing the data.
var chartT = new Highcharts.Chart({
chart:{ renderTo : 'chart-temperature' },
title: { text: 'Temperature Boiler1' },
series: [{
showInLegend: false,
data: value1
}],
plotOptions: {
line: { animation: false,
dataLabels: { enabled: true }
},
series: { color: '#059e8a' }
},
xAxis: {
type: 'datetime',
categories: reading_time
},
yAxis: {
title: { text: 'Temperature (Celsius)' }
//title: { text: 'Temperature (Fahrenheit)' }
},
credits: { enabled: false }
});
Alexa integration
The most developed home automation system is certainly the Amazon Alexa ecosystem for which integration through SinricPro is expected. By recalling the libraries, the SinricPro functionalities are loaded that allow communication with their cloud.
#include <SinricPro.h>
#include "SinricProTemperaturesensor.h"
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Temperaturesensor turned %s (via SinricPro) \r\n", state ? "on" : "off");
deviceIsOn = state; // turn on / off temperature sensor
return true; // request handled properly
}
void handleTemperaturesensor() {
if (deviceIsOn == false) return; // device is off...do nothing
unsigned long actualMillis = millis();
if (actualMillis - lastEvent < EVENT_WAIT_TIME) return; //only check every EVENT_WAIT_TIME milliseconds
t = dht.readTemperature(); // get actual temperature in °C
// temperature = dht.getTemperature() * 1.8f + 32; // get actual temperature in °F
h = dht.readHumidity(); // get actual humidity
if (isnan(t) || isnan(h)) { // reading failed...
Serial.printf("DHT reading failed!\r\n"); // print error message
return; // try again next time
}
if (t == lastTemperature || h == lastHumidity) return; // if no values changed do nothing...
SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID]; // get temperaturesensor device
bool success = mySensor.sendTemperatureEvent(t, h); // send event
if (success) { // if event was sent successfuly, print temperature and humidity to serial
Serial.printf("Temperature: %2.1f Celsius\tHumidity: %2.1f%%\r\n", t, h);
} else { // if sending event failed, print error message
Serial.printf("Something went wrong...could not send Event to server!\r\n");
}
lastTemperature = t; // save actual temperature for next compare
lastHumidity = h; // save actual humidity for next compare
lastEvent = actualMillis; // save actual time for next compare
}
// setup function for SinricPro
void setupSinricPro() {
// add device to SinricPro
SinricProTemperaturesensor &mySensor = SinricPro[TEMP_SENSOR_ID];
mySensor.onPowerState(onPowerState);
// setup SinricPro
SinricPro.onConnected([]() {
Serial.printf("Connected to SinricPro\r\n");
});
SinricPro.onDisconnected([]() {
Serial.printf("Disconnected from SinricPro\r\n");
});
SinricPro.begin(APP_KEY, APP_SECRET);
SinricPro.restoreDeviceStates(true); // get latest known deviceState from server (is device turned on?)
}
And in the loop they update by calling handleTemperaturesensor()
.


Control-system
The system focuses first on temperature and consumption monitoring. A second phase involves a control focused on reducing consumption and above all waste caused by a poorly calibrated system.
Reading-examples
One-week-reading in summer
In the following graph the reading of the sensors for the technical environment, for the boiler and storage.
Having optimized the thermal request of the puffer, the boiler does not start and does not supply thermal energy to the storage. the delivery and return of the boiler remain fixed, similar to the ambient temperature. The accumulation follows a periodic trend (it is repeated 7 times a week) in which the temperature drops at night and increases with the progressive rising of the sun. Clearly it can be influenced by the demand for hot water.
The graph contains 4 splines over 2017 points, one sampling every 5 minutes. The time lag between the different temporal temperatures is within ± 2 min and in the temperature there is a resolution of 0.0625 ° C with a maximum error of ± 1 ° C. Ta represents the average of the ambient temperature.
Reading rooms
24-hour reading of temperature and humidity from a bedroom.
In the following graph 1 month of reading of different sensors placed in various rooms.
The data has been exported from the database and added to a CSV file to which the vector containing the time has been added. Everything was done in MATLAB and then loaded into the Highcharts libraries.
For example, for the time vector:
t1=datetime(2021,06,11,11,10,00)
t2=datetime(2021,07,11,11,10,00)
t=[t1:minutes(5):t2]'