ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
haier_tundra.cpp
Go to the documentation of this file.
1#include "haier_tundra.h"
2
4
5// Number of bytes in decoded packet sans checksum
6static constexpr uint8_t HAIER_TUNDRA_FRAME_SIZE = 13;
7
9 // Button value does not seem to matter too much except
10 // when toggling light, as it has no bit flag of its own
11 // So in the default case we can simply set it to POWER
12 this->transmit_(HAIER_BUTTON_POWER);
13}
14
15void HaierTundra::transmit_(uint8_t button) {
16 // Force Quiet and Turbo off if we're not in Cool or Heat mode
18#ifdef USE_SWITCH
19 PUBLISH_STATE(this->quiet_mode_switch_, false);
20 PUBLISH_STATE(this->turbo_mode_switch_, false);
21#endif
22
23 this->quiet_mode_ = false;
24 this->turbo_mode_ = false;
25 }
26
27 const uint8_t frame[HAIER_TUNDRA_FRAME_SIZE] = {
28 this->unit_,
29 static_cast<uint8_t>(this->temperature_() << 4 | this->vertical_swing_()),
30 static_cast<uint8_t>(this->horizontal_swing_() << 5),
31 static_cast<uint8_t>(this->health_() << 1),
32 static_cast<uint8_t>(this->power_() << 6),
33 static_cast<uint8_t>(this->fan_speed_() << 5),
34 static_cast<uint8_t>(this->quiet_() << 7 | this->turbo_() << 6),
35 static_cast<uint8_t>(this->operation_mode_() << 5),
36 0x00,
37 0x00,
38 static_cast<uint8_t>((button == HAIER_BUTTON_SELF_CLEAN ? 1 : 0) << 4),
39 0x00,
40 button,
41 };
42
43 auto transmit = this->transmitter_->transmit();
44 remote_base::HaierProtocol().encode(transmit.get_data(), frame, sizeof(frame));
45 transmit.perform();
46}
47
49 return (uint8_t) roundf(clamp<float>(this->target_temperature, HAIER_TEMP_MIN, HAIER_TEMP_MAX)) - HAIER_TEMP_MIN;
50}
51
53 if (this->mode == climate::CLIMATE_MODE_OFF) {
54 return HAIER_SWING_V_OFF;
55 }
56 switch (this->swing_mode) {
59 return HAIER_SWING_V_AUTO;
60 default:
61 if (this->mode == climate::CLIMATE_MODE_HEAT) {
62 return HAIER_SWING_V_1BOT;
63 }
64 return HAIER_SWING_V_1TOP; // Cool/Dry/Auto
65 }
66}
67
69 switch (this->swing_mode) {
72 return HAIER_SWING_H_AUTO;
73 default:
74 return HAIER_SWING_H_MIDDLE;
75 }
76}
77
78uint8_t HaierTundra::health_() { return this->health_mode_ ? 1 : 0; }
79
80uint8_t HaierTundra::power_() { return this->mode == climate::CLIMATE_MODE_OFF ? 0 : 1; }
81
83 switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
85 return HAIER_FAN_LOW;
87 return HAIER_FAN_MED;
89 return HAIER_FAN_HIGH;
91 default:
92 return HAIER_FAN_AUTO;
93 }
94}
95
96uint8_t HaierTundra::quiet_() { return this->quiet_mode_ ? 1 : 0; }
97
98uint8_t HaierTundra::turbo_() { return this->turbo_mode_ ? 1 : 0; }
99
101 switch (this->mode) {
103 return HAIER_MODE_COOL;
105 return HAIER_MODE_DRY;
107 return HAIER_MODE_HEAT;
109 return HAIER_MODE_FAN;
111 default:
112 return HAIER_MODE_AUTO;
113 }
114}
115
117 auto haier = remote_base::HaierProtocol().decode(data);
118 if (haier.has_value()) {
119 return this->on_haier_(*haier);
120 }
121 return false;
122}
123
125 // Verify frame length and header
126 if (haier.data.size() != HAIER_TUNDRA_FRAME_SIZE || haier.data[0] != this->unit_) {
127 return false;
128 }
129
130 this->target_temperature = this->get_temperature_(haier.data[1] >> 4);
131 this->swing_mode = this->get_swing_mode_(haier.data[1] & 0xF, haier.data[2] >> 5);
132 this->health_mode_ = haier.data[3] & 0x2;
133 this->mode = this->get_operation_mode_(haier.data[4] & 0x40, haier.data[7] >> 5);
134 this->fan_mode = this->get_fan_speed_(haier.data[5] >> 5);
135 this->quiet_mode_ = haier.data[6] & 0x80;
136 this->turbo_mode_ = haier.data[6] & 0x40;
137
138#ifdef USE_SWITCH
139 PUBLISH_STATE(this->health_mode_switch_, this->health_mode_);
140 PUBLISH_STATE(this->quiet_mode_switch_, this->quiet_mode_);
141 PUBLISH_STATE(this->turbo_mode_switch_, this->turbo_mode_);
142#endif
143
144 this->publish_state();
145
146 return true;
147}
148
149float HaierTundra::get_temperature_(uint8_t temp) { return temp + HAIER_TEMP_MIN; }
150
152 if (swing_v == HAIER_SWING_V_AUTO) {
153 if (swing_h == HAIER_SWING_H_AUTO) {
155 }
156
158 } else if (swing_h == HAIER_SWING_H_AUTO) {
160 }
161
163}
164
166 if (!power) {
168 }
169
170 switch (mode) {
171 case HAIER_MODE_COOL:
173 case HAIER_MODE_DRY:
175 case HAIER_MODE_HEAT:
177 case HAIER_MODE_FAN:
179 case HAIER_MODE_AUTO:
180 default:
182 }
183}
184
186 switch (fan) {
187 case HAIER_FAN_LOW:
189 case HAIER_FAN_MED:
191 case HAIER_FAN_HIGH:
193 case HAIER_FAN_AUTO:
194 default:
196 }
197}
198
199void HaierTundra::set_health_mode(bool health, bool transmit) {
200 this->health_mode_ = health;
201
202 if (transmit && this->mode != climate::CLIMATE_MODE_OFF) {
203 this->transmit_(HAIER_BUTTON_HEALTH);
204 }
205}
206
207void HaierTundra::set_quiet_mode(bool quiet, bool transmit) {
208 // Quiet & Turbo cannot be enabled at the same time
209 if (quiet) {
210#ifdef USE_SWITCH
211 PUBLISH_STATE(this->turbo_mode_switch_, false);
212#endif
213 this->turbo_mode_ = false;
214 }
215
216 this->quiet_mode_ = quiet;
217 if (transmit)
218 this->transmit_(HAIER_BUTTON_TURBO_QUIET);
219}
220
221void HaierTundra::set_turbo_mode(bool turbo, bool transmit) {
222 // Quiet & Turbo cannot be enabled at the same time
223 if (turbo) {
224#ifdef USE_SWITCH
225 PUBLISH_STATE(this->quiet_mode_switch_, false);
226#endif
227 this->quiet_mode_ = false;
228 }
229
230 this->turbo_mode_ = turbo;
231 if (transmit)
232 this->transmit_(HAIER_BUTTON_TURBO_QUIET);
233}
234
236 if (this->mode != climate::CLIMATE_MODE_OFF) {
237 this->transmit_(HAIER_BUTTON_LIGHT);
238 }
239}
240
242 // Can be started when off
243 this->transmit_(HAIER_BUTTON_SELF_CLEAN);
244}
245
246} // namespace esphome::haier_tundra
BedjetMode mode
BedJet operating mode.
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:311
float target_temperature
The target temperature of the climate device.
Definition climate.h:298
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:323
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
void set_quiet_mode(bool quiet, bool transmit=true)
climate::ClimateSwingMode get_swing_mode_(uint8_t swing_v, uint8_t swing_h)
bool on_haier_(const remote_base::HaierData &haier)
void set_turbo_mode(bool turbo, bool transmit=true)
climate::ClimateFanMode get_fan_speed_(uint8_t fan)
climate::ClimateMode get_operation_mode_(uint8_t power, uint8_t mode)
void set_health_mode(bool health, bool transmit=true)
bool on_receive(remote_base::RemoteReceiveData data) override
void encode(RemoteTransmitData *dst, const HaierData &data)
optional< HaierData > decode(RemoteReceiveData src)
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ 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.
ClimateMode
Enum for all modes a climate device can be in.
@ 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_HIGH
The fan mode is set to High.
std::vector< uint8_t > data