ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
opentherm.cpp
Go to the documentation of this file.
1/*
2 * OpenTherm protocol implementation. Originally taken from https://github.com/jpraus/arduino-opentherm, but
3 * heavily modified to comply with ESPHome coding standards and provide better logging.
4 * Original code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
5 * Public License, which is compatible with GPLv3 license, which covers C++ part of ESPHome project.
6 */
7
8#include "opentherm.h"
10#include <cinttypes>
11#ifdef USE_ESP32
12#include "esp_err.h"
13#endif
14#ifdef ESP8266
15#include "Arduino.h"
16#endif
17#include <string>
18
19namespace esphome::opentherm {
20
21using std::string;
22
23static const char *const TAG = "opentherm";
24
25#ifdef ESP8266
26OpenTherm *OpenTherm::instance = nullptr;
27#endif
28
29OpenTherm::OpenTherm(InternalGPIOPin *in_pin, InternalGPIOPin *out_pin, int32_t device_timeout)
30 : in_pin_(in_pin),
31 out_pin_(out_pin),
32 mode_(OperationMode::IDLE),
33 error_type_(ProtocolErrorType::NO_ERROR),
34 capture_(0),
35 clock_(0),
36 data_(0),
37 bit_pos_(0),
38 timeout_counter_(-1),
39 device_timeout_(device_timeout) {
40 this->isr_in_pin_ = in_pin->to_isr();
41 this->isr_out_pin_ = out_pin->to_isr();
42}
43
44bool OpenTherm::initialize() {
45#ifdef ESP8266
46 OpenTherm::instance = this;
47#endif
48 this->in_pin_->pin_mode(gpio::FLAG_INPUT);
49 this->in_pin_->setup();
50 this->out_pin_->pin_mode(gpio::FLAG_OUTPUT);
51 this->out_pin_->setup();
52 this->out_pin_->digital_write(true);
53
54#ifdef USE_ESP32
55 return this->init_esp32_timer_();
56#else
57 return true;
58#endif
59}
60
61void OpenTherm::listen() {
62 this->stop_timer_();
63 this->timeout_counter_ = this->device_timeout_ * 5; // timer_ ticks at 5 ticks/ms
64
65 this->mode_ = OperationMode::LISTEN;
66 this->data_ = 0;
67 this->bit_pos_ = 0;
68
69 this->start_read_timer_();
70}
71
72void OpenTherm::send(OpenthermData &data) {
73 this->stop_timer_();
74 this->data_ = data.type;
75 this->data_ = (this->data_ << 12) | data.id;
76 this->data_ = (this->data_ << 8) | data.valueHB;
77 this->data_ = (this->data_ << 8) | data.valueLB;
78 if (!check_parity_(this->data_)) {
79 this->data_ = this->data_ | 0x80000000;
80 }
81
82 this->clock_ = 1; // clock starts at HIGH
83 this->bit_pos_ = 33; // count down (33 == start bit, 32-1 data, 0 == stop bit)
84 this->mode_ = OperationMode::WRITE;
85
86 this->start_write_timer_();
87}
88
89bool OpenTherm::get_message(OpenthermData &data) {
90 if (this->mode_ == OperationMode::RECEIVED) {
91 data.type = (this->data_ >> 28) & 0x7;
92 data.id = (this->data_ >> 16) & 0xFF;
93 data.valueHB = (this->data_ >> 8) & 0xFF;
94 data.valueLB = this->data_ & 0xFF;
95 return true;
96 }
97 return false;
98}
99
100bool OpenTherm::get_protocol_error(OpenThermError &error) {
101 if (this->mode_ != OperationMode::ERROR_PROTOCOL) {
102 return false;
103 }
104
105 error.error_type = this->error_type_;
106 error.bit_pos = this->bit_pos_;
107 error.capture = this->capture_;
108 error.clock = this->clock_;
109 error.data = this->data_;
110
111 return true;
112}
113
114void OpenTherm::stop() {
115 this->stop_timer_();
116 this->mode_ = OperationMode::IDLE;
117}
118
119void IRAM_ATTR OpenTherm::read_() {
120 this->data_ = 0;
121 this->bit_pos_ = 0;
122 this->mode_ = OperationMode::READ;
123 this->capture_ = 1; // reset counter and add as if read start bit
124 this->clock_ = 1; // clock is high at the start of comm
125 this->start_read_timer_(); // get us into 1/4 of manchester code. 5 timer ticks constitute 1 ms, which is 1 bit
126 // period in OpenTherm.
127}
128
129#ifdef USE_ESP32
130bool IRAM_ATTR OpenTherm::timer_isr(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx) {
131 auto *arg = static_cast<OpenTherm *>(user_ctx);
132#else
133bool IRAM_ATTR OpenTherm::timer_isr(OpenTherm *arg) {
134#endif
135 if (arg->mode_ == OperationMode::LISTEN) {
136 if (arg->timeout_counter_ == 0) {
137 arg->mode_ = OperationMode::ERROR_TIMEOUT;
138 arg->stop_timer_();
139 return false;
140 }
141 bool const value = arg->isr_in_pin_.digital_read();
142 if (value) { // incoming data (rising signal)
143 arg->read_();
144 }
145 if (arg->timeout_counter_ > 0) {
146 arg->timeout_counter_--;
147 }
148 } else if (arg->mode_ == OperationMode::READ) {
149 bool const value = arg->isr_in_pin_.digital_read();
150 uint8_t const last = (arg->capture_ & 1);
151 if (value != last) {
152 // transition of signal from last sampling
153 if (arg->clock_ == 1 && arg->capture_ > 0xF) {
154 // no transition in the middle of the bit
155 arg->mode_ = OperationMode::ERROR_PROTOCOL;
156 arg->error_type_ = ProtocolErrorType::NO_TRANSITION;
157 arg->stop_timer_();
158 return false;
159 } else if (arg->clock_ == 1 || arg->capture_ > 0xF) {
160 // transition in the middle of the bit OR no transition between two bit, both are valid data points
161 if (arg->bit_pos_ == BitPositions::STOP_BIT) {
162 // expecting stop bit
163 auto stop_bit_error = arg->verify_stop_bit_(last);
164 if (stop_bit_error == ProtocolErrorType::NO_ERROR) {
165 arg->mode_ = OperationMode::RECEIVED;
166 arg->stop_timer_();
167 return false;
168 } else {
169 // end of data not verified, invalid data
170 arg->mode_ = OperationMode::ERROR_PROTOCOL;
171 arg->error_type_ = stop_bit_error;
172 arg->stop_timer_();
173 return false;
174 }
175 } else {
176 // normal data point at clock high
177 arg->bit_read_(last);
178 arg->clock_ = 0;
179 }
180 } else {
181 // clock low, not a data point, switch clock
182 arg->clock_ = 1;
183 }
184 arg->capture_ = 1; // reset counter
185 } else if (arg->capture_ > 0xFF) {
186 // no change for too long, invalid manchester encoding
187 arg->mode_ = OperationMode::ERROR_PROTOCOL;
188 arg->error_type_ = ProtocolErrorType::NO_CHANGE_TOO_LONG;
189 arg->stop_timer_();
190 return false;
191 }
192 arg->capture_ = (arg->capture_ << 1) | value;
193 } else if (arg->mode_ == OperationMode::WRITE) {
194 // write data to pin
195 if (arg->bit_pos_ == 33 || arg->bit_pos_ == 0) { // start bit
196 arg->write_bit_(1, arg->clock_);
197 } else { // data bits
198 arg->write_bit_(read_bit(arg->data_, arg->bit_pos_ - 1), arg->clock_);
199 }
200 if (arg->clock_ == 0) {
201 if (arg->bit_pos_ <= 0) { // check termination
202 arg->mode_ = OperationMode::SENT; // all data written
203 arg->stop_timer_();
204 }
205 arg->bit_pos_--;
206 arg->clock_ = 1;
207 } else {
208 arg->clock_ = 0;
209 }
210 }
211
212 return false;
213}
214
215#ifdef ESP8266
216void IRAM_ATTR OpenTherm::esp8266_timer_isr() { OpenTherm::timer_isr(OpenTherm::instance); }
217#endif
218
219void IRAM_ATTR OpenTherm::bit_read_(uint8_t value) {
220 this->data_ = (this->data_ << 1) | value;
221 this->bit_pos_++;
222}
223
224ProtocolErrorType IRAM_ATTR OpenTherm::verify_stop_bit_(uint8_t value) {
225 if (value) { // stop bit detected
226 return check_parity_(this->data_) ? ProtocolErrorType::NO_ERROR : ProtocolErrorType::PARITY_ERROR;
227 } else { // no stop bit detected, error
228 return ProtocolErrorType::INVALID_STOP_BIT;
229 }
230}
231
232void IRAM_ATTR OpenTherm::write_bit_(uint8_t high, uint8_t clock) {
233 if (clock == 1) { // left part of manchester encoding
234 this->isr_out_pin_.digital_write(!high); // low means logical 1 to protocol
235 } else { // right part of manchester encoding
236 this->isr_out_pin_.digital_write(high); // high means logical 0 to protocol
237 }
238}
239
240#ifdef USE_ESP32
241
242bool OpenTherm::init_esp32_timer_() {
243 // 80MHz / 80 = 1MHz resolution (1µs per tick)
244 gptimer_config_t config = {
245 .clk_src = GPTIMER_CLK_SRC_DEFAULT,
246 .direction = GPTIMER_COUNT_UP,
247 .resolution_hz = 1000000,
248 };
249
250 esp_err_t result = gptimer_new_timer(&config, &this->timer_handle_);
251 if (result != ESP_OK) {
252 ESP_LOGE(TAG, "Failed to create timer: %s", esp_err_to_name(result));
253 return false;
254 }
255
256 gptimer_event_callbacks_t cbs = {
257 .on_alarm = OpenTherm::timer_isr,
258 };
259 result = gptimer_register_event_callbacks(this->timer_handle_, &cbs, this);
260 if (result != ESP_OK) {
261 ESP_LOGE(TAG, "Failed to register timer callback: %s", esp_err_to_name(result));
262 gptimer_del_timer(this->timer_handle_);
263 this->timer_handle_ = nullptr;
264 return false;
265 }
266
267 result = gptimer_enable(this->timer_handle_);
268 if (result != ESP_OK) {
269 ESP_LOGE(TAG, "Failed to enable timer: %s", esp_err_to_name(result));
270 gptimer_del_timer(this->timer_handle_);
271 this->timer_handle_ = nullptr;
272 return false;
273 }
274
275 return true;
276}
277
278void IRAM_ATTR OpenTherm::start_esp32_timer_(uint64_t alarm_value) {
279 // We will report timer errors outside of interrupt handler
280 this->timer_error_ = ESP_OK;
281 this->timer_error_type_ = TimerErrorType::NO_TIMER_ERROR;
282
283 this->alarm_config_.alarm_count = alarm_value;
284 this->timer_error_ = gptimer_set_alarm_action(this->timer_handle_, &this->alarm_config_);
285 if (this->timer_error_ != ESP_OK) {
286 this->timer_error_type_ = TimerErrorType::SET_ALARM_VALUE_ERROR;
287 return;
288 }
289 this->timer_error_ = gptimer_start(this->timer_handle_);
290 if (this->timer_error_ != ESP_OK) {
291 this->timer_error_type_ = TimerErrorType::TIMER_START_ERROR;
292 }
293}
294
295void OpenTherm::report_and_reset_timer_error() {
296 if (this->timer_error_ == ESP_OK) {
297 return;
298 }
299
300 ESP_LOGE(TAG, "Error occured while manipulating timer (%s): %s", this->timer_error_to_str(this->timer_error_type_),
301 esp_err_to_name(this->timer_error_));
302
303 this->timer_error_ = ESP_OK;
304 this->timer_error_type_ = NO_TIMER_ERROR;
305}
306
307// 5 kHz timer_
308void IRAM_ATTR OpenTherm::start_read_timer_() {
309 InterruptLock const lock;
310 this->start_esp32_timer_(200);
311}
312
313// 2 kHz timer_
314void IRAM_ATTR OpenTherm::start_write_timer_() {
315 InterruptLock const lock;
316 this->start_esp32_timer_(500);
317}
318
319void IRAM_ATTR OpenTherm::stop_timer_() {
320 InterruptLock const lock;
321 // We will report timer errors outside of interrupt handler
322 this->timer_error_ = ESP_OK;
323 this->timer_error_type_ = TimerErrorType::NO_TIMER_ERROR;
324
325 this->timer_error_ = gptimer_stop(this->timer_handle_);
326 if (this->timer_error_ != ESP_OK) {
327 this->timer_error_type_ = TimerErrorType::TIMER_PAUSE_ERROR;
328 return;
329 }
330 this->timer_error_ = gptimer_set_raw_count(this->timer_handle_, 0);
331 if (this->timer_error_ != ESP_OK) {
332 this->timer_error_type_ = TimerErrorType::SET_COUNTER_VALUE_ERROR;
333 }
334}
335
336#endif // USE_ESP32
337
338#ifdef ESP8266
339// 5 kHz timer_
340void IRAM_ATTR OpenTherm::start_read_timer_() {
341 InterruptLock const lock;
342 timer1_attachInterrupt(OpenTherm::esp8266_timer_isr);
343 timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP); // 5MHz (5 ticks/us - 1677721.4 us max)
344 timer1_write(1000); // 5kHz
345}
346
347// 2 kHz timer_
348void IRAM_ATTR OpenTherm::start_write_timer_() {
349 InterruptLock const lock;
350 timer1_attachInterrupt(OpenTherm::esp8266_timer_isr);
351 timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP); // 5MHz (5 ticks/us - 1677721.4 us max)
352 timer1_write(2500); // 2kHz
353}
354
355void IRAM_ATTR OpenTherm::stop_timer_() {
356 InterruptLock const lock;
357 timer1_disable();
358 timer1_detachInterrupt();
359}
360
361// There is nothing to report on ESP8266
362void OpenTherm::report_and_reset_timer_error() {}
363
364#endif // END ESP8266
365
366// https://stackoverflow.com/questions/21617970/how-to-check-if-value-has-even-parity-of-bits-or-odd
367bool IRAM_ATTR OpenTherm::check_parity_(uint32_t val) {
368 val ^= val >> 16;
369 val ^= val >> 8;
370 val ^= val >> 4;
371 val ^= val >> 2;
372 val ^= val >> 1;
373 return (~val) & 1;
374}
375
376#define TO_STRING_MEMBER(name) \
377 case name: \
378 return #name;
379
380const char *OpenTherm::operation_mode_to_str(OperationMode mode) {
381 switch (mode) {
382 TO_STRING_MEMBER(IDLE)
383 TO_STRING_MEMBER(LISTEN)
384 TO_STRING_MEMBER(READ)
385 TO_STRING_MEMBER(RECEIVED)
386 TO_STRING_MEMBER(WRITE)
387 TO_STRING_MEMBER(SENT)
388 TO_STRING_MEMBER(ERROR_PROTOCOL)
389 TO_STRING_MEMBER(ERROR_TIMEOUT)
390 TO_STRING_MEMBER(ERROR_TIMER)
391 default:
392 return "<INVALID>";
393 }
394}
395const char *OpenTherm::protocol_error_to_str(ProtocolErrorType error_type) {
396 switch (error_type) {
397 TO_STRING_MEMBER(NO_ERROR)
398 TO_STRING_MEMBER(NO_TRANSITION)
399 TO_STRING_MEMBER(INVALID_STOP_BIT)
400 TO_STRING_MEMBER(PARITY_ERROR)
401 TO_STRING_MEMBER(NO_CHANGE_TOO_LONG)
402 default:
403 return "<INVALID>";
404 }
405}
406const char *OpenTherm::timer_error_to_str(TimerErrorType error_type) {
407 switch (error_type) {
408 TO_STRING_MEMBER(NO_TIMER_ERROR)
409 TO_STRING_MEMBER(SET_ALARM_VALUE_ERROR)
410 TO_STRING_MEMBER(TIMER_START_ERROR)
411 TO_STRING_MEMBER(TIMER_PAUSE_ERROR)
412 TO_STRING_MEMBER(SET_COUNTER_VALUE_ERROR)
413 default:
414 return "<INVALID>";
415 }
416}
417const char *OpenTherm::message_type_to_str(MessageType message_type) {
418 switch (message_type) {
419 TO_STRING_MEMBER(READ_DATA)
420 TO_STRING_MEMBER(READ_ACK)
421 TO_STRING_MEMBER(WRITE_DATA)
422 TO_STRING_MEMBER(WRITE_ACK)
423 TO_STRING_MEMBER(INVALID_DATA)
424 TO_STRING_MEMBER(DATA_INVALID)
425 TO_STRING_MEMBER(UNKNOWN_DATAID)
426 default:
427 return "<INVALID>";
428 }
429}
430
431const char *OpenTherm::message_id_to_str(MessageId id) {
432 switch (id) {
433 TO_STRING_MEMBER(STATUS)
434 TO_STRING_MEMBER(CH_SETPOINT)
435 TO_STRING_MEMBER(CONTROLLER_CONFIG)
436 TO_STRING_MEMBER(DEVICE_CONFIG)
437 TO_STRING_MEMBER(COMMAND_CODE)
438 TO_STRING_MEMBER(FAULT_FLAGS)
439 TO_STRING_MEMBER(REMOTE)
440 TO_STRING_MEMBER(COOLING_CONTROL)
441 TO_STRING_MEMBER(CH2_SETPOINT)
442 TO_STRING_MEMBER(CH_SETPOINT_OVERRIDE)
443 TO_STRING_MEMBER(TSP_COUNT)
444 TO_STRING_MEMBER(TSP_COMMAND)
445 TO_STRING_MEMBER(FHB_SIZE)
446 TO_STRING_MEMBER(FHB_COMMAND)
447 TO_STRING_MEMBER(MAX_MODULATION_LEVEL)
448 TO_STRING_MEMBER(MAX_BOILER_CAPACITY)
449 TO_STRING_MEMBER(ROOM_SETPOINT)
450 TO_STRING_MEMBER(MODULATION_LEVEL)
451 TO_STRING_MEMBER(CH_WATER_PRESSURE)
452 TO_STRING_MEMBER(DHW_FLOW_RATE)
453 TO_STRING_MEMBER(DAY_TIME)
454 TO_STRING_MEMBER(DATE)
455 TO_STRING_MEMBER(YEAR)
456 TO_STRING_MEMBER(ROOM_SETPOINT_CH2)
457 TO_STRING_MEMBER(ROOM_TEMP)
458 TO_STRING_MEMBER(FEED_TEMP)
459 TO_STRING_MEMBER(DHW_TEMP)
460 TO_STRING_MEMBER(OUTSIDE_TEMP)
461 TO_STRING_MEMBER(RETURN_WATER_TEMP)
462 TO_STRING_MEMBER(SOLAR_STORE_TEMP)
463 TO_STRING_MEMBER(SOLAR_COLLECT_TEMP)
464 TO_STRING_MEMBER(FEED_TEMP_CH2)
465 TO_STRING_MEMBER(DHW2_TEMP)
466 TO_STRING_MEMBER(EXHAUST_TEMP)
467 TO_STRING_MEMBER(FAN_SPEED)
468 TO_STRING_MEMBER(FLAME_CURRENT)
469 TO_STRING_MEMBER(ROOM_TEMP_CH2)
470 TO_STRING_MEMBER(REL_HUMIDITY)
471 TO_STRING_MEMBER(DHW_BOUNDS)
472 TO_STRING_MEMBER(CH_BOUNDS)
473 TO_STRING_MEMBER(OTC_CURVE_BOUNDS)
474 TO_STRING_MEMBER(DHW_SETPOINT)
475 TO_STRING_MEMBER(MAX_CH_SETPOINT)
476 TO_STRING_MEMBER(OTC_CURVE_RATIO)
477 TO_STRING_MEMBER(HVAC_STATUS)
478 TO_STRING_MEMBER(REL_VENT_SETPOINT)
479 TO_STRING_MEMBER(DEVICE_VENT)
480 TO_STRING_MEMBER(HVAC_VER_ID)
481 TO_STRING_MEMBER(REL_VENTILATION)
482 TO_STRING_MEMBER(REL_HUMID_EXHAUST)
483 TO_STRING_MEMBER(EXHAUST_CO2)
484 TO_STRING_MEMBER(SUPPLY_INLET_TEMP)
485 TO_STRING_MEMBER(SUPPLY_OUTLET_TEMP)
486 TO_STRING_MEMBER(EXHAUST_INLET_TEMP)
487 TO_STRING_MEMBER(EXHAUST_OUTLET_TEMP)
488 TO_STRING_MEMBER(EXHAUST_FAN_SPEED)
489 TO_STRING_MEMBER(SUPPLY_FAN_SPEED)
490 TO_STRING_MEMBER(REMOTE_VENTILATION_PARAM)
491 TO_STRING_MEMBER(NOM_REL_VENTILATION)
492 TO_STRING_MEMBER(HVAC_NUM_TSP)
493 TO_STRING_MEMBER(HVAC_IDX_TSP)
494 TO_STRING_MEMBER(HVAC_FHB_SIZE)
495 TO_STRING_MEMBER(HVAC_FHB_IDX)
496 TO_STRING_MEMBER(RF_SIGNAL)
497 TO_STRING_MEMBER(DHW_MODE)
498 TO_STRING_MEMBER(OVERRIDE_FUNC)
499 TO_STRING_MEMBER(SOLAR_MODE_FLAGS)
500 TO_STRING_MEMBER(SOLAR_ASF)
501 TO_STRING_MEMBER(SOLAR_VERSION_ID)
502 TO_STRING_MEMBER(SOLAR_PRODUCT_ID)
503 TO_STRING_MEMBER(SOLAR_NUM_TSP)
504 TO_STRING_MEMBER(SOLAR_IDX_TSP)
505 TO_STRING_MEMBER(SOLAR_FHB_SIZE)
506 TO_STRING_MEMBER(SOLAR_FHB_IDX)
507 TO_STRING_MEMBER(SOLAR_STARTS)
508 TO_STRING_MEMBER(SOLAR_HOURS)
509 TO_STRING_MEMBER(SOLAR_ENERGY)
510 TO_STRING_MEMBER(SOLAR_TOTAL_ENERGY)
511 TO_STRING_MEMBER(FAILED_BURNER_STARTS)
512 TO_STRING_MEMBER(BURNER_FLAME_LOW)
513 TO_STRING_MEMBER(OEM_DIAGNOSTIC)
514 TO_STRING_MEMBER(BURNER_STARTS)
515 TO_STRING_MEMBER(CH_PUMP_STARTS)
516 TO_STRING_MEMBER(DHW_PUMP_STARTS)
517 TO_STRING_MEMBER(DHW_BURNER_STARTS)
518 TO_STRING_MEMBER(BURNER_HOURS)
519 TO_STRING_MEMBER(CH_PUMP_HOURS)
520 TO_STRING_MEMBER(DHW_PUMP_HOURS)
521 TO_STRING_MEMBER(DHW_BURNER_HOURS)
522 TO_STRING_MEMBER(OT_VERSION_CONTROLLER)
523 TO_STRING_MEMBER(OT_VERSION_DEVICE)
524 TO_STRING_MEMBER(VERSION_CONTROLLER)
525 TO_STRING_MEMBER(VERSION_DEVICE)
526 default:
527 return "<INVALID>";
528 }
529}
530
531void OpenTherm::debug_data(OpenthermData &data) {
532 char type_buf[9], id_buf[9], hb_buf[9], lb_buf[9];
533 ESP_LOGD(TAG, "%s %s %s %s", format_bin_to(type_buf, data.type), format_bin_to(id_buf, data.id),
534 format_bin_to(hb_buf, data.valueHB), format_bin_to(lb_buf, data.valueLB));
535 ESP_LOGD(TAG, "type: %s; id: %u; HB: %u; LB: %u; uint_16: %u; float: %f",
536 this->message_type_to_str((MessageType) data.type), data.id, data.valueHB, data.valueLB, data.u16(),
537 data.f88());
538}
539void OpenTherm::debug_error(OpenThermError &error) const {
540 ESP_LOGD(TAG, "data: 0x%08" PRIx32 "; clock: %u; capture: 0x%08" PRIx32 "; bit_pos: %u", error.data, this->clock_,
541 error.capture, error.bit_pos);
542}
543
544float OpenthermData::f88() { return ((float) this->s16()) / 256.0; }
545
546void OpenthermData::f88(float value) { this->s16((int16_t) (value * 256)); }
547
548uint16_t OpenthermData::u16() {
549 uint16_t const value = this->valueHB;
550 return (value << 8) | this->valueLB;
551}
552
553void OpenthermData::u16(uint16_t value) {
554 this->valueLB = value & 0xFF;
555 this->valueHB = (value >> 8) & 0xFF;
556}
557
558int16_t OpenthermData::s16() {
559 int16_t const value = this->valueHB;
560 return (value << 8) | this->valueLB;
561}
562
563void OpenthermData::s16(int16_t value) {
564 this->valueLB = value & 0xFF;
565 this->valueHB = (value >> 8) & 0xFF;
566}
567
568} // namespace esphome::opentherm
BedjetMode mode
BedJet operating mode.
OpenTherm(InternalGPIOPin *in_pin, InternalGPIOPin *out_pin, int32_t device_timeout=800)
mopeka_std_values val[3]
const std::vector< uint8_t > & data
constexpr T read_bit(T value, uint8_t bit)
Definition opentherm.h:21
const char *const TAG
Definition spi.cpp:7
const char * message_type_to_str(MessageType t)
char * format_bin_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as binary string to buffer.
Definition helpers.cpp:378
static void uint32_t