ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
toshiba.cpp
Go to the documentation of this file.
1#include "toshiba.h"
3
4#include <vector>
5
6namespace esphome {
7namespace toshiba {
8
9struct RacPt1411hwruFanSpeed {
10 uint8_t code1;
11 uint8_t code2;
12};
13
14static const char *const TAG = "toshiba.climate";
15// Timings for IR bits/data
16const uint16_t TOSHIBA_HEADER_MARK = 4380;
17const uint16_t TOSHIBA_HEADER_SPACE = 4370;
18const uint16_t TOSHIBA_GAP_SPACE = 5480;
19const uint16_t TOSHIBA_PACKET_SPACE = 10500;
20const uint16_t TOSHIBA_BIT_MARK = 540;
21const uint16_t TOSHIBA_ZERO_SPACE = 540;
22const uint16_t TOSHIBA_ONE_SPACE = 1620;
23const uint16_t TOSHIBA_CARRIER_FREQUENCY = 38000;
24const uint8_t TOSHIBA_HEADER_LENGTH = 4;
25// Generic Toshiba commands/flags
26const uint8_t TOSHIBA_COMMAND_DEFAULT = 0x01;
27const uint8_t TOSHIBA_COMMAND_TIMER = 0x02;
28const uint8_t TOSHIBA_COMMAND_POWER = 0x08;
29const uint8_t TOSHIBA_COMMAND_MOTION = 0x02;
30
31const uint8_t TOSHIBA_MODE_AUTO = 0x00;
32const uint8_t TOSHIBA_MODE_COOL = 0x01;
33const uint8_t TOSHIBA_MODE_DRY = 0x02;
34const uint8_t TOSHIBA_MODE_HEAT = 0x03;
35const uint8_t TOSHIBA_MODE_FAN_ONLY = 0x04;
36const uint8_t TOSHIBA_MODE_OFF = 0x07;
37
38const uint8_t TOSHIBA_FAN_SPEED_AUTO = 0x00;
39const uint8_t TOSHIBA_FAN_SPEED_QUIET = 0x20;
40const uint8_t TOSHIBA_FAN_SPEED_1 = 0x40;
41const uint8_t TOSHIBA_FAN_SPEED_2 = 0x60;
42const uint8_t TOSHIBA_FAN_SPEED_3 = 0x80;
43const uint8_t TOSHIBA_FAN_SPEED_4 = 0xa0;
44const uint8_t TOSHIBA_FAN_SPEED_5 = 0xc0;
45
46const uint8_t TOSHIBA_POWER_HIGH = 0x01;
47const uint8_t TOSHIBA_POWER_ECO = 0x03;
48
49const uint8_t TOSHIBA_MOTION_SWING = 0x04;
50const uint8_t TOSHIBA_MOTION_FIX = 0x00;
51
52// RAC-PT1411HWRU temperature code flag bits
53const uint8_t RAC_PT1411HWRU_FLAG_FAH = 0x01;
54const uint8_t RAC_PT1411HWRU_FLAG_FRAC = 0x20;
55const uint8_t RAC_PT1411HWRU_FLAG_NEG = 0x10;
56// RAC-PT1411HWRU temperature short code flags mask
57const uint8_t RAC_PT1411HWRU_FLAG_MASK = 0x0F;
58// RAC-PT1411HWRU Headers, Footers and such
59const uint8_t RAC_PT1411HWRU_MESSAGE_HEADER0 = 0xB2;
60const uint8_t RAC_PT1411HWRU_MESSAGE_HEADER1 = 0xD5;
62// RAC-PT1411HWRU "Comfort Sense" feature bits
63const uint8_t RAC_PT1411HWRU_CS_ENABLED = 0x40;
64const uint8_t RAC_PT1411HWRU_CS_DATA = 0x80;
65const uint8_t RAC_PT1411HWRU_CS_HEADER = 0xBA;
66const uint8_t RAC_PT1411HWRU_CS_FOOTER_AUTO = 0x7A;
67const uint8_t RAC_PT1411HWRU_CS_FOOTER_COOL = 0x72;
68const uint8_t RAC_PT1411HWRU_CS_FOOTER_HEAT = 0x7E;
69// RAC-PT1411HWRU Swing
70const uint8_t RAC_PT1411HWRU_SWING_HEADER = 0xB9;
71const std::vector<uint8_t> RAC_PT1411HWRU_SWING_VERTICAL{0xB9, 0x46, 0xF5, 0x0A, 0x04, 0xFB};
72const std::vector<uint8_t> RAC_PT1411HWRU_SWING_OFF{0xB9, 0x46, 0xF5, 0x0A, 0x05, 0xFA};
73// RAC-PT1411HWRU Fan speeds
74const uint8_t RAC_PT1411HWRU_FAN_OFF = 0x7B;
75constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_AUTO{0xBF, 0x66};
76constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_LOW{0x9F, 0x28};
77constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_MED{0x5F, 0x3C};
78constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_HIGH{0x3F, 0x64};
79// RAC-PT1411HWRU Fan speed for Auto and Dry climate modes
80const RacPt1411hwruFanSpeed RAC_PT1411HWRU_NO_FAN{0x1F, 0x65};
81// RAC-PT1411HWRU Modes
82const uint8_t RAC_PT1411HWRU_MODE_AUTO = 0x08;
83const uint8_t RAC_PT1411HWRU_MODE_COOL = 0x00;
84const uint8_t RAC_PT1411HWRU_MODE_DRY = 0x04;
85const uint8_t RAC_PT1411HWRU_MODE_FAN = 0x04;
86const uint8_t RAC_PT1411HWRU_MODE_HEAT = 0x0C;
87const uint8_t RAC_PT1411HWRU_MODE_OFF = 0x00;
88// RAC-PT1411HWRU Fan-only "temperature"/system off
90// RAC-PT1411HWRU temperature codes are not sequential; they instead follow a modified Gray code.
91// Hence these look-up tables. In addition, the upper nibble is used here for additional
92// "negative" and "fractional value" flags as required for some temperatures.
93// RAC-PT1411HWRU °C Temperatures (short codes)
94const std::vector<uint8_t> RAC_PT1411HWRU_TEMPERATURE_C{0x10, 0x00, 0x01, 0x03, 0x02, 0x06, 0x07, 0x05,
95 0x04, 0x0C, 0x0D, 0x09, 0x08, 0x0A, 0x0B};
96// RAC-PT1411HWRU °F Temperatures (short codes)
97const std::vector<uint8_t> RAC_PT1411HWRU_TEMPERATURE_F{0x10, 0x30, 0x00, 0x20, 0x01, 0x21, 0x03, 0x23, 0x02,
98 0x22, 0x06, 0x26, 0x07, 0x05, 0x25, 0x04, 0x24, 0x0C,
99 0x2C, 0x0D, 0x2D, 0x09, 0x08, 0x28, 0x0A, 0x2A, 0x0B};
100
101// RAS-2819T protocol constants
102const uint16_t RAS_2819T_HEADER1 = 0xC23D;
103const uint8_t RAS_2819T_HEADER2 = 0xD5;
104const uint8_t RAS_2819T_MESSAGE_LENGTH = 6;
105
106// RAS-2819T fan speed codes for rc_code_1 (bytes 2-3)
107const uint16_t RAS_2819T_FAN_AUTO = 0xBF40;
108const uint16_t RAS_2819T_FAN_QUIET = 0xFF00;
109const uint16_t RAS_2819T_FAN_LOW = 0x9F60;
110const uint16_t RAS_2819T_FAN_MEDIUM = 0x5FA0;
111const uint16_t RAS_2819T_FAN_HIGH = 0x3FC0;
112
113// RAS-2819T fan speed codes for rc_code_2 (byte 1)
114const uint8_t RAS_2819T_FAN2_AUTO = 0x66;
115const uint8_t RAS_2819T_FAN2_QUIET = 0x01;
116const uint8_t RAS_2819T_FAN2_LOW = 0x28;
117const uint8_t RAS_2819T_FAN2_MEDIUM = 0x3C;
118const uint8_t RAS_2819T_FAN2_HIGH = 0x50;
119
120// RAS-2819T second packet suffix bytes for rc_code_2 (bytes 3-5)
121// These are fixed patterns, not actual checksums
122struct Ras2819tPacketSuffix {
123 uint8_t byte3;
124 uint8_t byte4;
125 uint8_t byte5;
126};
127const Ras2819tPacketSuffix RAS_2819T_SUFFIX_AUTO{0x00, 0x02, 0x3D};
128const Ras2819tPacketSuffix RAS_2819T_SUFFIX_QUIET{0x00, 0x02, 0xD8};
129const Ras2819tPacketSuffix RAS_2819T_SUFFIX_LOW{0x00, 0x02, 0xFF};
130const Ras2819tPacketSuffix RAS_2819T_SUFFIX_MEDIUM{0x00, 0x02, 0x13};
131const Ras2819tPacketSuffix RAS_2819T_SUFFIX_HIGH{0x00, 0x02, 0x27};
132
133// RAS-2819T swing toggle command
134const uint64_t RAS_2819T_SWING_TOGGLE = 0xC23D6B94E01F;
135
136// RAS-2819T single-packet commands
137const uint64_t RAS_2819T_POWER_OFF_COMMAND = 0xC23D7B84E01F;
138
139// RAS-2819T known valid command patterns for validation
140const std::array<uint64_t, 2> RAS_2819T_VALID_SINGLE_COMMANDS = {
141 RAS_2819T_POWER_OFF_COMMAND, // Power off
142 RAS_2819T_SWING_TOGGLE, // Swing toggle
143};
144
145const uint16_t RAS_2819T_VALID_HEADER1 = 0xC23D;
146const uint8_t RAS_2819T_VALID_HEADER2 = 0xD5;
147
148const uint8_t RAS_2819T_DRY_BYTE2 = 0x1F;
149const uint8_t RAS_2819T_DRY_BYTE3 = 0xE0;
150const uint8_t RAS_2819T_DRY_TEMP_OFFSET = 0x24;
151
152const uint8_t RAS_2819T_AUTO_BYTE2 = 0x1F;
153const uint8_t RAS_2819T_AUTO_BYTE3 = 0xE0;
154const uint8_t RAS_2819T_AUTO_TEMP_OFFSET = 0x08;
155
156const uint8_t RAS_2819T_FAN_ONLY_TEMP = 0xE4;
157const uint8_t RAS_2819T_FAN_ONLY_TEMP_INV = 0x1B;
158
159const uint8_t RAS_2819T_HEAT_TEMP_OFFSET = 0x0C;
160
161// RAS-2819T second packet fixed values
162const uint8_t RAS_2819T_AUTO_DRY_FAN_BYTE = 0x65;
163const uint8_t RAS_2819T_AUTO_DRY_SUFFIX = 0x3A;
164const uint8_t RAS_2819T_HEAT_SUFFIX = 0x3B;
165
166// RAS-2819T temperature codes for 18-30°C
167static const uint8_t RAS_2819T_TEMP_CODES[] = {
168 0x10, // 18°C
169 0x30, // 19°C
170 0x20, // 20°C
171 0x60, // 21°C
172 0x70, // 22°C
173 0x50, // 23°C
174 0x40, // 24°C
175 0xC0, // 25°C
176 0xD0, // 26°C
177 0x90, // 27°C
178 0x80, // 28°C
179 0xA0, // 29°C
180 0xB0 // 30°C
181};
182
183// Helper functions for RAS-2819T protocol
184//
185// ===== RAS-2819T PROTOCOL DOCUMENTATION =====
186//
187// The RAS-2819T uses a two-packet IR protocol with some exceptions for simple commands.
188//
189// PACKET STRUCTURE:
190// All packets are 6 bytes (48 bits) transmitted with standard Toshiba timing.
191//
192// TWO-PACKET COMMANDS (Mode/Temperature/Fan changes):
193//
194// First Packet (rc_code_1): [C2 3D] [FAN_HI FAN_LO] [TEMP] [~TEMP]
195// Byte 0-1: Header (always 0xC23D)
196// Byte 2-3: Fan speed encoding (varies by mode, see fan tables below)
197// Byte 4: Temperature + mode encoding
198// Byte 5: Bitwise complement of temperature byte
199//
200// Second Packet (rc_code_2): [D5] [FAN2] [00] [SUF1] [SUF2] [SUF3]
201// Byte 0: Header (always 0xD5)
202// Byte 1: Fan speed secondary encoding
203// Byte 2: Always 0x00
204// Byte 3-5: Fixed suffix pattern (depends on fan speed and mode)
205//
206// TEMPERATURE ENCODING:
207// Base temp codes: 18°C=0x10, 19°C=0x30, 20°C=0x20, 21°C=0x60, 22°C=0x70,
208// 23°C=0x50, 24°C=0x40, 25°C=0xC0, 26°C=0xD0, 27°C=0x90,
209// 28°C=0x80, 29°C=0xA0, 30°C=0xB0
210// Mode offsets added to base temp:
211// COOL: No offset
212// HEAT: +0x0C (e.g., 24°C heat = 0x40 | 0x0C = 0x4C)
213// AUTO: +0x08 (e.g., 24°C auto = 0x40 | 0x08 = 0x48)
214// DRY: +0x24 (e.g., 24°C dry = 0x40 | 0x24 = 0x64)
215//
216// FAN SPEED ENCODING (First packet bytes 2-3):
217// AUTO: 0xBF40, QUIET: 0xFF00, LOW: 0x9F60, MEDIUM: 0x5FA0, HIGH: 0x3FC0
218// Special cases: AUTO/DRY modes use 0x1FE0 instead
219//
220// SINGLE-PACKET COMMANDS:
221// Power Off: 0xC23D7B84E01F (6 bytes, no second packet)
222// Swing Toggle: 0xC23D6B94E01F (6 bytes, no second packet)
223//
224// MODE DETECTION (from first packet):
225// - Check bytes 2-3: if 0x7B84 → OFF mode
226// - Check bytes 2-3: if 0x1FE0 → AUTO/DRY/low-temp-COOL (distinguish by temp code)
227// - Otherwise: COOL/HEAT/FAN_ONLY (distinguish by temp code and byte 5)
228
232static uint16_t get_ras_2819t_fan_code(climate::ClimateFanMode fan_mode) {
233 switch (fan_mode) {
235 return RAS_2819T_FAN_QUIET;
237 return RAS_2819T_FAN_LOW;
241 return RAS_2819T_FAN_HIGH;
243 default:
244 return RAS_2819T_FAN_AUTO;
245 }
246}
247
251struct Ras2819tSecondPacketCodes {
252 uint8_t fan_byte;
253 Ras2819tPacketSuffix suffix;
254};
255
256static Ras2819tSecondPacketCodes get_ras_2819t_second_packet_codes(climate::ClimateFanMode fan_mode) {
257 switch (fan_mode) {
267 default:
269 }
270}
271
275static uint8_t get_ras_2819t_temp_code(float temperature) {
276 int temp_index = static_cast<int>(temperature) - 18;
277 if (temp_index < 0 || temp_index >= static_cast<int>(sizeof(RAS_2819T_TEMP_CODES))) {
278 ESP_LOGW(TAG, "Temperature %.1f°C out of range [18-30°C], defaulting to 24°C", temperature);
279 return 0x40; // Default to 24°C
280 }
281
282 return RAS_2819T_TEMP_CODES[temp_index];
283}
284
288static float decode_ras_2819t_temperature(uint8_t temp_code) {
289 uint8_t base_temp_code = temp_code & 0xF0;
290
291 // Find the code in the temperature array
292 for (size_t temp_index = 0; temp_index < sizeof(RAS_2819T_TEMP_CODES); temp_index++) {
293 if (RAS_2819T_TEMP_CODES[temp_index] == base_temp_code) {
294 return static_cast<float>(temp_index + 18); // 18°C is the minimum
295 }
296 }
297
298 ESP_LOGW(TAG, "Unknown temp code: 0x%02X, defaulting to 24°C", base_temp_code);
299 return 24.0f; // Default to 24°C
300}
301
305static climate::ClimateFanMode decode_ras_2819t_fan_mode(uint16_t fan_code) {
306 switch (fan_code) {
316 default:
318 }
319}
320
324static bool is_valid_ras_2819t_command(uint64_t rc_code_1, uint64_t rc_code_2 = 0) {
325 // Check header of first packet
326 uint16_t header1 = (rc_code_1 >> 32) & 0xFFFF;
327 if (header1 != RAS_2819T_VALID_HEADER1) {
328 return false;
329 }
330
331 // Single packet commands
332 if (rc_code_2 == 0) {
333 for (uint64_t valid_cmd : RAS_2819T_VALID_SINGLE_COMMANDS) {
334 if (rc_code_1 == valid_cmd) {
335 return true;
336 }
337 }
338 // Additional validation for unknown single packets
339 return false;
340 }
341
342 // Two-packet commands - validate second packet header
343 uint8_t header2 = (rc_code_2 >> 40) & 0xFF;
344 if (header2 != RAS_2819T_VALID_HEADER2) {
345 return false;
346 }
347
348 // Validate temperature complement in first packet (byte 4 should be ~byte 5)
349 uint8_t temp_byte = (rc_code_1 >> 8) & 0xFF;
350 uint8_t temp_complement = rc_code_1 & 0xFF;
351 if (temp_byte != static_cast<uint8_t>(~temp_complement)) {
352 return false;
353 }
354
355 // Validate fan speed combinations make sense
356 uint16_t fan_code = (rc_code_1 >> 16) & 0xFFFF;
357 uint8_t fan2_byte = (rc_code_2 >> 32) & 0xFF;
358
359 // Check if fan codes are from known valid patterns
360 bool valid_fan_combo = false;
361 if (fan_code == RAS_2819T_FAN_AUTO && fan2_byte == RAS_2819T_FAN2_AUTO)
362 valid_fan_combo = true;
363 if (fan_code == RAS_2819T_FAN_QUIET && fan2_byte == RAS_2819T_FAN2_QUIET)
364 valid_fan_combo = true;
365 if (fan_code == RAS_2819T_FAN_LOW && fan2_byte == RAS_2819T_FAN2_LOW)
366 valid_fan_combo = true;
367 if (fan_code == RAS_2819T_FAN_MEDIUM && fan2_byte == RAS_2819T_FAN2_MEDIUM)
368 valid_fan_combo = true;
369 if (fan_code == RAS_2819T_FAN_HIGH && fan2_byte == RAS_2819T_FAN2_HIGH)
370 valid_fan_combo = true;
371 if (fan_code == 0x1FE0 && fan2_byte == RAS_2819T_AUTO_DRY_FAN_BYTE)
372 valid_fan_combo = true; // AUTO/DRY
373
374 return valid_fan_combo;
375}
376
378 if (this->sensor_) {
379 this->sensor_->add_on_state_callback([this](float state) {
382 // current temperature changed, publish state
383 this->publish_state();
384 });
385 this->current_temperature = this->sensor_->state;
386 } else {
387 this->current_temperature = NAN;
388 }
389 // restore set points
390 auto restore = this->restore_state_();
391 if (restore.has_value()) {
392 restore->apply(this);
393 } else {
394 // restore from defaults
396 // initialize target temperature to some value so that it's not NAN
397 this->target_temperature =
398 roundf(clamp<float>(this->current_temperature, this->minimum_temperature_, this->maximum_temperature_));
399 this->fan_mode = climate::CLIMATE_FAN_AUTO;
401 }
402 // Set supported modes & temperatures based on model
403 this->minimum_temperature_ = this->temperature_min_();
404 this->maximum_temperature_ = this->temperature_max_();
405 this->swing_modes_ = this->toshiba_swing_modes_();
406
407 // Ensure swing mode is always initialized to a valid value
408 if (this->swing_modes_.empty() || !this->swing_modes_.count(this->swing_mode)) {
409 // No swing support for this model or current swing mode not supported, reset to OFF
411 }
412
413 // Ensure mode is valid - ESPHome should only use standard climate modes
417 ESP_LOGW(TAG, "Invalid mode detected during setup, resetting to OFF");
419 }
420
421 // Ensure fan mode is valid
422 if (!this->fan_mode.has_value()) {
423 ESP_LOGW(TAG, "Fan mode not set during setup, defaulting to AUTO");
424 this->fan_mode = climate::CLIMATE_FAN_AUTO;
425 }
426
427 // Never send nan to HA
428 if (std::isnan(this->target_temperature))
429 this->target_temperature = 24;
430 // Log final state for debugging HA errors
431 ESP_LOGV(TAG, "Setup complete - Mode: %d, Fan: %s, Swing: %d, Temp: %.1f", static_cast<int>(this->mode),
432 this->fan_mode.has_value() ? std::to_string(static_cast<int>(this->fan_mode.value())).c_str() : "NONE",
433 static_cast<int>(this->swing_mode), this->target_temperature);
434}
435
437 if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F) {
439 } else if (this->model_ == MODEL_RAS_2819T) {
440 this->transmit_ras_2819t_();
441 } else {
442 this->transmit_generic_();
443 }
444}
445
447 uint8_t message[16] = {0};
448 uint8_t message_length = 9;
449
450 // Header
451 message[0] = 0xf2;
452 message[1] = 0x0d;
453
454 // Message length
455 message[2] = message_length - 6;
456
457 // First checksum
458 message[3] = message[0] ^ message[1] ^ message[2];
459
460 // Command
462
463 // Temperature
464 uint8_t temperature = static_cast<uint8_t>(
466 message[5] = (temperature - static_cast<uint8_t>(TOSHIBA_GENERIC_TEMP_C_MIN)) << 4;
467
468 // Mode and fan
469 uint8_t mode;
470 switch (this->mode) {
473 break;
474
477 break;
478
481 break;
482
485 break;
486
489 break;
490
492 default:
494 }
495
496 uint8_t fan;
497 switch (this->fan_mode.value()) {
500 break;
501
504 break;
505
508 break;
509
512 break;
513
515 default:
517 break;
518 }
519 message[6] = fan | mode;
520
521 // Zero
522 message[7] = 0x00;
523
524 // If timers bit in the command is set, two extra bytes are added here
525
526 // If power bit is set in the command, one extra byte is added here
527
528 // The last byte is the xor of all bytes from [4]
529 for (uint8_t i = 4; i < 8; i++) {
530 message[8] ^= message[i];
531 }
532
533 // Transmit
534 auto transmit = this->transmitter_->transmit();
535 auto *data = transmit.get_data();
536
537 this->encode_(data, message, message_length, 1);
538
539 transmit.perform();
540}
541
543 uint8_t code = 0, index = 0, message[RAC_PT1411HWRU_MESSAGE_LENGTH * 2] = {0};
544 float temperature =
547 auto transmit = this->transmitter_->transmit();
548 auto *data = transmit.get_data();
549
550 // Byte 0: Header upper (0xB2)
552 // Byte 1: Header lower (0x4D)
553 message[1] = ~message[0];
554 // Byte 2u: Fan speed
555 // Byte 2l: 1111 (on) or 1011 (off)
556 if (this->mode == climate::CLIMATE_MODE_OFF) {
558 } else if ((this->mode == climate::CLIMATE_MODE_HEAT_COOL) || (this->mode == climate::CLIMATE_MODE_DRY)) {
561 } else {
562 switch (this->fan_mode.value()) {
566 break;
567
571 break;
572
576 break;
577
579 default:
582 }
583 }
584 // Byte 3u: ~Fan speed
585 // Byte 3l: 0000 (on) or 0100 (off)
586 message[3] = ~message[2];
587 // Byte 4u: Temp
588 if (this->model_ == MODEL_RAC_PT1411HWRU_F) {
589 temperature = (temperature * 1.8) + 32;
591 }
592
593 index = static_cast<uint8_t>(roundf(temp_adjd));
594
595 if (this->model_ == MODEL_RAC_PT1411HWRU_F) {
596 code = RAC_PT1411HWRU_TEMPERATURE_F[index];
598 } else {
599 code = RAC_PT1411HWRU_TEMPERATURE_C[index];
600 }
603 }
604
605 if (code & RAC_PT1411HWRU_FLAG_FRAC) {
607 }
608 if (code & RAC_PT1411HWRU_FLAG_NEG) {
610 }
611 message[4] = (code & RAC_PT1411HWRU_FLAG_MASK) << 4;
612 // Byte 4l: Mode
613 switch (this->mode) {
615 // zerooooo
616 break;
617
620 break;
621
624 break;
625
628 break;
629
632 break;
633
635 default:
637 }
638
639 // Byte 5u: ~Temp
640 // Byte 5l: ~Mode
641 message[5] = ~message[4];
642
643 if (this->mode != climate::CLIMATE_MODE_OFF) {
644 // Byte 6: Header (0xD5)
646 // Byte 7: Fan speed part 2 (done above)
647 // Byte 8: 0x20 for °F frac, else 0 (done above)
648 // Byte 9: 0x10=NEG, 0x01=°F (done above)
649 // Byte 10: 0
650 // Byte 11: Checksum (bytes 6 through 10)
651 for (index = 6; index <= 10; index++) {
652 message[11] += message[index];
653 }
654 }
655
656 // load first block of IR code and repeat it once
657 this->encode_(data, &message[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
658 // load second block of IR code, if present
659 if (message[6] != 0) {
660 this->encode_(data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH, 0);
661 }
662
663 transmit.perform();
664
665 // Swing Mode
666 data->reset();
667 data->space(TOSHIBA_PACKET_SPACE);
668 switch (this->swing_mode) {
671 break;
672
674 default:
675 this->encode_(data, &RAC_PT1411HWRU_SWING_OFF[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
676 }
677
678 data->space(TOSHIBA_PACKET_SPACE);
679 transmit.perform();
680
681 if (this->sensor_) {
682 this->transmit_rac_pt1411hwru_temp_(true, false);
683 }
684}
685
686void ToshibaClimate::transmit_rac_pt1411hwru_temp_(const bool cs_state, const bool cs_send_update) {
687 if ((this->mode == climate::CLIMATE_MODE_HEAT) || (this->mode == climate::CLIMATE_MODE_COOL) ||
690 float temperature = clamp<float>(this->current_temperature, 0.0, TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX + 1);
691 auto transmit = this->transmitter_->transmit();
692 auto *data = transmit.get_data();
693 // "Comfort Sense" feature notes
694 // IR Code: 0xBA45 xxXX yyYY
695 // xx: Temperature in °C
696 // Bit 6: feature state (on/off)
697 // Bit 7: message contains temperature data for feature (bit 6 must also be set)
698 // XX: Bitwise complement of xx
699 // yy: Mode: Auto=0x7A, Cool=0x72, Heat=0x7E
700 // YY: Bitwise complement of yy
701 //
702 // Byte 0: Header upper (0xBA)
704 // Byte 1: Header lower (0x45)
705 message[1] = ~message[0];
706 // Byte 2: Temperature in °C
707 message[2] = static_cast<uint8_t>(roundf(temperature));
708 if (cs_send_update) {
710 } else if (cs_state) {
712 }
713 // Byte 3: Bitwise complement of byte 2
714 message[3] = ~message[2];
715 // Byte 4: Footer upper
716 switch (this->mode) {
719 break;
720
723 break;
724
727
728 default:
729 break;
730 }
731 // Byte 5: Footer lower/bitwise complement of byte 4
732 message[5] = ~message[4];
733
734 // load IR code and repeat it once
735 this->encode_(data, message, RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
736
737 transmit.perform();
738 }
739}
740
742 // Handle swing mode transmission for RAS-2819T
743 // Note: RAS-2819T uses a toggle command, so we need to track state changes
744
745 // Check if ONLY swing mode changed (and no other climate parameters)
746 bool swing_changed = (this->swing_mode != this->last_swing_mode_);
747 bool mode_changed = (this->mode != this->last_mode_);
748 bool fan_changed = (this->fan_mode != this->last_fan_mode_);
749 bool temp_changed = (abs(this->target_temperature - this->last_target_temperature_) > 0.1f);
750
751 bool only_swing_changed = swing_changed && !mode_changed && !fan_changed && !temp_changed;
752
753 if (only_swing_changed) {
754 // Send ONLY swing toggle command (like the physical remote does)
755 auto swing_transmit = this->transmitter_->transmit();
756 auto *swing_data = swing_transmit.get_data();
757
758 // Convert toggle command to bytes for transmission
759 uint8_t swing_message[RAS_2819T_MESSAGE_LENGTH];
760 swing_message[0] = (RAS_2819T_SWING_TOGGLE >> 40) & 0xFF;
761 swing_message[1] = (RAS_2819T_SWING_TOGGLE >> 32) & 0xFF;
762 swing_message[2] = (RAS_2819T_SWING_TOGGLE >> 24) & 0xFF;
763 swing_message[3] = (RAS_2819T_SWING_TOGGLE >> 16) & 0xFF;
764 swing_message[4] = (RAS_2819T_SWING_TOGGLE >> 8) & 0xFF;
765 swing_message[5] = RAS_2819T_SWING_TOGGLE & 0xFF;
766
767 // Use single packet transmission WITH repeat (like regular commands)
768 this->encode_(swing_data, swing_message, RAS_2819T_MESSAGE_LENGTH, 1);
769 swing_transmit.perform();
770
771 // Update all state tracking
772 this->last_swing_mode_ = this->swing_mode;
773 this->last_mode_ = this->mode;
774 this->last_fan_mode_ = this->fan_mode;
775 this->last_target_temperature_ = this->target_temperature;
776
777 // Immediately publish the state change to Home Assistant
778 this->publish_state();
779
780 return; // Exit early - don't send climate command
781 }
782
783 // If we get here, send the regular climate command (temperature/mode/fan)
784 uint8_t message1[RAS_2819T_MESSAGE_LENGTH] = {0};
785 uint8_t message2[RAS_2819T_MESSAGE_LENGTH] = {0};
786 float temperature =
788
789 // Build first packet (RAS_2819T_HEADER1 + 4 bytes)
790 message1[0] = (RAS_2819T_HEADER1 >> 8) & 0xFF;
791 message1[1] = RAS_2819T_HEADER1 & 0xFF;
792
793 // Handle OFF mode
794 if (this->mode == climate::CLIMATE_MODE_OFF) {
795 // Extract bytes from power off command constant
796 message1[2] = (RAS_2819T_POWER_OFF_COMMAND >> 24) & 0xFF;
797 message1[3] = (RAS_2819T_POWER_OFF_COMMAND >> 16) & 0xFF;
798 message1[4] = (RAS_2819T_POWER_OFF_COMMAND >> 8) & 0xFF;
799 message1[5] = RAS_2819T_POWER_OFF_COMMAND & 0xFF;
800 // No second packet for OFF
801 } else {
802 // Get temperature and fan encoding
803 uint8_t temp_code = get_ras_2819t_temp_code(temperature);
804
805 // Get fan speed encoding for rc_code_1
806 climate::ClimateFanMode effective_fan_mode = this->fan_mode.value();
807
808 // Dry mode only supports AUTO fan speed
809 if (this->mode == climate::CLIMATE_MODE_DRY) {
810 effective_fan_mode = climate::CLIMATE_FAN_AUTO;
811 if (this->fan_mode.value() != climate::CLIMATE_FAN_AUTO) {
812 ESP_LOGW(TAG, "Dry mode only supports AUTO fan speed, forcing AUTO");
813 }
814 }
815
816 uint16_t fan_code = get_ras_2819t_fan_code(effective_fan_mode);
817
818 // Mode and temperature encoding
819 switch (this->mode) {
821 // All cooling temperatures support fan speed control
822 message1[2] = (fan_code >> 8) & 0xFF;
823 message1[3] = fan_code & 0xFF;
824 message1[4] = temp_code;
825 message1[5] = ~temp_code;
826 break;
827
829 // Heating supports fan speed control
830 message1[2] = (fan_code >> 8) & 0xFF;
831 message1[3] = fan_code & 0xFF;
832 // Heat mode adds offset to temperature code
833 message1[4] = temp_code | RAS_2819T_HEAT_TEMP_OFFSET;
834 message1[5] = ~(temp_code | RAS_2819T_HEAT_TEMP_OFFSET);
835 break;
836
838 // Auto mode uses fixed encoding
839 message1[2] = RAS_2819T_AUTO_BYTE2;
840 message1[3] = RAS_2819T_AUTO_BYTE3;
841 message1[4] = temp_code | RAS_2819T_AUTO_TEMP_OFFSET;
842 message1[5] = ~(temp_code | RAS_2819T_AUTO_TEMP_OFFSET);
843 break;
844
846 // Dry mode uses fixed encoding and forces AUTO fan
847 message1[2] = RAS_2819T_DRY_BYTE2;
848 message1[3] = RAS_2819T_DRY_BYTE3;
849 message1[4] = temp_code | RAS_2819T_DRY_TEMP_OFFSET;
850 message1[5] = ~message1[4];
851 break;
852
854 // Fan only mode supports fan speed control
855 message1[2] = (fan_code >> 8) & 0xFF;
856 message1[3] = fan_code & 0xFF;
857 message1[4] = RAS_2819T_FAN_ONLY_TEMP;
858 message1[5] = RAS_2819T_FAN_ONLY_TEMP_INV;
859 break;
860
861 default:
862 // Default case supports fan speed control
863 message1[2] = (fan_code >> 8) & 0xFF;
864 message1[3] = fan_code & 0xFF;
865 message1[4] = temp_code;
866 message1[5] = ~temp_code;
867 break;
868 }
869
870 // Build second packet (RAS_2819T_HEADER2 + 4 bytes)
871 message2[0] = RAS_2819T_HEADER2;
872
873 // Get fan speed encoding for rc_code_2
874 Ras2819tSecondPacketCodes second_packet_codes = get_ras_2819t_second_packet_codes(effective_fan_mode);
875
876 // Determine header byte 2 and fan encoding based on mode
877 switch (this->mode) {
879 message2[1] = second_packet_codes.fan_byte;
880 message2[2] = 0x00;
881 message2[3] = second_packet_codes.suffix.byte3;
882 message2[4] = second_packet_codes.suffix.byte4;
883 message2[5] = second_packet_codes.suffix.byte5;
884 break;
885
887 message2[1] = second_packet_codes.fan_byte;
888 message2[2] = 0x00;
889 message2[3] = second_packet_codes.suffix.byte3;
890 message2[4] = 0x00;
891 message2[5] = RAS_2819T_HEAT_SUFFIX;
892 break;
893
896 // Auto/Dry modes use fixed values regardless of fan setting
897 message2[1] = RAS_2819T_AUTO_DRY_FAN_BYTE;
898 message2[2] = 0x00;
899 message2[3] = 0x00;
900 message2[4] = 0x00;
901 message2[5] = RAS_2819T_AUTO_DRY_SUFFIX;
902 break;
903
905 message2[1] = second_packet_codes.fan_byte;
906 message2[2] = 0x00;
907 message2[3] = second_packet_codes.suffix.byte3;
908 message2[4] = 0x00;
909 message2[5] = RAS_2819T_HEAT_SUFFIX;
910 break;
911
912 default:
913 message2[1] = second_packet_codes.fan_byte;
914 message2[2] = 0x00;
915 message2[3] = second_packet_codes.suffix.byte3;
916 message2[4] = second_packet_codes.suffix.byte4;
917 message2[5] = second_packet_codes.suffix.byte5;
918 break;
919 }
920 }
921
922 // Log final messages being transmitted
923
924 // Transmit using proper Toshiba protocol timing
925 auto transmit = this->transmitter_->transmit();
926 auto *data = transmit.get_data();
927
928 // Use existing Toshiba encode function for proper timing
929 this->encode_(data, message1, RAS_2819T_MESSAGE_LENGTH, 1);
930
931 if (this->mode != climate::CLIMATE_MODE_OFF) {
932 // Send second packet with gap
933 this->encode_(data, message2, RAS_2819T_MESSAGE_LENGTH, 0);
934 }
935
936 transmit.perform();
937
938 // Update all state tracking after successful transmission
939 this->last_swing_mode_ = this->swing_mode;
940 this->last_mode_ = this->mode;
941 this->last_fan_mode_ = this->fan_mode;
942 this->last_target_temperature_ = this->target_temperature;
943}
944
946 const std::vector<uint8_t> header{RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER,
948
949 for (auto i : header) {
950 if ((message[0] == i) && (message[1] == static_cast<uint8_t>(~i)))
951 return i;
952 }
955
956 return 0;
957}
958
959bool ToshibaClimate::compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2) {
960 for (uint8_t i = 0; i < RAC_PT1411HWRU_MESSAGE_LENGTH; i++) {
961 if (message1[i] != message2[i])
962 return false;
963 }
964 return true;
965}
966
968 uint8_t checksum = 0;
969
970 switch (this->is_valid_rac_pt1411hwru_header_(message)) {
974 if (this->is_valid_rac_pt1411hwru_header_(message) && (message[2] == static_cast<uint8_t>(~message[3])) &&
975 (message[4] == static_cast<uint8_t>(~message[5]))) {
976 return true;
977 }
978 break;
979
981 for (uint8_t i = 0; i < RAC_PT1411HWRU_MESSAGE_LENGTH - 1; i++) {
982 checksum += message[i];
983 }
985 return true;
986 }
987 break;
988
989 default:
990 return false;
991 }
992
993 return false;
994}
995
997 // Check for power-off command (single packet)
998 if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_POWER_OFF_COMMAND) {
1000 ESP_LOGI(TAG, "Mode: OFF");
1001 this->publish_state();
1002 return true;
1003 }
1004
1005 // Check for swing toggle command (single packet)
1006 if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_SWING_TOGGLE) {
1007 // Toggle swing mode
1010 ESP_LOGI(TAG, "Swing: OFF");
1011 } else {
1013 ESP_LOGI(TAG, "Swing: VERTICAL");
1014 }
1015 this->publish_state();
1016 return true;
1017 }
1018
1019 // Handle regular two-packet commands (mode/temperature/fan changes)
1020 if (toshiba_data.rc_code_2 != 0) {
1021 // Convert to byte array for easier processing
1022 uint8_t message1[6], message2[6];
1023 for (uint8_t i = 0; i < 6; i++) {
1024 message1[i] = (toshiba_data.rc_code_1 >> (40 - i * 8)) & 0xFF;
1025 message2[i] = (toshiba_data.rc_code_2 >> (40 - i * 8)) & 0xFF;
1026 }
1027
1028 // Decode the protocol using message1 (rc_code_1)
1029 uint8_t temp_code = message1[4];
1030
1031 // Decode mode - check bytes 2-3 pattern and temperature code
1032 if ((message1[2] == 0x7B) && (message1[3] == 0x84)) {
1033 // OFF mode has specific pattern
1035 ESP_LOGI(TAG, "Mode: OFF");
1036 } else if ((message1[2] == 0x1F) && (message1[3] == 0xE0)) {
1037 // 0x1FE0 pattern is used for AUTO, DRY, and low-temp COOL
1038 if ((temp_code & 0x0F) == 0x08) {
1040 ESP_LOGI(TAG, "Mode: AUTO");
1041 } else if ((temp_code & 0x0F) == 0x04) {
1043 ESP_LOGI(TAG, "Mode: DRY");
1044 } else {
1046 ESP_LOGI(TAG, "Mode: COOL (low temp)");
1047 }
1048 } else {
1049 // Variable fan speed patterns - decode by temperature code
1050 if ((temp_code & 0x0F) == 0x0C) {
1052 ESP_LOGI(TAG, "Mode: HEAT");
1053 } else if (message1[5] == 0x1B) {
1055 ESP_LOGI(TAG, "Mode: FAN_ONLY");
1056 } else {
1058 ESP_LOGI(TAG, "Mode: COOL");
1059 }
1060 }
1061
1062 // Decode fan speed from rc_code_1
1063 uint16_t fan_code = (message1[2] << 8) | message1[3];
1064 this->fan_mode = decode_ras_2819t_fan_mode(fan_code);
1065
1066 // Decode temperature
1068 this->target_temperature = decode_ras_2819t_temperature(temp_code);
1069 }
1070
1071 this->publish_state();
1072 return true;
1073 } else {
1074 ESP_LOGD(TAG, "Unknown single-packet RAS-2819T command: 0x%" PRIX64, toshiba_data.rc_code_1);
1075 return false;
1076 }
1077}
1078
1080 // Try modern ToshibaAcProtocol decoder first (handles RAS-2819T and potentially others)
1081 remote_base::ToshibaAcProtocol toshiba_protocol;
1082 auto decode_result = toshiba_protocol.decode(data);
1083
1084 if (decode_result.has_value()) {
1085 auto toshiba_data = decode_result.value();
1086 // Validate and process RAS-2819T commands
1087 if (is_valid_ras_2819t_command(toshiba_data.rc_code_1, toshiba_data.rc_code_2)) {
1088 return this->process_ras_2819t_command_(toshiba_data);
1089 }
1090 }
1091
1092 // Fall back to generic processing for older protocols
1093 uint8_t message[18] = {0};
1094 uint8_t message_length = TOSHIBA_HEADER_LENGTH, temperature_code = 0;
1095
1096 // Validate header
1098 return false;
1099 }
1100 // Read incoming bits into buffer
1101 if (!this->decode_(&data, message, message_length)) {
1102 return false;
1103 }
1104 // Determine incoming message protocol version and/or length
1105 if (this->is_valid_rac_pt1411hwru_header_(message)) {
1106 // We already received four bytes
1107 message_length = RAC_PT1411HWRU_MESSAGE_LENGTH - 4;
1108 } else if ((message[0] ^ message[1] ^ message[2]) != message[3]) {
1109 // Return false if first checksum was not valid
1110 return false;
1111 } else {
1112 // First checksum was valid so continue receiving the remaining bits
1113 message_length = message[2] + 2;
1114 }
1115 // Decode the remaining bytes
1116 if (!this->decode_(&data, &message[4], message_length)) {
1117 return false;
1118 }
1119 // If this is a RAC-PT1411HWRU message, we expect the first packet a second time and also possibly a third packet
1120 if (this->is_valid_rac_pt1411hwru_header_(message)) {
1121 // There is always a space between packets
1123 return false;
1124 }
1125 // Validate header 2
1127 return false;
1128 }
1129 if (!this->decode_(&data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
1130 return false;
1131 }
1132 // If this is a RAC-PT1411HWRU message, there may also be a third packet.
1133 // We do not fail the receive if we don't get this; it isn't always present
1135 // Validate header 3
1137 if (this->decode_(&data, &message[12], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
1138 if (!this->is_valid_rac_pt1411hwru_message_(&message[12])) {
1139 // If a third packet was received but the checksum is not valid, fail
1140 return false;
1141 }
1142 }
1143 }
1144 if (!this->compare_rac_pt1411hwru_packets_(&message[0], &message[6])) {
1145 // If the first two packets don't match each other, fail
1146 return false;
1147 }
1148 if (!this->is_valid_rac_pt1411hwru_message_(&message[0])) {
1149 // If the first packet isn't valid, fail
1150 return false;
1151 }
1152 }
1153
1154 // Header has been verified, now determine protocol version and set the climate component properties
1155 switch (this->is_valid_rac_pt1411hwru_header_(message)) {
1156 // Power, temperature, mode, fan speed
1158 // Get the mode
1159 switch (message[4] & 0x0F) {
1162 break;
1163
1164 // case RAC_PT1411HWRU_MODE_OFF:
1166 if (((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) && (message[2] == RAC_PT1411HWRU_FAN_OFF)) {
1168 } else {
1170 }
1171 break;
1172
1173 // case RAC_PT1411HWRU_MODE_DRY:
1175 if ((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) {
1177 } else {
1179 }
1180 break;
1181
1184 break;
1185
1186 default:
1188 break;
1189 }
1190 // Get the fan speed/mode
1191 switch (message[2]) {
1192 case RAC_PT1411HWRU_FAN_LOW.code1:
1193 this->fan_mode = climate::CLIMATE_FAN_LOW;
1194 break;
1195
1196 case RAC_PT1411HWRU_FAN_MED.code1:
1197 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
1198 break;
1199
1200 case RAC_PT1411HWRU_FAN_HIGH.code1:
1201 this->fan_mode = climate::CLIMATE_FAN_HIGH;
1202 break;
1203
1204 case RAC_PT1411HWRU_FAN_AUTO.code1:
1205 default:
1206 this->fan_mode = climate::CLIMATE_FAN_AUTO;
1207 break;
1208 }
1209 // Get the target temperature
1210 if (this->is_valid_rac_pt1411hwru_message_(&message[12])) {
1211 temperature_code =
1213 if (message[15] & RAC_PT1411HWRU_FLAG_FAH) {
1214 for (size_t i = 0; i < RAC_PT1411HWRU_TEMPERATURE_F.size(); i++) {
1215 if (RAC_PT1411HWRU_TEMPERATURE_F[i] == temperature_code) {
1216 this->target_temperature = static_cast<float>((i + TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN - 32) * 5) / 9;
1217 }
1218 }
1219 } else {
1220 for (size_t i = 0; i < RAC_PT1411HWRU_TEMPERATURE_C.size(); i++) {
1221 if (RAC_PT1411HWRU_TEMPERATURE_C[i] == temperature_code) {
1223 }
1224 }
1225 }
1226 }
1227 break;
1228 // "Comfort Sense" temperature packet
1230 // "Comfort Sense" feature notes
1231 // IR Code: 0xBA45 xxXX yyYY
1232 // xx: Temperature in °C
1233 // Bit 6: feature state (on/off)
1234 // Bit 7: message contains temperature data for feature (bit 6 must also be set)
1235 // XX: Bitwise complement of xx
1236 // yy: Mode: Auto: 7A
1237 // Cool: 72
1238 // Heat: 7E
1239 // YY: Bitwise complement of yy
1241 // Setting current_temperature this way allows the unit's remote to provide the temperature to HA
1243 }
1244 break;
1245 // Swing mode
1249 } else {
1251 }
1252 break;
1253 // Generic (old) Toshiba packet
1254 default:
1255 uint8_t checksum = 0;
1256 // Add back the length of the header (we pruned it above)
1257 message_length += TOSHIBA_HEADER_LENGTH;
1258 // Validate the second checksum before trusting any more of the message
1259 for (uint8_t i = TOSHIBA_HEADER_LENGTH; i < message_length - 1; i++) {
1260 checksum ^= message[i];
1261 }
1262 // Did our computed checksum and the provided checksum match?
1263 if (checksum != message[message_length - 1]) {
1264 return false;
1265 }
1266 // Check if this is a short swing/fix message
1268 // Not supported yet
1269 return false;
1270 }
1271
1272 // Get the mode
1273 switch (message[6] & 0x0F) {
1274 case TOSHIBA_MODE_OFF:
1276 break;
1277
1278 case TOSHIBA_MODE_COOL:
1280 break;
1281
1282 case TOSHIBA_MODE_DRY:
1284 break;
1285
1288 break;
1289
1290 case TOSHIBA_MODE_HEAT:
1292 break;
1293
1294 case TOSHIBA_MODE_AUTO:
1295 default:
1297 }
1298
1299 // Get the fan mode
1300 switch (message[6] & 0xF0) {
1302 this->fan_mode = climate::CLIMATE_FAN_QUIET;
1303 break;
1304
1306 this->fan_mode = climate::CLIMATE_FAN_LOW;
1307 break;
1308
1310 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
1311 break;
1312
1314 this->fan_mode = climate::CLIMATE_FAN_HIGH;
1315 break;
1316
1318 default:
1319 this->fan_mode = climate::CLIMATE_FAN_AUTO;
1320 break;
1321 }
1322
1323 // Get the target temperature
1324 this->target_temperature = (message[5] >> 4) + TOSHIBA_GENERIC_TEMP_C_MIN;
1325 }
1326
1327 this->publish_state();
1328 return true;
1329}
1330
1331void ToshibaClimate::encode_(remote_base::RemoteTransmitData *data, const uint8_t *message, const uint8_t nbytes,
1332 const uint8_t repeat) {
1334
1335 for (uint8_t copy = 0; copy <= repeat; copy++) {
1337
1338 for (uint8_t byte = 0; byte < nbytes; byte++) {
1339 for (uint8_t bit = 0; bit < 8; bit++) {
1340 data->mark(TOSHIBA_BIT_MARK);
1341 if (message[byte] & (1 << (7 - bit))) {
1342 data->space(TOSHIBA_ONE_SPACE);
1343 } else {
1345 }
1346 }
1347 }
1349 }
1350}
1351
1352bool ToshibaClimate::decode_(remote_base::RemoteReceiveData *data, uint8_t *message, const uint8_t nbytes) {
1353 for (uint8_t byte = 0; byte < nbytes; byte++) {
1354 for (uint8_t bit = 0; bit < 8; bit++) {
1355 if (data->expect_item(TOSHIBA_BIT_MARK, TOSHIBA_ONE_SPACE)) {
1356 message[byte] |= 1 << (7 - bit);
1357 } else if (data->expect_item(TOSHIBA_BIT_MARK, TOSHIBA_ZERO_SPACE)) {
1358 message[byte] &= static_cast<uint8_t>(~(1 << (7 - bit)));
1359 } else {
1360 return false;
1361 }
1362 }
1363 }
1364 return true;
1365}
1366
1367} // namespace toshiba
1368} // namespace esphome
uint8_t checksum
Definition bl0906.h:3
constexpr bool empty() const
Check if the set is empty.
ClimateMode mode
The active mode of the climate device.
Definition climate.h:256
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:250
float target_temperature
The target temperature of the climate device.
Definition climate.h:237
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:262
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:230
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:426
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:350
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:66
bool expect_item(uint32_t mark, uint32_t space)
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:30
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:25
optional< ToshibaAcData > decode(RemoteReceiveData src) override
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition sensor.cpp:90
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:116
bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2)
Definition toshiba.cpp:959
bool is_valid_rac_pt1411hwru_message_(const uint8_t *message)
Definition toshiba.cpp:967
uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message)
Definition toshiba.cpp:945
bool process_ras_2819t_command_(const remote_base::ToshibaAcData &toshiba_data)
Definition toshiba.cpp:996
void transmit_rac_pt1411hwru_temp_(bool cs_state=true, bool cs_send_update=true)
Definition toshiba.cpp:686
bool on_receive(remote_base::RemoteReceiveData data) override
Definition toshiba.cpp:1079
ClimateFanMode fan_mode
Definition climate.h:3
const char * message
Definition component.cpp:38
bool state
Definition fan.h:0
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
const uint8_t RAS_2819T_FAN2_MEDIUM
Definition toshiba.cpp:117
const uint8_t TOSHIBA_HEADER_LENGTH
Definition toshiba.cpp:24
const uint8_t RAC_PT1411HWRU_MODE_HEAT
Definition toshiba.cpp:86
const uint16_t RAS_2819T_VALID_HEADER1
Definition toshiba.cpp:145
const uint16_t TOSHIBA_HEADER_MARK
Definition toshiba.cpp:16
const uint8_t TOSHIBA_MODE_HEAT
Definition toshiba.cpp:34
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_AUTO
Definition toshiba.cpp:127
const uint8_t RAC_PT1411HWRU_MODE_FAN
Definition toshiba.cpp:85
const uint8_t RAC_PT1411HWRU_CS_ENABLED
Definition toshiba.cpp:63
const uint16_t TOSHIBA_CARRIER_FREQUENCY
Definition toshiba.cpp:23
const uint8_t TOSHIBA_FAN_SPEED_2
Definition toshiba.cpp:41
@ MODEL_RAC_PT1411HWRU_C
Definition toshiba.h:12
@ MODEL_RAC_PT1411HWRU_F
Definition toshiba.h:13
const uint8_t RAC_PT1411HWRU_MODE_AUTO
Definition toshiba.cpp:82
const uint16_t RAS_2819T_FAN_AUTO
Definition toshiba.cpp:107
const RacPt1411hwruFanSpeed RAC_PT1411HWRU_NO_FAN
Definition toshiba.cpp:80
const uint8_t RAC_PT1411HWRU_MODE_COOL
Definition toshiba.cpp:83
const uint8_t RAS_2819T_DRY_BYTE3
Definition toshiba.cpp:149
const uint64_t RAS_2819T_POWER_OFF_COMMAND
Definition toshiba.cpp:137
const uint8_t RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY
Definition toshiba.cpp:89
const float TOSHIBA_RAS_2819T_TEMP_C_MAX
Definition toshiba.h:25
const uint8_t TOSHIBA_COMMAND_MOTION
Definition toshiba.cpp:29
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_LOW
Definition toshiba.cpp:129
const uint8_t RAS_2819T_FAN2_QUIET
Definition toshiba.cpp:115
const uint8_t RAS_2819T_FAN2_AUTO
Definition toshiba.cpp:114
const uint8_t RAC_PT1411HWRU_FLAG_FAH
Definition toshiba.cpp:53
const uint8_t RAS_2819T_HEAT_SUFFIX
Definition toshiba.cpp:164
const uint8_t RAS_2819T_AUTO_DRY_SUFFIX
Definition toshiba.cpp:163
const uint64_t RAS_2819T_SWING_TOGGLE
Definition toshiba.cpp:134
const uint8_t RAC_PT1411HWRU_CS_FOOTER_COOL
Definition toshiba.cpp:67
const uint8_t RAC_PT1411HWRU_CS_DATA
Definition toshiba.cpp:64
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_MEDIUM
Definition toshiba.cpp:130
const uint8_t TOSHIBA_MODE_DRY
Definition toshiba.cpp:33
const uint8_t RAC_PT1411HWRU_FAN_OFF
Definition toshiba.cpp:74
const uint8_t TOSHIBA_FAN_SPEED_QUIET
Definition toshiba.cpp:39
const uint16_t TOSHIBA_BIT_MARK
Definition toshiba.cpp:20
const uint8_t RAC_PT1411HWRU_FLAG_NEG
Definition toshiba.cpp:55
const uint8_t RAS_2819T_VALID_HEADER2
Definition toshiba.cpp:146
const uint8_t RAS_2819T_HEADER2
Definition toshiba.cpp:103
const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN
Definition toshiba.h:22
const uint8_t TOSHIBA_POWER_HIGH
Definition toshiba.cpp:46
const uint8_t RAS_2819T_FAN2_LOW
Definition toshiba.cpp:116
const uint8_t TOSHIBA_MODE_FAN_ONLY
Definition toshiba.cpp:35
const uint8_t TOSHIBA_POWER_ECO
Definition toshiba.cpp:47
const float TOSHIBA_GENERIC_TEMP_C_MAX
Definition toshiba.h:19
const uint8_t TOSHIBA_MODE_COOL
Definition toshiba.cpp:32
const float TOSHIBA_GENERIC_TEMP_C_MIN
Definition toshiba.h:18
const uint16_t TOSHIBA_ZERO_SPACE
Definition toshiba.cpp:21
const uint8_t TOSHIBA_FAN_SPEED_3
Definition toshiba.cpp:42
constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_LOW
Definition toshiba.cpp:76
const uint16_t TOSHIBA_GAP_SPACE
Definition toshiba.cpp:18
const uint8_t RAC_PT1411HWRU_MESSAGE_HEADER1
Definition toshiba.cpp:60
const uint8_t RAS_2819T_DRY_BYTE2
Definition toshiba.cpp:148
const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX
Definition toshiba.h:21
const uint8_t RAC_PT1411HWRU_CS_HEADER
Definition toshiba.cpp:65
const uint8_t TOSHIBA_COMMAND_POWER
Definition toshiba.cpp:28
const uint16_t RAS_2819T_FAN_MEDIUM
Definition toshiba.cpp:110
constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_AUTO
Definition toshiba.cpp:75
const std::vector< uint8_t > RAC_PT1411HWRU_TEMPERATURE_F
Definition toshiba.cpp:97
const uint8_t TOSHIBA_COMMAND_TIMER
Definition toshiba.cpp:27
const uint8_t TOSHIBA_FAN_SPEED_4
Definition toshiba.cpp:43
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_QUIET
Definition toshiba.cpp:128
const uint8_t TOSHIBA_COMMAND_DEFAULT
Definition toshiba.cpp:26
const uint8_t TOSHIBA_FAN_SPEED_1
Definition toshiba.cpp:40
const std::vector< uint8_t > RAC_PT1411HWRU_SWING_VERTICAL
Definition toshiba.cpp:71
const uint8_t RAC_PT1411HWRU_CS_FOOTER_AUTO
Definition toshiba.cpp:66
const uint16_t RAS_2819T_HEADER1
Definition toshiba.cpp:102
const uint8_t TOSHIBA_MOTION_SWING
Definition toshiba.cpp:49
const uint8_t TOSHIBA_MODE_AUTO
Definition toshiba.cpp:31
const uint8_t RAS_2819T_AUTO_TEMP_OFFSET
Definition toshiba.cpp:154
const uint8_t RAC_PT1411HWRU_MODE_DRY
Definition toshiba.cpp:84
const uint8_t RAS_2819T_FAN_ONLY_TEMP
Definition toshiba.cpp:156
const uint8_t RAS_2819T_AUTO_BYTE3
Definition toshiba.cpp:153
const uint16_t TOSHIBA_ONE_SPACE
Definition toshiba.cpp:22
constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_HIGH
Definition toshiba.cpp:78
const uint8_t TOSHIBA_FAN_SPEED_5
Definition toshiba.cpp:44
const uint8_t RAC_PT1411HWRU_MESSAGE_HEADER0
Definition toshiba.cpp:59
const float TOSHIBA_RAS_2819T_TEMP_C_MIN
Definition toshiba.h:24
constexpr RacPt1411hwruFanSpeed RAC_PT1411HWRU_FAN_MED
Definition toshiba.cpp:77
const uint8_t RAC_PT1411HWRU_FLAG_FRAC
Definition toshiba.cpp:54
const uint8_t RAS_2819T_AUTO_BYTE2
Definition toshiba.cpp:152
const uint16_t TOSHIBA_HEADER_SPACE
Definition toshiba.cpp:17
const uint8_t RAS_2819T_HEAT_TEMP_OFFSET
Definition toshiba.cpp:159
const uint8_t TOSHIBA_MODE_OFF
Definition toshiba.cpp:36
const Ras2819tPacketSuffix RAS_2819T_SUFFIX_HIGH
Definition toshiba.cpp:131
const uint8_t RAC_PT1411HWRU_CS_FOOTER_HEAT
Definition toshiba.cpp:68
const uint8_t RAS_2819T_FAN2_HIGH
Definition toshiba.cpp:118
const uint16_t TOSHIBA_PACKET_SPACE
Definition toshiba.cpp:19
const uint8_t RAS_2819T_FAN_ONLY_TEMP_INV
Definition toshiba.cpp:157
const uint8_t RAC_PT1411HWRU_MODE_OFF
Definition toshiba.cpp:87
const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MIN
Definition toshiba.h:20
const uint8_t RAC_PT1411HWRU_MESSAGE_LENGTH
Definition toshiba.cpp:61
const uint8_t RAC_PT1411HWRU_FLAG_MASK
Definition toshiba.cpp:57
const uint8_t RAS_2819T_AUTO_DRY_FAN_BYTE
Definition toshiba.cpp:162
const uint16_t RAS_2819T_FAN_LOW
Definition toshiba.cpp:109
const std::array< uint64_t, 2 > RAS_2819T_VALID_SINGLE_COMMANDS
Definition toshiba.cpp:140
const uint8_t TOSHIBA_MOTION_FIX
Definition toshiba.cpp:50
const uint16_t RAS_2819T_FAN_QUIET
Definition toshiba.cpp:108
const std::vector< uint8_t > RAC_PT1411HWRU_TEMPERATURE_C
Definition toshiba.cpp:94
const uint16_t RAS_2819T_FAN_HIGH
Definition toshiba.cpp:111
const uint8_t RAC_PT1411HWRU_SWING_HEADER
Definition toshiba.cpp:70
const uint8_t RAS_2819T_MESSAGE_LENGTH
Definition toshiba.cpp:104
const uint8_t TOSHIBA_FAN_SPEED_AUTO
Definition toshiba.cpp:38
const uint8_t RAS_2819T_DRY_TEMP_OFFSET
Definition toshiba.cpp:150
const std::vector< uint8_t > RAC_PT1411HWRU_SWING_OFF
Definition toshiba.cpp:72
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t temperature
Definition sun_gtil2.cpp:12