Jeroen88 / EasyOpenTherm

OpenTherm library to create thermostat for OpenTherm enabled boilers and HVACs using an OpenTherm controller and an ESP32 or other microcontroller
GNU General Public License v3.0
68 stars 2 forks source link
arduino-library central-heating-controller device-control esp32 esp8266 home homeautomation hvac hvac-control maker opentherm thermostat

OpenTherm Arduino ESP32/ESP8266 Library

Was already working on an ESP32, now ready for an ESP8266 too!

Create your own thermostat with this library and save money on your energy bills while reducing your carbon footprint! Or use a home automation system like Home Assistant and smart thermostatic valves to heat up each room individually.

The library complies with the OpenTherm specification. Control any (condensing) boiler or air conditioner (HVAC) that also meets the OpenTherm specification.

The library can be easily installed in the Arduino IDE. It has been tested on an ESP32-S2, ESP32-C3, ESP32 NodeMCU and an ESP8266 NodeMCU microcontroller and may also work on other MCU's. To connect the boiler, you will need an OpenTherm controller board or an OpenTherm controller Shield.

Fully functioning Home Assistant Boiler Thermostat in examples

Home Assistant logo MQTT logo\

The Advanced_Thermostat.ino example is specially designed for Home Assistant

Installation

Usage

#include <EasyOpenTherm.h>

Select two free GPIO pins, one to send data to the boiler and one to receive data. The pin receiving data must support interrupts. For the pin that sends data, do not use a 'read only' GPIO. Define these pins in the program

#define OT_RX_PIN (35)
#define OT_TX_PIN (33)

In this case GPIO34 is used for receiving and GPIO33 is used for sending data. Note that the Rx pin is connected to the TxD pin of the OpenTherm controller and vice versa!

Create an OpenTherm class instance

OpenTherm thermostat(OT_RX_PIN, OT_TX_PIN);

Make sure that only one instance of this object is alive at a time. So make it global or static like in the examples. Start communicating with the boiler (or HVAC) e.g. request activation of the services of the boiler and request it's status flags

uint8_t primaryFlags = uint8_t(OpenTherm::STATUS_FLAGS::PRIMARY_DHW_ENABLE);  // Enable Domestic Hot Water 
primaryFlags |= uint8_t(OpenTherm::STATUS_FLAGS::PRIMARY_CH_ENABLE);          // Enable Central Heating
primaryFlags |= uint8_t(OpenTherm::STATUS_FLAGS::PRIMARY_COOLING_ENABLE);     // Enable cooling (of your boiler, if available)
primaryFlags |= uint8_t(OpenTherm::STATUS_FLAGS::PRIMARY_OTC_ENABLE);         // Enable Outside Temperature Compensation (ifa available in your boiler)
uint8_t statusFlags;                                                          // Flags returned by the boiler will be stored into this variable
thermostat.status(primaryFlags, statusFlags);

This command will return true on success and false otherwise All other interaction with the boiler is done using the read(), write() or readWrite() functions, e.g.

thermostat.write(OpenTherm::WRITE_DATA_ID::CONTROL_SETPOINT_CH, 40.0); // This will start up the boiler to heat up the boiler water to 40 degrees

All these functions take an OpenTherm DATA-ID as first parameter. The DATA-ID refers to the action requested from the boiler. All known DATA-ID's are defined in EasyOpenTherm.h. The DATA-IDs for reading data from the boiler are defined in enum class READ_DATA_ID, DATA-IDs for writing data to the boiler are defined in enum class WRITE_DATA_ID and DATA-IDs for writing and reading data to and from the boiler are defined in enum class READ_WRITE_DATA_ID. The second parameter and sometimes third parameter defines the value written to the boiler or read from the boiler. The data types are:

Error handling

The function error() is used to get information about the last call to one of the functions read(), write() or readWrite(). All these functions return false if an error occurred in the communication between thermostat (primary) and boiler or HVAC (secondary). These functions return true if everything is fine, but also upon an error on application level. You will get this error if e.g. you read out your boiler or HVAC with a DATA-ID that is not supported. Also, if you write data to your boiler or HVAC, the value can be out of range, e.g. a setpoint is too low or too high. In this case error() will return INVALID_DATA.

All error codes:

Glossary

License

© 2022 Jeroen Döll, licensed under the GNU General Public License. Enjoy using the library, feedback is welcome!