Posted on Sunday, April 1, 2018 at 12:00 AM, 39516 views
OpenTherm Library is based on OpenTherm protocol specification v2.2 and works with all OpenTherm compatible boilers. Library can be easily installed into Arduino IDE and compiled for Arduino, ESP8266 and other similar controllers. OpenTherm protocol requires simple low voltage twowire connection to boiler, but voltage levels (7..15V) still much higher than Arduino/ESP8266 levels, which requires OpenTherm Adapter.
This version of library uses interrupts to achieve better stability and synchronization with boiler. For educational puprouses and to get better undestanding of OpenTherm protocol there is OpenTherm Controller based on simple sketch implemented using delays. So if you want control and integrate your boiler into home automation system, without proprietary thermostats, this library for you.
#include <OpenTherm.h>
const int inPin = 2; //4
const int outPin = 3; //5
Controller output pin should be connected to OpenTherm Adapter input pin and vise versa.
OpenTherm ot(inPin, outPin);
void ICACHE_RAM_ATTR handleInterrupt() {
ot.handleInterrupt();
}
void setup()
{
ot.begin(handleInterrupt);
}
void loop()
{
//Set/Get Boiler Status
ot.setBoilerStatus(enableCentralHeating, enableHotWater, enableCooling);
//Set Boiler Temperature to 64 degrees C
ot.setBoilerTemperature(64);
//Get Boiler Temperature
float temperature = ot.getBoilerTemperature();
delay(1000);
}
#include <Arduino.h>
#include <OpenTherm.h>
const int inPin = 2; //4
const int outPin = 3; //5
OpenTherm ot(inPin, outPin);
void ICACHE_RAM_ATTR handleInterrupt() {
ot.handleInterrupt();
}
void setup()
{
Serial.begin(115200);
Serial.println("Start");
ot.begin(handleInterrupt);
}
void loop()
{
//Set/Get Boiler Status
bool enableCentralHeating = true;
bool enableHotWater = true;
bool enableCooling = false;
unsigned long response = ot.setBoilerStatus(enableCentralHeating, enableHotWater, enableCooling);
OpenThermResponseStatus responseStatus = ot.getLastResponseStatus();
if (responseStatus == OpenThermResponseStatus::SUCCESS) {
Serial.println("Central Heating: " +
String(ot.isCentralHeatingActive(response) ? "on" : "off"));
Serial.println("Hot Water: " +
String(ot.isHotWaterActive(response) ? "on" : "off"));
Serial.println("Flame: " +
String(ot.isFlameOn(response) ? "on" : "off"));
}
if (responseStatus == OpenThermResponseStatus::NONE) {
Serial.println("Error: OpenTherm is not initialized");
}
else if (responseStatus == OpenThermResponseStatus::INVALID) {
Serial.println("Error: Invalid response " + String(response, HEX));
}
else if (responseStatus == OpenThermResponseStatus::TIMEOUT) {
Serial.println("Error: Response timeout");
}
//Set Boiler Temperature to 64 degrees C
ot.setBoilerTemperature(64);
//Get Boiler Temperature
float temperature = ot.getBoilerTemperature();
Serial.println("Boiler temperature is " + String(temperature) + " degrees C");
Serial.println();
delay(1000);
}
Start
Central Heating: on
Hot Water: on
Flame: on
Boiler temperature is 64 degrees C
unsigned long buildRequest(
OpenThermRequestType type,
OpenThermMessageID id,
unsigned int data);
unsigned long response = ot.sendRequest(request);
//Read Relative Modulation Level:
unsigned int data = 0xFFFF;
unsigned long request = ot.buildRequest(
OpenThermRequestType::READ,
OpenThermMessageID::RelModLevel,
data);
unsigned long response = ot.sendRequest(request);
void processResponse(unsigned long response, OpenThermResponseStatus status) {
if (status == OpenThermResponseStatus::SUCCESS) {
//handle response
}
}
void begin(
void(*handleInterruptCallback)(void),
void(*processResponseCallback)(unsigned long, OpenThermResponseStatus));
bool sendRequestAync(unsigned long request);
ot.process();
bool isReady = ot.isReady();