ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
heatpumpir.cpp
Go to the documentation of this file.
1#include "heatpumpir.h"
2
3#ifdef USE_ARDUINO
4
5#include <map>
6#include "ir_sender_esphome.h"
7#include "HeatpumpIRFactory.h"
8#include "esphome/core/log.h"
9
10namespace esphome {
11namespace heatpumpir {
12
13static const char *const TAG = "heatpumpir.climate";
14
15const std::map<Protocol, std::function<HeatpumpIR *()>> PROTOCOL_CONSTRUCTOR_MAP = {
16 {PROTOCOL_AUX, []() { return new AUXHeatpumpIR(); }}, // NOLINT
17 {PROTOCOL_BALLU, []() { return new BalluHeatpumpIR(); }}, // NOLINT
18 {PROTOCOL_CARRIER_MCA, []() { return new CarrierMCAHeatpumpIR(); }}, // NOLINT
19 {PROTOCOL_CARRIER_NQV, []() { return new CarrierNQVHeatpumpIR(); }}, // NOLINT
20 {PROTOCOL_DAIKIN_ARC417, []() { return new DaikinHeatpumpARC417IR(); }}, // NOLINT
21 {PROTOCOL_DAIKIN_ARC480, []() { return new DaikinHeatpumpARC480A14IR(); }}, // NOLINT
22 {PROTOCOL_DAIKIN, []() { return new DaikinHeatpumpIR(); }}, // NOLINT
23 {PROTOCOL_ELECTROLUXYAL, []() { return new ElectroluxYALHeatpumpIR(); }}, // NOLINT
24 {PROTOCOL_FUEGO, []() { return new FuegoHeatpumpIR(); }}, // NOLINT
25 {PROTOCOL_FUJITSU_AWYZ, []() { return new FujitsuHeatpumpIR(); }}, // NOLINT
26 {PROTOCOL_GREE, []() { return new GreeGenericHeatpumpIR(); }}, // NOLINT
27 {PROTOCOL_GREEYAA, []() { return new GreeYAAHeatpumpIR(); }}, // NOLINT
28 {PROTOCOL_GREEYAN, []() { return new GreeYANHeatpumpIR(); }}, // NOLINT
29 {PROTOCOL_GREEYAC, []() { return new GreeYACHeatpumpIR(); }}, // NOLINT
30 {PROTOCOL_GREEYT, []() { return new GreeYTHeatpumpIR(); }}, // NOLINT
31 {PROTOCOL_GREEYAP, []() { return new GreeYAPHeatpumpIR(); }}, // NOLINT
32 {PROTOCOL_HISENSE_AUD, []() { return new HisenseHeatpumpIR(); }}, // NOLINT
33 {PROTOCOL_HITACHI, []() { return new HitachiHeatpumpIR(); }}, // NOLINT
34 {PROTOCOL_HYUNDAI, []() { return new HyundaiHeatpumpIR(); }}, // NOLINT
35 {PROTOCOL_IVT, []() { return new IVTHeatpumpIR(); }}, // NOLINT
36 {PROTOCOL_MIDEA, []() { return new MideaHeatpumpIR(); }}, // NOLINT
37 {PROTOCOL_MITSUBISHI_FA, []() { return new MitsubishiFAHeatpumpIR(); }}, // NOLINT
38 {PROTOCOL_MITSUBISHI_FD, []() { return new MitsubishiFDHeatpumpIR(); }}, // NOLINT
39 {PROTOCOL_MITSUBISHI_FE, []() { return new MitsubishiFEHeatpumpIR(); }}, // NOLINT
40 {PROTOCOL_MITSUBISHI_HEAVY_FDTC, []() { return new MitsubishiHeavyFDTCHeatpumpIR(); }}, // NOLINT
41 {PROTOCOL_MITSUBISHI_HEAVY_ZJ, []() { return new MitsubishiHeavyZJHeatpumpIR(); }}, // NOLINT
42 {PROTOCOL_MITSUBISHI_HEAVY_ZM, []() { return new MitsubishiHeavyZMHeatpumpIR(); }}, // NOLINT
43 {PROTOCOL_MITSUBISHI_HEAVY_ZMP, []() { return new MitsubishiHeavyZMPHeatpumpIR(); }}, // NOLINT
44 {PROTOCOL_MITSUBISHI_KJ, []() { return new MitsubishiKJHeatpumpIR(); }}, // NOLINT
45 {PROTOCOL_MITSUBISHI_MSC, []() { return new MitsubishiMSCHeatpumpIR(); }}, // NOLINT
46 {PROTOCOL_MITSUBISHI_MSY, []() { return new MitsubishiMSYHeatpumpIR(); }}, // NOLINT
47 {PROTOCOL_MITSUBISHI_SEZ, []() { return new MitsubishiSEZKDXXHeatpumpIR(); }}, // NOLINT
48 {PROTOCOL_PANASONIC_CKP, []() { return new PanasonicCKPHeatpumpIR(); }}, // NOLINT
49 {PROTOCOL_PANASONIC_DKE, []() { return new PanasonicDKEHeatpumpIR(); }}, // NOLINT
50 {PROTOCOL_PANASONIC_EKE, []() { return new PanasonicEKEHeatpumpIR(); }}, // NOLINT
51 {PROTOCOL_PANASONIC_JKE, []() { return new PanasonicJKEHeatpumpIR(); }}, // NOLINT
52 {PROTOCOL_PANASONIC_LKE, []() { return new PanasonicLKEHeatpumpIR(); }}, // NOLINT
53 {PROTOCOL_PANASONIC_NKE, []() { return new PanasonicNKEHeatpumpIR(); }}, // NOLINT
54 {PROTOCOL_SAMSUNG_AQV, []() { return new SamsungAQVHeatpumpIR(); }}, // NOLINT
55 {PROTOCOL_SAMSUNG_FJM, []() { return new SamsungFJMHeatpumpIR(); }}, // NOLINT
56 {PROTOCOL_SHARP, []() { return new SharpHeatpumpIR(); }}, // NOLINT
57 {PROTOCOL_TOSHIBA_DAISEIKAI, []() { return new ToshibaDaiseikaiHeatpumpIR(); }}, // NOLINT
58 {PROTOCOL_TOSHIBA, []() { return new ToshibaHeatpumpIR(); }}, // NOLINT
59 {PROTOCOL_ZHLT01, []() { return new ZHLT01HeatpumpIR(); }}, // NOLINT
60 {PROTOCOL_NIBE, []() { return new NibeHeatpumpIR(); }}, // NOLINT
61 {PROTOCOL_QLIMA_1, []() { return new Qlima1HeatpumpIR(); }}, // NOLINT
62 {PROTOCOL_QLIMA_2, []() { return new Qlima2HeatpumpIR(); }}, // NOLINT
63 {PROTOCOL_SAMSUNG_AQV12MSAN, []() { return new SamsungAQV12MSANHeatpumpIR(); }}, // NOLINT
64 {PROTOCOL_ZHJG01, []() { return new ZHJG01HeatpumpIR(); }}, // NOLINT
65 {PROTOCOL_AIRWAY, []() { return new AIRWAYHeatpumpIR(); }}, // NOLINT
66 {PROTOCOL_BGH_AUD, []() { return new BGHHeatpumpIR(); }}, // NOLINT
67 {PROTOCOL_PANASONIC_ALTDKE, []() { return new PanasonicAltDKEHeatpumpIR(); }}, // NOLINT
68 {PROTOCOL_PHILCO_PHS32, []() { return new PhilcoPHS32HeatpumpIR(); }}, // NOLINT
69 {PROTOCOL_VAILLANTVAI8, []() { return new VaillantHeatpumpIR(); }}, // NOLINT
70 {PROTOCOL_R51M, []() { return new R51MHeatpumpIR(); }}, // NOLINT
71};
72
74 auto protocol_constructor = PROTOCOL_CONSTRUCTOR_MAP.find(protocol_);
75 if (protocol_constructor == PROTOCOL_CONSTRUCTOR_MAP.end()) {
76 ESP_LOGE(TAG, "Invalid protocol");
77 return;
78 }
79 this->heatpump_ir_ = protocol_constructor->second();
81 if (this->sensor_) {
82 this->sensor_->add_on_state_callback([this](float state) {
84
85 IRSenderESPHome esp_sender(this->transmitter_);
86 this->heatpump_ir_->send(esp_sender, uint8_t(lround(this->current_temperature + 0.5)));
87
88 // current temperature changed, publish state
89 this->publish_state();
90 });
91 this->current_temperature = this->sensor_->state;
92 } else {
93 this->current_temperature = NAN;
94 }
95}
96
98 uint8_t power_mode_cmd;
99 uint8_t operating_mode_cmd;
100 uint8_t temperature_cmd;
101 uint8_t fan_speed_cmd;
102
103 uint8_t swing_v_cmd;
106 swing_v_cmd = VDIR_AUTO;
107 break;
109 swing_v_cmd = VDIR_UP;
110 break;
112 swing_v_cmd = VDIR_MUP;
113 break;
115 swing_v_cmd = VDIR_MIDDLE;
116 break;
118 swing_v_cmd = VDIR_MDOWN;
119 break;
121 swing_v_cmd = VDIR_DOWN;
122 break;
123 default:
124 ESP_LOGE(TAG, "Invalid default vertical direction");
125 return;
126 }
128 swing_v_cmd = VDIR_SWING;
129 }
130
131 uint8_t swing_h_cmd;
134 swing_h_cmd = HDIR_AUTO;
135 break;
137 swing_h_cmd = HDIR_MIDDLE;
138 break;
140 swing_h_cmd = HDIR_LEFT;
141 break;
143 swing_h_cmd = HDIR_MLEFT;
144 break;
146 swing_h_cmd = HDIR_MRIGHT;
147 break;
149 swing_h_cmd = HDIR_RIGHT;
150 break;
151 default:
152 ESP_LOGE(TAG, "Invalid default horizontal direction");
153 return;
154 }
156 swing_h_cmd = HDIR_SWING;
157 }
158
161 fan_speed_cmd = FAN_2;
162 break;
164 fan_speed_cmd = FAN_3;
165 break;
167 fan_speed_cmd = FAN_4;
168 break;
170 default:
171 fan_speed_cmd = FAN_AUTO;
172 break;
173 }
174
175 switch (this->mode) {
177 power_mode_cmd = POWER_ON;
178 operating_mode_cmd = MODE_COOL;
179 break;
181 power_mode_cmd = POWER_ON;
182 operating_mode_cmd = MODE_HEAT;
183 break;
185 power_mode_cmd = POWER_ON;
186 operating_mode_cmd = MODE_AUTO;
187 break;
189 power_mode_cmd = POWER_ON;
190 operating_mode_cmd = MODE_FAN;
191 break;
193 power_mode_cmd = POWER_ON;
194 operating_mode_cmd = MODE_DRY;
195 break;
197 default:
198 power_mode_cmd = POWER_OFF;
199 operating_mode_cmd = MODE_AUTO;
200 break;
201 }
202
203 temperature_cmd = (uint8_t) clamp(this->target_temperature, this->min_temperature_, this->max_temperature_);
204
205 IRSenderESPHome esp_sender(this->transmitter_);
206 heatpump_ir_->send(esp_sender, power_mode_cmd, operating_mode_cmd, fan_speed_cmd, temperature_cmd, swing_v_cmd,
207 swing_h_cmd);
208}
209
210} // namespace heatpumpir
211} // namespace esphome
212
213#endif
ClimateMode mode
The active mode of the climate device.
Definition climate.h:173
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:199
float target_temperature
The target temperature of the climate device.
Definition climate.h:186
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:202
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:179
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:395
VerticalDirection default_vertical_direction_
Definition heatpumpir.h:124
void transmit_state() override
Transmit via IR the state of this climate controller.
HorizontalDirection default_horizontal_direction_
Definition heatpumpir.h:123
value_type value_or(U const &v) const
Definition optional.h:98
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:60
float state
This member variable stores the last state that has passed through all filters.
Definition sensor.h:133
bool state
Definition fan.h:0
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ 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_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
@ 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_HIGH
The fan mode is set to High.
const std::map< Protocol, std::function< HeatpumpIR *()> > PROTOCOL_CONSTRUCTOR_MAP
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7