ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
coolix.cpp
Go to the documentation of this file.
1#include "coolix.h"
3#include "esphome/core/log.h"
4
5namespace esphome::coolix {
6
7static const char *const TAG = "coolix.climate";
8
9static const uint32_t COOLIX_OFF = 0xB27BE0;
10static const uint32_t COOLIX_SWING = 0xB26BE0;
11static const uint32_t COOLIX_LED = 0xB5F5A5;
12static const uint32_t COOLIX_SILENCE_FP = 0xB5F5B6;
13
14// On, 25C, Mode: Auto, Fan: Auto, Zone Follow: Off, Sensor Temp: Ignore.
15static const uint8_t COOLIX_COOL = 0b0000;
16static const uint8_t COOLIX_DRY_FAN = 0b0100;
17static const uint8_t COOLIX_AUTO = 0b1000;
18static const uint8_t COOLIX_HEAT = 0b1100;
19static const uint32_t COOLIX_MODE_MASK = 0b1100;
20static const uint32_t COOLIX_FAN_MASK = 0xF000;
21static const uint32_t COOLIX_FAN_MODE_AUTO_DRY = 0x1000;
22static const uint32_t COOLIX_FAN_AUTO = 0xB000;
23static const uint32_t COOLIX_FAN_MIN = 0x9000;
24static const uint32_t COOLIX_FAN_MED = 0x5000;
25static const uint32_t COOLIX_FAN_MAX = 0x3000;
26
27// Temperature
28static const uint8_t COOLIX_TEMP_RANGE = COOLIX_TEMP_MAX - COOLIX_TEMP_MIN + 1;
29static const uint8_t COOLIX_FAN_TEMP_CODE = 0b11100000; // Part of Fan Mode.
30static const uint32_t COOLIX_TEMP_MASK = 0b11110000;
31static const uint8_t COOLIX_TEMP_MAP[COOLIX_TEMP_RANGE] = {
32 0b00000000, // 17C
33 0b00010000, // 18c
34 0b00110000, // 19C
35 0b00100000, // 20C
36 0b01100000, // 21C
37 0b01110000, // 22C
38 0b01010000, // 23C
39 0b01000000, // 24C
40 0b11000000, // 25C
41 0b11010000, // 26C
42 0b10010000, // 27C
43 0b10000000, // 28C
44 0b10100000, // 29C
45 0b10110000 // 30C
46};
47
49 uint32_t remote_state = 0xB20F00;
50
51 if (send_swing_cmd_) {
52 send_swing_cmd_ = false;
53 remote_state = COOLIX_SWING;
54 } else {
55 switch (this->mode) {
57 remote_state |= COOLIX_COOL;
58 break;
60 remote_state |= COOLIX_HEAT;
61 break;
63 remote_state |= COOLIX_AUTO;
64 break;
67 remote_state |= COOLIX_DRY_FAN;
68 break;
70 default:
71 remote_state = COOLIX_OFF;
72 break;
73 }
74 if (this->mode != climate::CLIMATE_MODE_OFF) {
76 auto temp = (uint8_t) roundf(clamp<float>(this->target_temperature, COOLIX_TEMP_MIN, COOLIX_TEMP_MAX));
77 remote_state |= COOLIX_TEMP_MAP[temp - COOLIX_TEMP_MIN];
78 } else {
79 remote_state |= COOLIX_FAN_TEMP_CODE;
80 }
83 remote_state |= COOLIX_FAN_MODE_AUTO_DRY;
84 } else {
85 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
87 remote_state |= COOLIX_FAN_MAX;
88 break;
90 remote_state |= COOLIX_FAN_MED;
91 break;
93 remote_state |= COOLIX_FAN_MIN;
94 break;
96 default:
97 remote_state |= COOLIX_FAN_AUTO;
98 break;
99 }
100 }
101 }
102 }
103 ESP_LOGV(TAG, "Sending coolix code: 0x%06" PRIX32, remote_state);
104 this->transmit_<remote_base::CoolixProtocol>(remote_state);
105}
106
108 auto decoded = remote_base::CoolixProtocol().decode(data);
109 if (!decoded.has_value())
110 return false;
111 // Decoded remote state y 3 bytes long code.
112 uint32_t remote_state = (*decoded).second;
113 ESP_LOGV(TAG, "Decoded 0x%06" PRIX32, remote_state);
114 if ((remote_state & 0xFF0000) != 0xB20000)
115 return false;
116
117 if (remote_state == COOLIX_OFF) {
119 } else if (remote_state == COOLIX_SWING) {
120 parent->swing_mode =
122 } else {
123 if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) {
125 } else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_AUTO) {
127 } else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) {
128 if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) {
130 } else {
132 }
133 } else {
135 }
136
137 // Fan Speed
138 if ((remote_state & COOLIX_FAN_AUTO) == COOLIX_FAN_AUTO || parent->mode == climate::CLIMATE_MODE_HEAT_COOL ||
139 parent->mode == climate::CLIMATE_MODE_DRY) {
141 } else if ((remote_state & COOLIX_FAN_MIN) == COOLIX_FAN_MIN) {
143 } else if ((remote_state & COOLIX_FAN_MED) == COOLIX_FAN_MED) {
145 } else if ((remote_state & COOLIX_FAN_MAX) == COOLIX_FAN_MAX) {
147 }
148
149 // Temperature
150 uint8_t temperature_code = remote_state & COOLIX_TEMP_MASK;
151 for (uint8_t i = 0; i < COOLIX_TEMP_RANGE; i++) {
152 if (COOLIX_TEMP_MAP[i] == temperature_code)
154 }
155 }
156 parent->publish_state();
157
158 return true;
159}
160
161} // namespace esphome::coolix
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:187
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
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:437
void transmit_state() override
Transmit via IR the state of this climate controller.
Definition coolix.cpp:48
static bool on_coolix(climate::Climate *parent, remote_base::RemoteReceiveData data)
This static method can be used in other climate components that accept the Coolix protocol.
Definition coolix.cpp:107
optional< CoolixData > decode(RemoteReceiveData data) override
void transmit_(const Protocol::ProtocolData &data, uint32_t send_times=1, uint32_t send_wait=0)
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ 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_HIGH
The fan mode is set to High.
const uint8_t COOLIX_TEMP_MAX
Definition coolix.h:11
const uint8_t COOLIX_TEMP_MIN
Definition coolix.h:10
static void uint32_t