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