ESPHome 2026.5.1
Loading...
Searching...
No Matches
toshiba.cpp
Go to the documentation of this file.
1#include "toshiba.h"
4
5#include <vector>
6
7namespace esphome::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 || static_cast<size_t>(temp_index) >= 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#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
431 // Log final state for debugging HA errors
432 const char *fan_mode_str = "NONE";
433 char fan_mode_buf[4]; // max 3 digits for fan mode enum + null
434 if (this->fan_mode.has_value()) {
435 buf_append_printf(fan_mode_buf, sizeof(fan_mode_buf), 0, "%d", static_cast<int>(this->fan_mode.value()));
436 fan_mode_str = fan_mode_buf;
437 }
438 ESP_LOGV(TAG, "Setup complete - Mode: %d, Fan: %s, Swing: %d, Temp: %.1f", static_cast<int>(this->mode), fan_mode_str,
439 static_cast<int>(this->swing_mode), this->target_temperature);
440#endif
441}
442
444 if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F) {
446 } else if (this->model_ == MODEL_RAS_2819T) {
447 this->transmit_ras_2819t_();
448 } else {
449 this->transmit_generic_();
450 }
451}
452
454 uint8_t message[16] = {0};
455 uint8_t message_length = 9;
456
457 // Header
458 message[0] = 0xf2;
459 message[1] = 0x0d;
460
461 // Message length
462 message[2] = message_length - 6;
463
464 // First checksum
465 message[3] = message[0] ^ message[1] ^ message[2];
466
467 // Command
469
470 // Temperature
471 uint8_t temperature = static_cast<uint8_t>(
473 message[5] = (temperature - static_cast<uint8_t>(TOSHIBA_GENERIC_TEMP_C_MIN)) << 4;
474
475 // Mode and fan
476 uint8_t mode;
477 switch (this->mode) {
480 break;
481
484 break;
485
488 break;
489
492 break;
493
496 break;
497
499 default:
501 }
502
503 uint8_t fan;
504 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
507 break;
508
511 break;
512
515 break;
516
519 break;
520
522 default:
524 break;
525 }
526 message[6] = fan | mode;
527
528 // Zero
529 message[7] = 0x00;
530
531 // If timers bit in the command is set, two extra bytes are added here
532
533 // If power bit is set in the command, one extra byte is added here
534
535 // The last byte is the xor of all bytes from [4]
536 for (uint8_t i = 4; i < 8; i++) {
537 message[8] ^= message[i];
538 }
539
540 // Transmit
541 auto transmit = this->transmitter_->transmit();
542 auto *data = transmit.get_data();
543
544 this->encode_(data, message, message_length, 1);
545
546 transmit.perform();
547}
548
550 uint8_t code = 0, index = 0, message[RAC_PT1411HWRU_MESSAGE_LENGTH * 2] = {0};
551 float temperature =
554 auto transmit = this->transmitter_->transmit();
555 auto *data = transmit.get_data();
556
557 // Byte 0: Header upper (0xB2)
559 // Byte 1: Header lower (0x4D)
560 message[1] = ~message[0];
561 // Byte 2u: Fan speed
562 // Byte 2l: 1111 (on) or 1011 (off)
563 if (this->mode == climate::CLIMATE_MODE_OFF) {
565 } else if ((this->mode == climate::CLIMATE_MODE_HEAT_COOL) || (this->mode == climate::CLIMATE_MODE_DRY)) {
568 } else {
569 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
573 break;
574
578 break;
579
583 break;
584
586 default:
589 }
590 }
591 // Byte 3u: ~Fan speed
592 // Byte 3l: 0000 (on) or 0100 (off)
593 message[3] = ~message[2];
594 // Byte 4u: Temp
595 if (this->model_ == MODEL_RAC_PT1411HWRU_F) {
596 temperature = (temperature * 1.8) + 32;
598 }
599
600 index = static_cast<uint8_t>(roundf(temp_adjd));
601
602 if (this->model_ == MODEL_RAC_PT1411HWRU_F) {
603 code = RAC_PT1411HWRU_TEMPERATURE_F[index];
605 } else {
606 code = RAC_PT1411HWRU_TEMPERATURE_C[index];
607 }
610 }
611
612 if (code & RAC_PT1411HWRU_FLAG_FRAC) {
614 }
615 if (code & RAC_PT1411HWRU_FLAG_NEG) {
617 }
618 message[4] = (code & RAC_PT1411HWRU_FLAG_MASK) << 4;
619 // Byte 4l: Mode
620 switch (this->mode) {
622 // zerooooo
623 break;
624
627 break;
628
631 break;
632
635 break;
636
639 break;
640
642 default:
644 }
645
646 // Byte 5u: ~Temp
647 // Byte 5l: ~Mode
648 message[5] = ~message[4];
649
650 if (this->mode != climate::CLIMATE_MODE_OFF) {
651 // Byte 6: Header (0xD5)
653 // Byte 7: Fan speed part 2 (done above)
654 // Byte 8: 0x20 for °F frac, else 0 (done above)
655 // Byte 9: 0x10=NEG, 0x01=°F (done above)
656 // Byte 10: 0
657 // Byte 11: Checksum (bytes 6 through 10)
658 for (index = 6; index <= 10; index++) {
659 message[11] += message[index];
660 }
661 }
662
663 // load first block of IR code and repeat it once
664 this->encode_(data, &message[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
665 // load second block of IR code, if present
666 if (message[6] != 0) {
667 this->encode_(data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH, 0);
668 }
669
670 transmit.perform();
671
672 // Swing Mode
673 data->reset();
674 data->space(TOSHIBA_PACKET_SPACE);
675 switch (this->swing_mode) {
678 break;
679
681 default:
682 this->encode_(data, &RAC_PT1411HWRU_SWING_OFF[0], RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
683 }
684
685 data->space(TOSHIBA_PACKET_SPACE);
686 transmit.perform();
687
688 if (this->sensor_) {
689 this->transmit_rac_pt1411hwru_temp_(true, false);
690 }
691}
692
693void ToshibaClimate::transmit_rac_pt1411hwru_temp_(const bool cs_state, const bool cs_send_update) {
694 if ((this->mode == climate::CLIMATE_MODE_HEAT) || (this->mode == climate::CLIMATE_MODE_COOL) ||
697 float temperature = clamp<float>(this->current_temperature, 0.0, TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX + 1);
698 auto transmit = this->transmitter_->transmit();
699 auto *data = transmit.get_data();
700 // "Comfort Sense" feature notes
701 // IR Code: 0xBA45 xxXX yyYY
702 // xx: Temperature in °C
703 // Bit 6: feature state (on/off)
704 // Bit 7: message contains temperature data for feature (bit 6 must also be set)
705 // XX: Bitwise complement of xx
706 // yy: Mode: Auto=0x7A, Cool=0x72, Heat=0x7E
707 // YY: Bitwise complement of yy
708 //
709 // Byte 0: Header upper (0xBA)
711 // Byte 1: Header lower (0x45)
712 message[1] = ~message[0];
713 // Byte 2: Temperature in °C
714 message[2] = static_cast<uint8_t>(roundf(temperature));
715 if (cs_send_update) {
717 } else if (cs_state) {
719 }
720 // Byte 3: Bitwise complement of byte 2
721 message[3] = ~message[2];
722 // Byte 4: Footer upper
723 switch (this->mode) {
726 break;
727
730 break;
731
734
735 default:
736 break;
737 }
738 // Byte 5: Footer lower/bitwise complement of byte 4
739 message[5] = ~message[4];
740
741 // load IR code and repeat it once
742 this->encode_(data, message, RAC_PT1411HWRU_MESSAGE_LENGTH, 1);
743
744 transmit.perform();
745 }
746}
747
749 // Handle swing mode transmission for RAS-2819T
750 // Note: RAS-2819T uses a toggle command, so we need to track state changes
751
752 // Check if ONLY swing mode changed (and no other climate parameters)
753 bool swing_changed = (this->swing_mode != this->last_swing_mode_);
754 bool mode_changed = (this->mode != this->last_mode_);
755 bool fan_changed = (this->fan_mode != this->last_fan_mode_);
756 bool temp_changed = (abs(this->target_temperature - this->last_target_temperature_) > 0.1f);
757
758 bool only_swing_changed = swing_changed && !mode_changed && !fan_changed && !temp_changed;
759
760 if (only_swing_changed) {
761 // Send ONLY swing toggle command (like the physical remote does)
762 auto swing_transmit = this->transmitter_->transmit();
763 auto *swing_data = swing_transmit.get_data();
764
765 // Convert toggle command to bytes for transmission
766 uint8_t swing_message[RAS_2819T_MESSAGE_LENGTH];
767 swing_message[0] = (RAS_2819T_SWING_TOGGLE >> 40) & 0xFF;
768 swing_message[1] = (RAS_2819T_SWING_TOGGLE >> 32) & 0xFF;
769 swing_message[2] = (RAS_2819T_SWING_TOGGLE >> 24) & 0xFF;
770 swing_message[3] = (RAS_2819T_SWING_TOGGLE >> 16) & 0xFF;
771 swing_message[4] = (RAS_2819T_SWING_TOGGLE >> 8) & 0xFF;
772 swing_message[5] = RAS_2819T_SWING_TOGGLE & 0xFF;
773
774 // Use single packet transmission WITH repeat (like regular commands)
775 this->encode_(swing_data, swing_message, RAS_2819T_MESSAGE_LENGTH, 1);
776 swing_transmit.perform();
777
778 // Update all state tracking
779 this->last_swing_mode_ = this->swing_mode;
780 this->last_mode_ = this->mode;
781 this->last_fan_mode_ = this->fan_mode;
782 this->last_target_temperature_ = this->target_temperature;
783
784 // Immediately publish the state change to Home Assistant
785 this->publish_state();
786
787 return; // Exit early - don't send climate command
788 }
789
790 // If we get here, send the regular climate command (temperature/mode/fan)
791 uint8_t message1[RAS_2819T_MESSAGE_LENGTH] = {0};
792 uint8_t message2[RAS_2819T_MESSAGE_LENGTH] = {0};
793 float temperature =
795
796 // Build first packet (RAS_2819T_HEADER1 + 4 bytes)
797 message1[0] = (RAS_2819T_HEADER1 >> 8) & 0xFF;
798 message1[1] = RAS_2819T_HEADER1 & 0xFF;
799
800 // Handle OFF mode
801 if (this->mode == climate::CLIMATE_MODE_OFF) {
802 // Extract bytes from power off command constant
803 message1[2] = (RAS_2819T_POWER_OFF_COMMAND >> 24) & 0xFF;
804 message1[3] = (RAS_2819T_POWER_OFF_COMMAND >> 16) & 0xFF;
805 message1[4] = (RAS_2819T_POWER_OFF_COMMAND >> 8) & 0xFF;
806 message1[5] = RAS_2819T_POWER_OFF_COMMAND & 0xFF;
807 // No second packet for OFF
808 } else {
809 // Get temperature and fan encoding
810 uint8_t temp_code = get_ras_2819t_temp_code(temperature);
811
812 // Get fan speed encoding for rc_code_1
813 climate::ClimateFanMode effective_fan_mode = this->fan_mode.value_or(climate::CLIMATE_FAN_ON);
814
815 // Dry mode only supports AUTO fan speed
816 if (this->mode == climate::CLIMATE_MODE_DRY) {
817 effective_fan_mode = climate::CLIMATE_FAN_AUTO;
818 if (this->fan_mode.value_or(climate::CLIMATE_FAN_ON) != climate::CLIMATE_FAN_AUTO) {
819 ESP_LOGW(TAG, "Dry mode only supports AUTO fan speed, forcing AUTO");
820 }
821 }
822
823 uint16_t fan_code = get_ras_2819t_fan_code(effective_fan_mode);
824
825 // Mode and temperature encoding
826 switch (this->mode) {
828 // All cooling temperatures support fan speed control
829 message1[2] = (fan_code >> 8) & 0xFF;
830 message1[3] = fan_code & 0xFF;
831 message1[4] = temp_code;
832 message1[5] = ~temp_code;
833 break;
834
836 // Heating supports fan speed control
837 message1[2] = (fan_code >> 8) & 0xFF;
838 message1[3] = fan_code & 0xFF;
839 // Heat mode adds offset to temperature code
840 message1[4] = temp_code | RAS_2819T_HEAT_TEMP_OFFSET;
841 message1[5] = ~(temp_code | RAS_2819T_HEAT_TEMP_OFFSET);
842 break;
843
845 // Auto mode uses fixed encoding
846 message1[2] = RAS_2819T_AUTO_BYTE2;
847 message1[3] = RAS_2819T_AUTO_BYTE3;
848 message1[4] = temp_code | RAS_2819T_AUTO_TEMP_OFFSET;
849 message1[5] = ~(temp_code | RAS_2819T_AUTO_TEMP_OFFSET);
850 break;
851
853 // Dry mode uses fixed encoding and forces AUTO fan
854 message1[2] = RAS_2819T_DRY_BYTE2;
855 message1[3] = RAS_2819T_DRY_BYTE3;
856 message1[4] = temp_code | RAS_2819T_DRY_TEMP_OFFSET;
857 message1[5] = ~message1[4];
858 break;
859
861 // Fan only mode supports fan speed control
862 message1[2] = (fan_code >> 8) & 0xFF;
863 message1[3] = fan_code & 0xFF;
864 message1[4] = RAS_2819T_FAN_ONLY_TEMP;
865 message1[5] = RAS_2819T_FAN_ONLY_TEMP_INV;
866 break;
867
868 default:
869 // Default case supports fan speed control
870 message1[2] = (fan_code >> 8) & 0xFF;
871 message1[3] = fan_code & 0xFF;
872 message1[4] = temp_code;
873 message1[5] = ~temp_code;
874 break;
875 }
876
877 // Build second packet (RAS_2819T_HEADER2 + 4 bytes)
878 message2[0] = RAS_2819T_HEADER2;
879
880 // Get fan speed encoding for rc_code_2
881 Ras2819tSecondPacketCodes second_packet_codes = get_ras_2819t_second_packet_codes(effective_fan_mode);
882
883 // Determine header byte 2 and fan encoding based on mode
884 switch (this->mode) {
886 message2[1] = second_packet_codes.fan_byte;
887 message2[2] = 0x00;
888 message2[3] = second_packet_codes.suffix.byte3;
889 message2[4] = second_packet_codes.suffix.byte4;
890 message2[5] = second_packet_codes.suffix.byte5;
891 break;
892
894 message2[1] = second_packet_codes.fan_byte;
895 message2[2] = 0x00;
896 message2[3] = second_packet_codes.suffix.byte3;
897 message2[4] = 0x00;
898 message2[5] = RAS_2819T_HEAT_SUFFIX;
899 break;
900
903 // Auto/Dry modes use fixed values regardless of fan setting
904 message2[1] = RAS_2819T_AUTO_DRY_FAN_BYTE;
905 message2[2] = 0x00;
906 message2[3] = 0x00;
907 message2[4] = 0x00;
908 message2[5] = RAS_2819T_AUTO_DRY_SUFFIX;
909 break;
910
912 message2[1] = second_packet_codes.fan_byte;
913 message2[2] = 0x00;
914 message2[3] = second_packet_codes.suffix.byte3;
915 message2[4] = 0x00;
916 message2[5] = RAS_2819T_HEAT_SUFFIX;
917 break;
918
919 default:
920 message2[1] = second_packet_codes.fan_byte;
921 message2[2] = 0x00;
922 message2[3] = second_packet_codes.suffix.byte3;
923 message2[4] = second_packet_codes.suffix.byte4;
924 message2[5] = second_packet_codes.suffix.byte5;
925 break;
926 }
927 }
928
929 // Log final messages being transmitted
930
931 // Transmit using proper Toshiba protocol timing
932 auto transmit = this->transmitter_->transmit();
933 auto *data = transmit.get_data();
934
935 // Use existing Toshiba encode function for proper timing
936 this->encode_(data, message1, RAS_2819T_MESSAGE_LENGTH, 1);
937
938 if (this->mode != climate::CLIMATE_MODE_OFF) {
939 // Send second packet with gap
940 this->encode_(data, message2, RAS_2819T_MESSAGE_LENGTH, 0);
941 }
942
943 transmit.perform();
944
945 // Update all state tracking after successful transmission
946 this->last_swing_mode_ = this->swing_mode;
947 this->last_mode_ = this->mode;
948 this->last_fan_mode_ = this->fan_mode;
949 this->last_target_temperature_ = this->target_temperature;
950}
951
953 static constexpr uint8_t HEADERS[] = {RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER,
955
956 for (auto i : HEADERS) {
957 if ((message[0] == i) && (message[1] == static_cast<uint8_t>(~i)))
958 return i;
959 }
962
963 return 0;
964}
965
966bool ToshibaClimate::compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2) {
967 for (uint8_t i = 0; i < RAC_PT1411HWRU_MESSAGE_LENGTH; i++) {
968 if (message1[i] != message2[i])
969 return false;
970 }
971 return true;
972}
973
975 uint8_t checksum = 0;
976
977 switch (this->is_valid_rac_pt1411hwru_header_(message)) {
981 if (this->is_valid_rac_pt1411hwru_header_(message) && (message[2] == static_cast<uint8_t>(~message[3])) &&
982 (message[4] == static_cast<uint8_t>(~message[5]))) {
983 return true;
984 }
985 break;
986
988 for (uint8_t i = 0; i < RAC_PT1411HWRU_MESSAGE_LENGTH - 1; i++) {
989 checksum += message[i];
990 }
992 return true;
993 }
994 break;
995
996 default:
997 return false;
998 }
999
1000 return false;
1001}
1002
1004 // Check for power-off command (single packet)
1005 if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_POWER_OFF_COMMAND) {
1007 ESP_LOGI(TAG, "Mode: OFF");
1008 this->publish_state();
1009 return true;
1010 }
1011
1012 // Check for swing toggle command (single packet)
1013 if (toshiba_data.rc_code_2 == 0 && toshiba_data.rc_code_1 == RAS_2819T_SWING_TOGGLE) {
1014 // Toggle swing mode
1017 ESP_LOGI(TAG, "Swing: OFF");
1018 } else {
1020 ESP_LOGI(TAG, "Swing: VERTICAL");
1021 }
1022 this->publish_state();
1023 return true;
1024 }
1025
1026 // Handle regular two-packet commands (mode/temperature/fan changes)
1027 if (toshiba_data.rc_code_2 != 0) {
1028 // Convert to byte array for easier processing
1029 uint8_t message1[6], message2[6];
1030 for (uint8_t i = 0; i < 6; i++) {
1031 message1[i] = (toshiba_data.rc_code_1 >> (40 - i * 8)) & 0xFF;
1032 message2[i] = (toshiba_data.rc_code_2 >> (40 - i * 8)) & 0xFF;
1033 }
1034
1035 // Decode the protocol using message1 (rc_code_1)
1036 uint8_t temp_code = message1[4];
1037
1038 // Decode mode - check bytes 2-3 pattern and temperature code
1039 if ((message1[2] == 0x7B) && (message1[3] == 0x84)) {
1040 // OFF mode has specific pattern
1042 ESP_LOGI(TAG, "Mode: OFF");
1043 } else if ((message1[2] == 0x1F) && (message1[3] == 0xE0)) {
1044 // 0x1FE0 pattern is used for AUTO, DRY, and low-temp COOL
1045 if ((temp_code & 0x0F) == 0x08) {
1047 ESP_LOGI(TAG, "Mode: AUTO");
1048 } else if ((temp_code & 0x0F) == 0x04) {
1050 ESP_LOGI(TAG, "Mode: DRY");
1051 } else {
1053 ESP_LOGI(TAG, "Mode: COOL (low temp)");
1054 }
1055 } else {
1056 // Variable fan speed patterns - decode by temperature code
1057 if ((temp_code & 0x0F) == 0x0C) {
1059 ESP_LOGI(TAG, "Mode: HEAT");
1060 } else if (message1[5] == 0x1B) {
1062 ESP_LOGI(TAG, "Mode: FAN_ONLY");
1063 } else {
1065 ESP_LOGI(TAG, "Mode: COOL");
1066 }
1067 }
1068
1069 // Decode fan speed from rc_code_1
1070 uint16_t fan_code = (message1[2] << 8) | message1[3];
1071 this->fan_mode = decode_ras_2819t_fan_mode(fan_code);
1072
1073 // Decode temperature
1075 this->target_temperature = decode_ras_2819t_temperature(temp_code);
1076 }
1077
1078 this->publish_state();
1079 return true;
1080 } else {
1081 ESP_LOGD(TAG, "Unknown single-packet RAS-2819T command: 0x%" PRIX64, toshiba_data.rc_code_1);
1082 return false;
1083 }
1084}
1085
1087 // Try modern ToshibaAcProtocol decoder first (handles RAS-2819T and potentially others)
1088 remote_base::ToshibaAcProtocol toshiba_protocol;
1089 auto decode_result = toshiba_protocol.decode(data);
1090
1091 if (decode_result.has_value()) {
1092 auto toshiba_data = decode_result.value();
1093 // Validate and process RAS-2819T commands
1094 if (is_valid_ras_2819t_command(toshiba_data.rc_code_1, toshiba_data.rc_code_2)) {
1095 return this->process_ras_2819t_command_(toshiba_data);
1096 }
1097 }
1098
1099 // Fall back to generic processing for older protocols
1100 uint8_t message[18] = {0};
1101 uint8_t message_length = TOSHIBA_HEADER_LENGTH, temperature_code = 0;
1102
1103 // Validate header
1104 if (!data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE)) {
1105 return false;
1106 }
1107 // Read incoming bits into buffer
1108 if (!this->decode_(&data, message, message_length)) {
1109 return false;
1110 }
1111 // Determine incoming message protocol version and/or length
1112 if (this->is_valid_rac_pt1411hwru_header_(message)) {
1113 // We already received four bytes
1114 message_length = RAC_PT1411HWRU_MESSAGE_LENGTH - 4;
1115 } else if ((message[0] ^ message[1] ^ message[2]) != message[3]) {
1116 // Return false if first checksum was not valid
1117 return false;
1118 } else {
1119 // First checksum was valid so continue receiving the remaining bits
1120 message_length = message[2] + 2;
1121 }
1122 // Decode the remaining bytes
1123 if (!this->decode_(&data, &message[4], message_length)) {
1124 return false;
1125 }
1126 // If this is a RAC-PT1411HWRU message, we expect the first packet a second time and also possibly a third packet
1127 if (this->is_valid_rac_pt1411hwru_header_(message)) {
1128 // There is always a space between packets
1129 if (!data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) {
1130 return false;
1131 }
1132 // Validate header 2
1133 if (!data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE)) {
1134 return false;
1135 }
1136 if (!this->decode_(&data, &message[6], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
1137 return false;
1138 }
1139 // If this is a RAC-PT1411HWRU message, there may also be a third packet.
1140 // We do not fail the receive if we don't get this; it isn't always present
1141 if (data.expect_item(TOSHIBA_BIT_MARK, TOSHIBA_GAP_SPACE)) {
1142 // Validate header 3
1143 data.expect_item(TOSHIBA_HEADER_MARK, TOSHIBA_HEADER_SPACE);
1144 if (this->decode_(&data, &message[12], RAC_PT1411HWRU_MESSAGE_LENGTH)) {
1145 if (!this->is_valid_rac_pt1411hwru_message_(&message[12])) {
1146 // If a third packet was received but the checksum is not valid, fail
1147 return false;
1148 }
1149 }
1150 }
1151 if (!this->compare_rac_pt1411hwru_packets_(&message[0], &message[6])) {
1152 // If the first two packets don't match each other, fail
1153 return false;
1154 }
1155 if (!this->is_valid_rac_pt1411hwru_message_(&message[0])) {
1156 // If the first packet isn't valid, fail
1157 return false;
1158 }
1159 }
1160
1161 // Header has been verified, now determine protocol version and set the climate component properties
1162 switch (this->is_valid_rac_pt1411hwru_header_(message)) {
1163 // Power, temperature, mode, fan speed
1165 // Get the mode
1166 switch (message[4] & 0x0F) {
1169 break;
1170
1171 // case RAC_PT1411HWRU_MODE_OFF:
1173 if (((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) && (message[2] == RAC_PT1411HWRU_FAN_OFF)) {
1175 } else {
1177 }
1178 break;
1179
1180 // case RAC_PT1411HWRU_MODE_DRY:
1182 if ((message[4] >> 4) == RAC_PT1411HWRU_TEMPERATURE_FAN_ONLY) {
1184 } else {
1186 }
1187 break;
1188
1191 break;
1192
1193 default:
1195 break;
1196 }
1197 // Get the fan speed/mode
1198 switch (message[2]) {
1199 case RAC_PT1411HWRU_FAN_LOW.code1:
1200 this->fan_mode = climate::CLIMATE_FAN_LOW;
1201 break;
1202
1203 case RAC_PT1411HWRU_FAN_MED.code1:
1204 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
1205 break;
1206
1207 case RAC_PT1411HWRU_FAN_HIGH.code1:
1208 this->fan_mode = climate::CLIMATE_FAN_HIGH;
1209 break;
1210
1211 case RAC_PT1411HWRU_FAN_AUTO.code1:
1212 default:
1213 this->fan_mode = climate::CLIMATE_FAN_AUTO;
1214 break;
1215 }
1216 // Get the target temperature
1217 if (this->is_valid_rac_pt1411hwru_message_(&message[12])) {
1218 temperature_code =
1220 if (message[15] & RAC_PT1411HWRU_FLAG_FAH) {
1221 for (size_t i = 0; i < RAC_PT1411HWRU_TEMPERATURE_F.size(); i++) {
1222 if (RAC_PT1411HWRU_TEMPERATURE_F[i] == temperature_code) {
1223 this->target_temperature = static_cast<float>((i + TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN - 32) * 5) / 9;
1224 }
1225 }
1226 } else {
1227 for (size_t i = 0; i < RAC_PT1411HWRU_TEMPERATURE_C.size(); i++) {
1228 if (RAC_PT1411HWRU_TEMPERATURE_C[i] == temperature_code) {
1230 }
1231 }
1232 }
1233 }
1234 break;
1235 // "Comfort Sense" temperature packet
1237 // "Comfort Sense" feature notes
1238 // IR Code: 0xBA45 xxXX yyYY
1239 // xx: Temperature in °C
1240 // Bit 6: feature state (on/off)
1241 // Bit 7: message contains temperature data for feature (bit 6 must also be set)
1242 // XX: Bitwise complement of xx
1243 // yy: Mode: Auto: 7A
1244 // Cool: 72
1245 // Heat: 7E
1246 // YY: Bitwise complement of yy
1248 // Setting current_temperature this way allows the unit's remote to provide the temperature to HA
1250 }
1251 break;
1252 // Swing mode
1256 } else {
1258 }
1259 break;
1260 // Generic (old) Toshiba packet
1261 default:
1262 uint8_t checksum = 0;
1263 // Add back the length of the header (we pruned it above)
1264 message_length += TOSHIBA_HEADER_LENGTH;
1265 // Validate the second checksum before trusting any more of the message
1266 for (uint8_t i = TOSHIBA_HEADER_LENGTH; i < message_length - 1; i++) {
1267 checksum ^= message[i];
1268 }
1269 // Did our computed checksum and the provided checksum match?
1270 if (checksum != message[message_length - 1]) {
1271 return false;
1272 }
1273 // Check if this is a short swing/fix message
1275 // Not supported yet
1276 return false;
1277 }
1278
1279 // Get the mode
1280 switch (message[6] & 0x0F) {
1281 case TOSHIBA_MODE_OFF:
1283 break;
1284
1285 case TOSHIBA_MODE_COOL:
1287 break;
1288
1289 case TOSHIBA_MODE_DRY:
1291 break;
1292
1295 break;
1296
1297 case TOSHIBA_MODE_HEAT:
1299 break;
1300
1301 case TOSHIBA_MODE_AUTO:
1302 default:
1304 }
1305
1306 // Get the fan mode
1307 switch (message[6] & 0xF0) {
1309 this->fan_mode = climate::CLIMATE_FAN_QUIET;
1310 break;
1311
1313 this->fan_mode = climate::CLIMATE_FAN_LOW;
1314 break;
1315
1317 this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
1318 break;
1319
1321 this->fan_mode = climate::CLIMATE_FAN_HIGH;
1322 break;
1323
1325 default:
1326 this->fan_mode = climate::CLIMATE_FAN_AUTO;
1327 break;
1328 }
1329
1330 // Get the target temperature
1331 this->target_temperature = (message[5] >> 4) + TOSHIBA_GENERIC_TEMP_C_MIN;
1332 }
1333
1334 this->publish_state();
1335 return true;
1336}
1337
1338void ToshibaClimate::encode_(remote_base::RemoteTransmitData *data, const uint8_t *message, const uint8_t nbytes,
1339 const uint8_t repeat) {
1340 data->set_carrier_frequency(TOSHIBA_CARRIER_FREQUENCY);
1341
1342 for (uint8_t copy = 0; copy <= repeat; copy++) {
1344
1345 for (uint8_t byte = 0; byte < nbytes; byte++) {
1346 for (uint8_t bit = 0; bit < 8; bit++) {
1347 data->mark(TOSHIBA_BIT_MARK);
1348 if (message[byte] & (1 << (7 - bit))) {
1349 data->space(TOSHIBA_ONE_SPACE);
1350 } else {
1351 data->space(TOSHIBA_ZERO_SPACE);
1352 }
1353 }
1354 }
1356 }
1357}
1358
1359bool ToshibaClimate::decode_(remote_base::RemoteReceiveData *data, uint8_t *message, const uint8_t nbytes) {
1360 for (uint8_t byte = 0; byte < nbytes; byte++) {
1361 for (uint8_t bit = 0; bit < 8; bit++) {
1362 if (data->expect_item(TOSHIBA_BIT_MARK, TOSHIBA_ONE_SPACE)) {
1363 message[byte] |= 1 << (7 - bit);
1364 } else if (data->expect_item(TOSHIBA_BIT_MARK, TOSHIBA_ZERO_SPACE)) {
1365 message[byte] &= static_cast<uint8_t>(~(1 << (7 - bit)));
1366 } else {
1367 return false;
1368 }
1369 }
1370 }
1371 return true;
1372}
1373
1374} // namespace esphome::toshiba
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:293
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:287
float target_temperature
The target temperature of the climate device.
Definition climate.h:274
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:299
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:267
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:437
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:362
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:66
optional< ToshibaAcData > decode(RemoteReceiveData src) override
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition sensor.h:119
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:138
bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2)
Definition toshiba.cpp:966
bool is_valid_rac_pt1411hwru_message_(const uint8_t *message)
Definition toshiba.cpp:974
uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message)
Definition toshiba.cpp:952
bool process_ras_2819t_command_(const remote_base::ToshibaAcData &toshiba_data)
Definition toshiba.cpp:1003
void transmit_rac_pt1411hwru_temp_(bool cs_state=true, bool cs_send_update=true)
Definition toshiba.cpp:693
bool on_receive(remote_base::RemoteReceiveData data) override
Definition toshiba.cpp:1086
ClimateFanMode fan_mode
Definition climate.h:3
const char * message
Definition component.cpp:35
bool state
Definition fan.h:2
@ 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_ON
The fan mode is set to On.
@ 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 std::vector< uint8_t > & data
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:11
@ MODEL_RAC_PT1411HWRU_F
Definition toshiba.h:12
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:24
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:21
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:18
const uint8_t TOSHIBA_MODE_COOL
Definition toshiba.cpp:32
const float TOSHIBA_GENERIC_TEMP_C_MIN
Definition toshiba.h:17
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:20
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:23
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:19
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
uint16_t temperature
Definition sun_gtil2.cpp:12