-
Notifications
You must be signed in to change notification settings - Fork 25
/
driver_kamheat.h
131 lines (118 loc) · 6.1 KB
/
driver_kamheat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Based on: https://github.com/wmbusmeters/wmbusmeters/blob/master/src/driver_kamheat.cc
Copyright (C) 2021-2022 Fredrik Öhrström (gpl-3.0-or-later)
*/
#pragma once
#include "driver.h"
#include <vector>
#include <string>
struct Kamheat: Driver
{
Kamheat(std::string key = "") : Driver(std::string("kamheat"), key) {};
virtual esphome::optional<std::map<std::string, double>> get_values(std::vector<unsigned char> &telegram) override {
std::map<std::string, double> ret_val{};
add_to_map(ret_val, "total_energy_consumption_kwh", this->get_0406(telegram));
add_to_map(ret_val, "total_energy_consumption_kwh", this->get_040F(telegram));
add_to_map(ret_val, "total_energy_consumption_kwh", this->get_0405(telegram));
add_to_map(ret_val, "total_energy_consumption_kwh", this->get_total_energy_consumption_kwh(telegram));
add_to_map(ret_val, "volume_flow_lh", this->get_043B(telegram));
add_to_map(ret_val, "volume_flow_lh", this->get_023B(telegram));
add_to_map(ret_val, "volume_flow_lh", this->get_volume_flow_lh(telegram));
add_to_map(ret_val, "power_kw", this->get_022D(telegram));
// add_to_map(ret_val, "total_forward_energy_m3c", this->get_04FF07(telegram));
// add_to_map(ret_val, "total_return_energy_m3c", this->get_04FF08(telegram));
// add_to_map(ret_val, "total_volume_m3", this->get_0414(telegram));
add_to_map(ret_val, "flow_temperature_c", this->get_0259(telegram));
// add_to_map(ret_val, "flow_temperature_c", this->get_flow_temperature_c(telegram));
add_to_map(ret_val, "return_temperature_c", this->get_025D(telegram));
// add_to_map(ret_val, "return_temperature_c", this->get_return_temperature_c(telegram));
if (ret_val.size() > 0) {
return ret_val;
}
else {
return {};
}
};
private:
esphome::optional<double> get_total_energy_consumption_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if ((tpl_ci_field == 0x79) && (l_field > 0x30)) { // check !!!!
uint32_t usage{0};
uint8_t i = 29; // check !!!!
usage = (((uint32_t)telegram[i+3] << 24) | ((uint32_t)telegram[i+2] << 16) |
((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
// in kWh
ret_val = usage / 27777.0;
ESP_LOGVV(TAG, "Found total_energy_consumption with '%d'->'%f'", usage, ret_val.value());
}
return ret_val;
};
esphome::optional<double> get_volume_flow_lh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if ((tpl_ci_field == 0x79) && (l_field > 0x30)) { // check !!!!
uint32_t flow{0};
uint8_t i = 42; // check !!!!
flow = (((uint32_t)telegram[i+3] << 24) | ((uint32_t)telegram[i+2] << 16) |
((uint32_t)telegram[i+1] << 8) | (uint32_t)telegram[i+0]);
ret_val = (double)flow;
ESP_LOGVV(TAG, "Found volume_flow with '%f'", ret_val.value());
}
return ret_val;
};
// esphome::optional<double> get_forward_energy_m3c(std::vector<unsigned char> &telegram) {
// esphome::optional<double> ret_val{};
// size_t i = 19;
// if ((telegram[0] == 0x40) && (telegram[19] == 0x78)) { //longer frame (L=0x40) and 0x78 tpl-ci-field
// ret_val = (((uint32_t)telegram[i+13] << 24) + ((uint32_t)telegram[i+12] << 16) + ((uint32_t)telegram[i+11] << 8) + (uint32_t)telegram[i+10]);
// }
// return ret_val;
// };
// esphome::optional<double> get_return_energy_m3c(std::vector<unsigned char> &telegram) {
// esphome::optional<double> ret_val{};
// size_t i = 19;
// if ((telegram[0] == 0x40) && (telegram[19] == 0x78)) { //longer frame (L=0x40) and 0x78 tpl-ci-field
// ret_val = (((uint32_t)telegram[i+20] << 24) + ((uint32_t)telegram[i+19] << 16) + ((uint32_t)telegram[i+18] << 8) + (uint32_t)telegram[i+17]);
// }
// return ret_val;
// };
// esphome::optional<double> get_volume_flow_lh(std::vector<unsigned char> &telegram) {
// esphome::optional<double> ret_val{};
// size_t i = 19;
// if ((telegram[0] == 0x31) && (telegram[19] == 0x79)) { //short frame (L=0x31) and 0x79 tpl-ci-field (EN 13757-3 Application Layer with Compact frame (no tplh))
// i-=11;
// ret_val = (((uint32_t)telegram[i+37] << 24) + ((uint32_t)telegram[i+36] << 16) + ((uint32_t)telegram[i+35] << 8) + (uint32_t)telegram[i+34]);
// }
// else if ((telegram[0] == 0x40) && (telegram[19] == 0x78)) { //longer frame (L=0x40) and 0x78 tpl-ci-field
// ret_val = (((uint32_t)telegram[i+37] << 24) + ((uint32_t)telegram[i+36] << 16) + ((uint32_t)telegram[i+35] << 8) + (uint32_t)telegram[i+34]);
// }
// return ret_val;
// };
// esphome::optional<double> get_temperature_inlet_C(std::vector<unsigned char> &telegram) {
// esphome::optional<double> ret_val{};
// size_t i = 19;
// if ((telegram[0] == 0x31) && (telegram[19] == 0x79)) { //short frame (L=0x31) and 0x79 tpl-ci-field (EN 13757-3 Application Layer with Compact frame (no tplh))
// i-=13;
// ret_val = (((uint32_t)telegram[i+41] << 8) + (uint32_t)telegram[i+40]) / 100.0 ;
// }
// else if ((telegram[0] == 0x40) && (telegram[19] == 0x78)) { //longer frame (L=0x40) and 0x78 tpl-ci-field
// ret_val = (((uint32_t)telegram[i+41] << 8) + (uint32_t)telegram[i+40]) / 100.0 ; // t1
// }
// return ret_val;
// };
// esphome::optional<double> get_temperature_outlet_C(std::vector<unsigned char> &telegram) {
// esphome::optional<double> ret_val{};
// size_t i = 19;
// if ((telegram[0] == 0x31) && (telegram[19] == 0x79)) { //short frame (L=0x31) and 0x79 tpl-ci-field (EN 13757-3 Application Layer with Compact frame (no tplh))
// i-=15;
// ret_val = (((uint32_t)telegram[i+45] << 8) + (uint32_t)telegram[i+44]) / 100.0;
// }
// else if ((telegram[0] == 0x40) && (telegram[19] == 0x78)) { //longer frame (L=0x40) and 0x78 tpl-ci-field
// ret_val = (((uint32_t)telegram[i+45] << 8) + (uint32_t)telegram[i+44]) / 100.0; // t2
// }
// return ret_val;
// };
};