ESPHome  2022.6.3
mitsubishi.cpp
Go to the documentation of this file.
1 #include "mitsubishi.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace mitsubishi {
6 
7 static const char *const TAG = "mitsubishi.climate";
8 
9 const uint32_t MITSUBISHI_OFF = 0x00;
10 
11 const uint8_t MITSUBISHI_COOL = 0x18;
12 const uint8_t MITSUBISHI_DRY = 0x10;
13 const uint8_t MITSUBISHI_AUTO = 0x20;
14 const uint8_t MITSUBISHI_HEAT = 0x08;
15 const uint8_t MITSUBISHI_FAN_AUTO = 0x00;
16 
17 // Pulse parameters in usec
18 const uint16_t MITSUBISHI_BIT_MARK = 430;
19 const uint16_t MITSUBISHI_ONE_SPACE = 1250;
20 const uint16_t MITSUBISHI_ZERO_SPACE = 390;
21 const uint16_t MITSUBISHI_HEADER_MARK = 3500;
22 const uint16_t MITSUBISHI_HEADER_SPACE = 1700;
23 const uint16_t MITSUBISHI_MIN_GAP = 17500;
24 
26  uint32_t remote_state[18] = {0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x00, 0x30,
27  0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
28 
29  switch (this->mode) {
31  remote_state[6] = MITSUBISHI_COOL;
32  break;
34  remote_state[6] = MITSUBISHI_HEAT;
35  break;
37  remote_state[6] = MITSUBISHI_AUTO;
38  break;
40  default:
41  remote_state[5] = MITSUBISHI_OFF;
42  break;
43  }
44 
45  remote_state[7] = (uint8_t) roundf(clamp<float>(this->target_temperature, MITSUBISHI_TEMP_MIN, MITSUBISHI_TEMP_MAX) -
47 
48  ESP_LOGV(TAG, "Sending Mitsubishi target temp: %.1f state: %02X mode: %02X temp: %02X", this->target_temperature,
49  remote_state[5], remote_state[6], remote_state[7]);
50 
51  // Checksum
52  for (int i = 0; i < 17; i++) {
53  remote_state[17] += remote_state[i];
54  }
55 
56  auto transmit = this->transmitter_->transmit();
57  auto *data = transmit.get_data();
58 
59  data->set_carrier_frequency(38000);
60  // repeat twice
61  for (uint16_t r = 0; r < 2; r++) {
62  // Header
63  data->mark(MITSUBISHI_HEADER_MARK);
64  data->space(MITSUBISHI_HEADER_SPACE);
65  // Data
66  for (uint8_t i : remote_state) {
67  for (uint8_t j = 0; j < 8; j++) {
68  data->mark(MITSUBISHI_BIT_MARK);
69  bool bit = i & (1 << j);
70  data->space(bit ? MITSUBISHI_ONE_SPACE : MITSUBISHI_ZERO_SPACE);
71  }
72  }
73  // Footer
74  if (r == 0) {
75  data->mark(MITSUBISHI_BIT_MARK);
76  data->space(MITSUBISHI_MIN_GAP); // Pause before repeating
77  }
78  }
79  data->mark(MITSUBISHI_BIT_MARK);
80 
81  transmit.perform();
82 }
83 
84 } // namespace mitsubishi
85 } // namespace esphome
const uint16_t MITSUBISHI_MIN_GAP
Definition: mitsubishi.cpp:23
const uint16_t MITSUBISHI_ONE_SPACE
Definition: mitsubishi.cpp:19
const uint8_t MITSUBISHI_AUTO
Definition: mitsubishi.cpp:13
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
void set_carrier_frequency(uint32_t carrier_frequency)
Definition: remote_base.h:30
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:175
const uint32_t MITSUBISHI_OFF
Definition: mitsubishi.cpp:9
void transmit_state() override
Transmit via IR the state of this climate controller.
Definition: mitsubishi.cpp:25
const uint16_t MITSUBISHI_BIT_MARK
Definition: mitsubishi.cpp:18
const uint8_t MITSUBISHI_HEAT
Definition: mitsubishi.cpp:14
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
const uint8_t MITSUBISHI_FAN_AUTO
Definition: mitsubishi.cpp:15
const uint8_t MITSUBISHI_TEMP_MAX
Definition: mitsubishi.h:10
const uint16_t MITSUBISHI_HEADER_SPACE
Definition: mitsubishi.cpp:22
const uint16_t MITSUBISHI_HEADER_MARK
Definition: mitsubishi.cpp:21
The climate device is set to heat/cool to reach the target temperature.
Definition: climate_mode.h:14
The climate device is off.
Definition: climate_mode.h:12
const uint8_t MITSUBISHI_DRY
Definition: mitsubishi.cpp:12
Definition: a4988.cpp:4
const uint8_t MITSUBISHI_TEMP_MIN
Definition: mitsubishi.h:9
const uint16_t MITSUBISHI_ZERO_SPACE
Definition: mitsubishi.cpp:20
remote_transmitter::RemoteTransmitterComponent * transmitter_
Definition: climate_ir.h:67
const uint8_t MITSUBISHI_COOL
Definition: mitsubishi.cpp:11