Created
December 21, 2019 19:50
-
-
Save phha/f9a17811b2256a28d9a00b11680b3b5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ESPHome component for Viessmann boilers. | |
* | |
* Tested with OptoLink ESP32 adapter from here: | |
* https://github.com/openv/openv/wiki/Bauanleitung-ESP32-Adafruit-Feather-Huzzah32-and-Proto-Wing | |
* | |
* Example yaml: | |
* | |
* sensor: | |
* - platform: custom | |
* lambda: |- | |
* auto link = new optolink(); | |
* App.register_component(link); | |
* return {link->sensor_outside_temp, link->sensor_boiler_temp}; | |
* sensors: | |
* - name: ${name} outside temperature | |
* unit_of_measurement: °C | |
* accuracy_decimals: 1 | |
* filters: | |
* - multiply: 0.1 | |
* - name: ${name} boiler temperature | |
* unit_of_measurement: °C | |
* accuracy_decimals: 1 | |
* filters: | |
* - multiply: 0.1 | |
* | |
*/ | |
#pragma once | |
#include "esphome.h" | |
#include "VitoWiFi.h" | |
#include "datapoints.h" | |
using namespace std; | |
using namespace std::placeholders; | |
#define RX2 16 | |
#define TX2 17 | |
string _betriebsart[] = { | |
"Abschaltbetrieb", | |
"Nur Warmwasser", | |
"Heizen, Kühlen, Warmwasser", | |
"Undefiniert", | |
"Dauernd reduziert", | |
"Dauernd normal", | |
"Normal abschalt", | |
"Nur kühlen" | |
}; | |
class optolink : public Component { | |
private: | |
// Optolink data points | |
dp_float16 _dp_outside_temp; | |
dp_float16 _dp_boiler_temp; | |
dp_float16 _dp_speicher_temp; | |
dp_uint8 _dp_brenner_status; | |
dp_uint8 _dp_betriebsart; | |
// Callbacks for optolink data points | |
void _float_cb(Sensor *sensor, const IDatapoint& dp, DPValue value); | |
void _uint8_cb(Sensor *sensor, const IDatapoint& dp, DPValue value); | |
void _binary_cb(BinarySensor *sensor, const IDatapoint& dp, DPValue value); | |
void _betriebsart_cb(TextSensor *sensor, const IDatapoint& dp, DPValue value); | |
// Scheduled call for initiating communication via optolink | |
void _comm(); | |
public: | |
Sensor *sensor_outside_temp = new Sensor(); | |
Sensor *sensor_boiler_temp = new Sensor(); | |
Sensor *sensor_speicher_temp = new Sensor(); | |
BinarySensor *sensor_brenner_status = new BinarySensor(); | |
TextSensor *sensor_betriebsart = new TextSensor(); | |
optolink(); | |
void setup() override; | |
void loop() override; | |
}; //class optolink | |
VitoWiFi_setProtocol(KW); | |
// optolink class definitions | |
optolink::optolink() : | |
_dp_outside_temp("outsideTemp", "boiler", 0x5525), | |
_dp_boiler_temp("boilerTemp", "boiler", 0x0810), | |
_dp_speicher_temp("speicherTemp", "speicher", 0x0804), | |
_dp_brenner_status("brennerStatus", "boiler", 0x551E), | |
_dp_betriebsart("betriebsart", "boiler", 0xB000) {} | |
void optolink::_comm() { | |
VitoWiFi.readAll(); | |
} | |
void optolink::_float_cb(Sensor* sensor, const IDatapoint& dp, DPValue value) { | |
sensor->publish_state(value.getFloat()); | |
} | |
void optolink::_uint8_cb(Sensor* sensor, const IDatapoint& dp, DPValue value) { | |
sensor->publish_state(value.getU8()); | |
} | |
void optolink::_binary_cb(BinarySensor* sensor, const IDatapoint& dp, DPValue value) { | |
sensor->publish_state(value.getU8() != 0); | |
} | |
void optolink::_betriebsart_cb(TextSensor* sensor, const IDatapoint& dp, DPValue value) { | |
sensor->publish_state(_betriebsart[value.getU8()]); | |
} | |
void optolink::setup() { | |
_dp_outside_temp.setCallback(bind(&optolink::_float_cb, this, sensor_outside_temp, _1, _2)); | |
_dp_boiler_temp.setCallback(bind(&optolink::_float_cb, this, sensor_boiler_temp, _1, _2)); | |
_dp_speicher_temp.setCallback(bind(&optolink::_float_cb, this, sensor_speicher_temp, _1, _2)); | |
_dp_brenner_status.setCallback(bind(&optolink::_binary_cb, this, sensor_brenner_status, _1, _2)); | |
_dp_betriebsart.setCallback(bind(&optolink::_betriebsart_cb, this, sensor_betriebsart, _1, _2)); | |
VitoWiFi.setup(&Serial2, RX2, TX2); // | |
set_interval("optolink_comm", 10000, bind(&optolink::_comm, this)); | |
ESP_LOGI("OptoLink", "Component Initialized."); | |
} | |
void optolink::loop() { | |
VitoWiFi.loop(); | |
} | |
// end optolink class definitions |
Ok thank you. Let you know.
Dear,
I've open an issue on https://github.com/phha/vitowifi_esphome if you can have a look :)
Thank you !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will need all the files in the repository. You will also have to adapt the yaml with your WiFi settings and whatever else you want to add to the configuration. Then you can upload everything from the yaml just like any other ESPHome project.