-
-
Save phha/f9a17811b2256a28d9a00b11680b3b5d to your computer and use it in GitHub Desktop.
/* | |
* 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 |
This was made for a WiFi enabled microcontroller running esphome such as ESP8266 or ESP32. Similar to this one:
https://github.com/openv/openv/wiki/Bauanleitung-ESP32-Adafruit-Feather-Huzzah32-and-Proto-Wing
It is meant to feed data into Home Assistant via Wifi. This seems different from what you are trying to do, so I‘m afraid it won’t be very useful to you.
Ok maybe i misexplain. I have HA and NodeMCU ESP8266 at home. My point is can I just replace my USB-TTL with an ESP ? Components are almost the same.
In that case I believe it should work. You might have to adapt the values for the RX2 and TX2 pins, since the ones above are for ESP32.
I've put a more recent version here in case you want to try it out:
https://github.com/phha/vitowifi_esphome/blob/master/viessmann.yaml
Dear,
I will test and let You know. I’am new in esphome. I only have to upload the yaml https://github.com/phha/vitowifi_esphome/blob/master/viessmann.yaml as I did for my led strip ? Is the librairie marrant include ? Thank you and sorry for bothering you.
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.
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 !
Dear,
I am using this hardware https://github.com/openv/openv/wiki/Weiterentwicklung-3.3V-TTL-mit-3D-Geh%C3%A4use and vitalk (old and deprecated)
Do you think that it will work with this project ?