ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
vbus_sensor.cpp
Go to the documentation of this file.
1#include "vbus_sensor.h"
3#include "esphome/core/log.h"
4
5namespace esphome::vbus {
6
7ESPHOME_LOG_TAG(TAG, "vbus.sensor");
8
9static inline uint16_t get_u16(std::vector<uint8_t> &message, int start) {
10 return encode_value_le<uint16_t>(&message[start]);
11}
12
13static inline int16_t get_i16(std::vector<uint8_t> &message, int start) {
14 return encode_value_le<int16_t>(&message[start]);
15}
16
18 ESP_LOGCONFIG(TAG, "Deltasol BS Plus:");
19 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
20 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
21 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
22 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
23 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
24 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
25 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
26 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
27 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
28 LOG_SENSOR(" ", "System Time", this->time_sensor_);
29 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
30}
31
32void DeltaSolBSPlusSensor::handle_message(std::vector<uint8_t> &message) {
33 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
34 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
35 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
36 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
37 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
38 PUBLISH_STATE(this->pump_speed2_sensor_, message[9]);
39 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 16));
40 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 18));
41 PUBLISH_STATE(this->heat_quantity_sensor_,
42 get_u16(message, 20) + get_u16(message, 22) * 1000.0f + get_u16(message, 24) * 1000000.0f);
43 PUBLISH_STATE(this->time_sensor_, get_u16(message, 12));
44 PUBLISH_STATE(this->version_sensor_, get_u16(message, 26) * 0.01f);
45}
46
48 ESP_LOGCONFIG(TAG, "Deltasol BS 2009:");
49 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
50 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
51 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
52 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
53 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
54 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
55 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
56 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
57 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
58 LOG_SENSOR(" ", "System Time", this->time_sensor_);
59 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
60}
61
62void DeltaSolBS2009Sensor::handle_message(std::vector<uint8_t> &message) {
63 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
64 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
65 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
66 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
67 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
68 PUBLISH_STATE(this->pump_speed2_sensor_, message[12]);
69 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 10));
70 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 18));
71 PUBLISH_STATE(this->heat_quantity_sensor_, get_u16(message, 28) + get_u16(message, 30) * 1000);
72 PUBLISH_STATE(this->time_sensor_, get_u16(message, 22));
73 PUBLISH_STATE(this->version_sensor_, get_u16(message, 32) * 0.01f);
74}
75
77 ESP_LOGCONFIG(TAG, "Deltasol C:");
78 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
79 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
80 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
81 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
82 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
83 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
84 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
85 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
86 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
87 LOG_SENSOR(" ", "System Time", this->time_sensor_);
88}
89
90void DeltaSolCSensor::handle_message(std::vector<uint8_t> &message) {
91 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
92 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
93 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
94 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
95 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
96 PUBLISH_STATE(this->pump_speed2_sensor_, message[9]);
97 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 12));
98 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 14));
99 PUBLISH_STATE(this->heat_quantity_sensor_,
100 get_u16(message, 16) + get_u16(message, 18) * 1000.0f + get_u16(message, 20) * 1000000.0f);
101 PUBLISH_STATE(this->time_sensor_, get_u16(message, 22));
102}
103
105 ESP_LOGCONFIG(TAG, "Deltasol CS2:");
106 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
107 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
108 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
109 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
110 LOG_SENSOR(" ", "Pump Speed", this->pump_speed_sensor_);
111 LOG_SENSOR(" ", "Operating Hours", this->operating_hours_sensor_);
112 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
113 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
114}
115
116void DeltaSolCS2Sensor::handle_message(std::vector<uint8_t> &message) {
117 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
118 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
119 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
120 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
121 PUBLISH_STATE(this->pump_speed_sensor_, message[12]);
122 PUBLISH_STATE(this->operating_hours_sensor_, get_u16(message, 14));
123 PUBLISH_STATE(this->heat_quantity_sensor_,
124 (static_cast<uint32_t>(get_u16(message, 26)) << 16) | get_u16(message, 24));
125 PUBLISH_STATE(this->version_sensor_, get_u16(message, 28) * 0.01f);
126}
127
129 ESP_LOGCONFIG(TAG, "Deltasol CS4:");
130 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
131 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
132 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
133 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
134 LOG_SENSOR(" ", "Temperature 5", this->temperature5_sensor_);
135 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
136 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
137 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
138 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
139 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
140 LOG_SENSOR(" ", "System Time", this->time_sensor_);
141 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
142 LOG_SENSOR(" ", "Flow Rate", this->flow_rate_sensor_);
143}
144
145void DeltaSolCS4Sensor::handle_message(std::vector<uint8_t> &message) {
146 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
147 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
148 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
149 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
150 PUBLISH_STATE(this->temperature5_sensor_, get_i16(message, 36) * 0.1f);
151 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
152 PUBLISH_STATE(this->pump_speed2_sensor_, message[12]);
153 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 10));
154 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 14));
155 PUBLISH_STATE(this->heat_quantity_sensor_,
156 (static_cast<uint32_t>(get_u16(message, 30)) << 16) | get_u16(message, 28));
157 PUBLISH_STATE(this->time_sensor_, get_u16(message, 22));
158 PUBLISH_STATE(this->version_sensor_, get_u16(message, 32) * 0.01f);
159 PUBLISH_STATE(this->flow_rate_sensor_, get_u16(message, 38));
160}
161
163 ESP_LOGCONFIG(TAG, "Deltasol CS Plus:");
164 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
165 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
166 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
167 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
168 LOG_SENSOR(" ", "Temperature 5", this->temperature5_sensor_);
169 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
170 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
171 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
172 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
173 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
174 LOG_SENSOR(" ", "System Time", this->time_sensor_);
175 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
176 LOG_SENSOR(" ", "Flow Rate", this->flow_rate_sensor_);
177}
178
179void DeltaSolCSPlusSensor::handle_message(std::vector<uint8_t> &message) {
180 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
181 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
182 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
183 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
184 PUBLISH_STATE(this->temperature5_sensor_, get_i16(message, 36) * 0.1f);
185 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
186 PUBLISH_STATE(this->pump_speed2_sensor_, message[12]);
187 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 10));
188 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 14));
189 PUBLISH_STATE(this->heat_quantity_sensor_,
190 (static_cast<uint32_t>(get_u16(message, 30)) << 16) | get_u16(message, 28));
191 PUBLISH_STATE(this->time_sensor_, get_u16(message, 22));
192 PUBLISH_STATE(this->version_sensor_, get_u16(message, 32) * 0.01f);
193 PUBLISH_STATE(this->flow_rate_sensor_, get_u16(message, 38));
194}
195
197 ESP_LOGCONFIG(TAG, "DeltaSol BS/2 (DrainBack):");
198 LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_);
199 LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_);
200 LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_);
201 LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_);
202 LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_);
203 LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_);
204 LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_);
205 LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_);
206 LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_);
207 LOG_SENSOR(" ", "FW Version", this->version_sensor_);
208}
209
210void DeltaSolBS2Sensor::handle_message(std::vector<uint8_t> &message) {
211 PUBLISH_STATE(this->temperature1_sensor_, get_i16(message, 0) * 0.1f);
212 PUBLISH_STATE(this->temperature2_sensor_, get_i16(message, 2) * 0.1f);
213 PUBLISH_STATE(this->temperature3_sensor_, get_i16(message, 4) * 0.1f);
214 PUBLISH_STATE(this->temperature4_sensor_, get_i16(message, 6) * 0.1f);
215 PUBLISH_STATE(this->pump_speed1_sensor_, message[8]);
216 PUBLISH_STATE(this->pump_speed2_sensor_, message[9]);
217 PUBLISH_STATE(this->operating_hours1_sensor_, get_u16(message, 12));
218 PUBLISH_STATE(this->operating_hours2_sensor_, get_u16(message, 14));
219 PUBLISH_STATE(this->heat_quantity_sensor_,
220 get_u16(message, 16) + get_u16(message, 18) * 1000.0f + get_u16(message, 20) * 1000000.0f);
221 PUBLISH_STATE(this->version_sensor_, get_u16(message, 24) * 0.01f);
222}
223
225 ESP_LOGCONFIG(TAG, "VBus Custom Sensor:");
226 if (this->source_ == 0xffff) {
227 ESP_LOGCONFIG(TAG, " Source address: ANY");
228 } else {
229 ESP_LOGCONFIG(TAG, " Source address: 0x%04x", this->source_);
230 }
231 if (this->dest_ == 0xffff) {
232 ESP_LOGCONFIG(TAG, " Dest address: ANY");
233 } else {
234 ESP_LOGCONFIG(TAG, " Dest address: 0x%04x", this->dest_);
235 }
236 if (this->command_ == 0xffff) {
237 ESP_LOGCONFIG(TAG, " Command: ANY");
238 } else {
239 ESP_LOGCONFIG(TAG, " Command: 0x%04x", this->command_);
240 }
241 ESP_LOGCONFIG(TAG, " Sensors:");
242 for (VBusCustomSubSensor *sensor : this->sensors_) {
243 LOG_SENSOR(" ", "-", sensor);
244 }
245}
246
247void VBusCustomSensor::handle_message(std::vector<uint8_t> &message) {
248 for (VBusCustomSubSensor *sensor : this->sensors_)
249 sensor->parse_message(message);
250}
251
252void VBusCustomSubSensor::parse_message(std::vector<uint8_t> &message) {
253 this->publish_state(this->message_parser_(message));
254}
255
256} // namespace esphome::vbus
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
void handle_message(std::vector< uint8_t > &message) override
std::vector< VBusCustomSubSensor * > sensors_
void parse_message(std::vector< uint8_t > &message)
virtual void handle_message(std::vector< uint8_t > &message)=0
const LogString * message
Definition component.cpp:35
ESPHOME_LOG_TAG(TAG, "vbus.binary_sensor")
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
Definition helpers.h:1084
static void uint32_t