From the desire to control a gas boiler remotely to complete automation of home heating

In this article I’ll tell you about my path to developing DIY hardware to work with Home Assistant in order to automate heating in a private home.

Chapter 0. Background

I wanted to build a house. The house was built, the problem arose with heating and control, and since people were sometimes absent from the house for several months, I didn’t really want to overpay for gas. There is no main gas supply, but “we’ll get it through soon.” Before this, a gas tank was buried “soon”, and the gas there is +-10 times more expensive than the main gas. An inquisitive mind decided: we will maintain the temperature in the house at 15 degrees when no one is there. How to do it? Hang the controller/thermostat for the boiler. Are there ready-made solutions on the market? There is, but not enough. Or I didn’t search well.

Chapter 1. Studying the market

There are some ready-made solutions on the market, for example ZONT. For most, it would be suitable, but in my case I wanted to control all this stuff from Home Assistant, because I don’t like the zoo from applications. But it can’t do this. More precisely, it can, but through a non-public API. This means that at the most inopportune moment, one of the developers will deploy a new version of the API and our “integration” will turn into a pumpkin.

All other proposals turned out to be just as cloudy. Although now there is hardware and software from WirenBoard, this is no longer important.

As a result, the choice arises: use ZONT and crutches, or do something of your own.

Chapter 2. Doing something of our own

We are looking for documentation on OpenTherm, but there isn’t much of it, except for OpenTherm Protocol Specification v2.2 from 2003, everything is very secure. On github there was only one normal library for working with the protocol – OpenTherm Library. And there are examples too. Simple and without details.

Later 20 minutes a couple of days we get something that can slightly control the boiler. Add WiFiManager for the convenience of setting up a Wifi connection and… it doesn’t work normally. Because OpenTherm Library is blocking by default. That is, when the code expects a response from the boiler, the microcontroller is busy waiting. Fiasco.

Okay, I thought, let’s add scheduler! While the library is waiting for a response, let’s do something else, for example, the web server will respond to requests. Sounds wonderful. True, the scheduler had to be rewritten a little. And make a small change to the OpenTherm Library.

At some point I wanted to burn everything down, install the Zont and nail it with crutches to the HA.

But, later for a while After a month, we got quite the result: from Home Assistant you can set the coolant temperature. But the task was different – to maintain the set temperature in the house, and not in the boiler heat exchanger.

Chapter 3. Still doing our own thing

How to select the coolant temperature necessary to maintain the desired air temperature in the house? Historically, it has been empirical. It’s cold at home – we increase it, at home it’s hot – we lower it. From a development point of view – PID controller.

We add code and test. We see slow heating of the house or swinging of the system, when the house is either 25 or 19 degrees, and stabilization takes time. This is due to the fact that heating is an inert process.

Having studied other possible options, I settle on weather-dependent regulation (equithermal curves). The algorithm is at least described in the documentation for some thermostats for boilers, but there are no formulas for calculation. Maxim Vdovin performed an approximation and posted the data for the calculation, for which I thank him.

We write a small library to calculate the coolant temperature depending on the temperature outside and the temperature in the house, add it to the controller, and add logic. We test, select coefficients, and a miracle happens – it works! The desired temperature reigned in the house. For the first time in a couple of months, I don’t have to manually adjust anything.

For the first few months I took the outside temperature from the integration Weather in Home Assistant, but its accuracy left much to be desired, so the temperature in the house fluctuated a little, within 1-2 degrees from the set one.

The solution turned out to be simple – take the external sensor outside and take readings from it. While the DS18B20 sensor was driving, I printed Stevenson’s booth (meteorological booth) to exclude the influence of precipitation and sun on the readings.

A couple of hours to finish writing the firmware, adding noise filtering for readings. Fill it up.

Having looked suspiciously at the fact that everything was working as intended, I left it alone for almost a year and a half.

Chapter 4. Tests and observations

Over the remaining 3-4 cold months and the entire next winter, the controller performed very well: despite daily temperature fluctuations from -30 to +2, the set temperature was maintained in the house.

Over the summer, new functions were added, the code was combed, full integration into HomeAssistant was added via MQTT Auto Discovery, a normal board was designed and assembled.

After testing I decided to post it project on Github. The code is open source and free. The page contains files for producing and assembling the board.

The latest version also makes it possible to connect another DS18B20 sensor to determine the temperature inside the house. But personally, it’s more convenient for me to send temperature from ZigBee sensors to the controller via MQTT.

In general, I am now more than satisfied with the controller’s performance. Behind the scenes there is a lot of not very interesting and boring things left: the development took about a year and is still underway.

Chapter 5: still no main gas

Since the “quick connection” took a long time, and gas at times was 25-35 rubles per liter, I was haunted by the thought that at night rates it seemed cheaper to heat a house with electricity.

Having sketched out a table in Excel with calculations, it was clear that the idea was not bad. On average, in a mixed cycle (gas during the day, electricity at night) it should be 24% cheaper per year. With the cost of an electric boiler being 57,000 rubles, the payback for such a solution is a little more than 2.5 years.

Calculation example

Calculation example

The same year, Baxi released the Ampera electric boiler, which, by a fortunate coincidence, can do Opentherm. Accidents are not accidental, and after some time the boiler was installed parallel to the gas one.

A second controller was assembled and connected to it, and Home Assistant created automation that switches boilers depending on the electricity tariff and the cost of gas at the time of refueling. Whether this decision will be justified – time will tell; in extreme cases, it will be as a backup.

Chapter 6. Telemetry

As I wrote earlier, due to the lack of main gas, I have a buried gas holder. By default, they are equipped with a mechanical float-type level gauge with the same mechanical indicator.

For example this
Mechanical level gauge

Mechanical level gauge

That is, if you want to check the level in winter, then be so kind as to find it under the snow, dig out the snow cover and look. And then it is advisable to bury it.

Having studied the market, I again did not find solutions that can work locally and can be integrated into Home Assistant. Or again I was looking poorly. Google for the request: telemetry for a gas tank.

In the process of studying the market, it became clear that you need to separately look for the sensor and its documentation with reference values. All available sensors operate on the principle of a hall sensor; in Russia it is possible to purchase SRG 487-530-2001, for which the software was written.

SRG 487-530-2001

In order not to bore the reader with another story about the development of the device, I will say this: everything was much simpler and faster. It took a little more than a couple of months from the prototype to a normal board. Then we had to slightly adjust the reading matrix, since reference values ​​for this sensor could not be found.

The device has a meter function, so you can use it to track gas consumption in Home Assistant.

To track gas consumption, a meter function has been added to Home Assistant (via the Energy panel). Not everything is going smoothly with it, since in HA it is impossible to count gas in liters, so conversion to m3 is used, perhaps this will be corrected in the future.

The project was also published on Github. There are also files for producing and assembling the board.

Chapter 7. Final

Actually, why was all this done? To automate processes and convenience, to control all smart home devices from one application. And for fun. So the goal has been achieved.

Examples of additional automations in HA that can be created:

  1. Push notifications if any of the boilers fails

  2. Push notifications when the gas level in the gas tank is critically low

  3. Push notifications when a gas tank is flooded (groundwater)

  4. Automatic switching to an electric boiler when the night tariff is in effect (23:00-07:00) provided that the price per kW of heat from gas is higher than the price per kW of heat from electricity.

  5. Setting the temperature in the house to 15 degrees when the house is armed (when no one is present)

  6. Setting a comfortable temperature when the house is disarmed.

  7. Setting the night temperature when the house is switched to night mode

Home screen example in Home Assistant

Home screen example in Home Assistant

More screenshots
Example of a boiler device page

Example of a boiler device page

Example of a gas tank device page

Example of a gas tank device page

Future plans

Despite the fact that for more than several years ESP8266 boards feel normal and no freezes have been noticed, there is an opinion on the Internet that the hardware watchdog does not work correctly on them and people in general experience freezes on this board. To eliminate this problem, people do external watchdog on attiny13 or recommend using esp32. Therefore, in the future there are plans to switch to this platform, adding the ability to use BLE temperature sensors.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *