ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
climate.cpp
Go to the documentation of this file.
1#include "climate.h"
5#include <strings.h>
6
7namespace esphome::climate {
8
9static const char *const TAG = "climate";
10
11// Memory-efficient lookup tables
12struct StringToUint8 {
13 const char *str;
14 const uint8_t value;
15};
16
17constexpr StringToUint8 CLIMATE_MODES_BY_STR[] = {
18 {"OFF", CLIMATE_MODE_OFF},
19 {"AUTO", CLIMATE_MODE_AUTO},
20 {"COOL", CLIMATE_MODE_COOL},
21 {"HEAT", CLIMATE_MODE_HEAT},
22 {"FAN_ONLY", CLIMATE_MODE_FAN_ONLY},
23 {"DRY", CLIMATE_MODE_DRY},
24 {"HEAT_COOL", CLIMATE_MODE_HEAT_COOL},
25};
26
27constexpr StringToUint8 CLIMATE_FAN_MODES_BY_STR[] = {
28 {"ON", CLIMATE_FAN_ON}, {"OFF", CLIMATE_FAN_OFF}, {"AUTO", CLIMATE_FAN_AUTO},
29 {"LOW", CLIMATE_FAN_LOW}, {"MEDIUM", CLIMATE_FAN_MEDIUM}, {"HIGH", CLIMATE_FAN_HIGH},
30 {"MIDDLE", CLIMATE_FAN_MIDDLE}, {"FOCUS", CLIMATE_FAN_FOCUS}, {"DIFFUSE", CLIMATE_FAN_DIFFUSE},
31 {"QUIET", CLIMATE_FAN_QUIET},
32};
33
34constexpr StringToUint8 CLIMATE_PRESETS_BY_STR[] = {
35 {"ECO", CLIMATE_PRESET_ECO}, {"AWAY", CLIMATE_PRESET_AWAY}, {"BOOST", CLIMATE_PRESET_BOOST},
36 {"COMFORT", CLIMATE_PRESET_COMFORT}, {"HOME", CLIMATE_PRESET_HOME}, {"SLEEP", CLIMATE_PRESET_SLEEP},
37 {"ACTIVITY", CLIMATE_PRESET_ACTIVITY}, {"NONE", CLIMATE_PRESET_NONE},
38};
39
40constexpr StringToUint8 CLIMATE_SWING_MODES_BY_STR[] = {
41 {"OFF", CLIMATE_SWING_OFF},
42 {"BOTH", CLIMATE_SWING_BOTH},
43 {"VERTICAL", CLIMATE_SWING_VERTICAL},
44 {"HORIZONTAL", CLIMATE_SWING_HORIZONTAL},
45};
46
48 this->parent_->control_callback_.call(*this);
49 ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
50 this->validate_();
51 if (this->mode_.has_value()) {
52 const LogString *mode_s = climate_mode_to_string(*this->mode_);
53 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(mode_s));
54 }
55 if (this->custom_fan_mode_ != nullptr) {
56 this->fan_mode_.reset();
57 ESP_LOGD(TAG, " Custom Fan: %s", this->custom_fan_mode_);
58 }
59 if (this->fan_mode_.has_value()) {
60 this->custom_fan_mode_ = nullptr;
61 const LogString *fan_mode_s = climate_fan_mode_to_string(*this->fan_mode_);
62 ESP_LOGD(TAG, " Fan: %s", LOG_STR_ARG(fan_mode_s));
63 }
64 if (this->custom_preset_ != nullptr) {
65 this->preset_.reset();
66 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
67 }
68 if (this->preset_.has_value()) {
69 this->custom_preset_ = nullptr;
70 const LogString *preset_s = climate_preset_to_string(*this->preset_);
71 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(preset_s));
72 }
73 if (this->swing_mode_.has_value()) {
74 const LogString *swing_mode_s = climate_swing_mode_to_string(*this->swing_mode_);
75 ESP_LOGD(TAG, " Swing: %s", LOG_STR_ARG(swing_mode_s));
76 }
77 if (this->target_temperature_.has_value()) {
78 ESP_LOGD(TAG, " Target Temperature: %.2f", *this->target_temperature_);
79 }
81 ESP_LOGD(TAG, " Target Temperature Low: %.2f", *this->target_temperature_low_);
82 }
84 ESP_LOGD(TAG, " Target Temperature High: %.2f", *this->target_temperature_high_);
85 }
86 if (this->target_humidity_.has_value()) {
87 ESP_LOGD(TAG, " Target Humidity: %.0f", *this->target_humidity_);
88 }
89 this->parent_->control(*this);
90}
91
93 auto traits = this->parent_->get_traits();
94 if (this->mode_.has_value()) {
95 auto mode = *this->mode_;
96 if (!traits.supports_mode(mode)) {
97 ESP_LOGW(TAG, " Mode %s not supported", LOG_STR_ARG(climate_mode_to_string(mode)));
98 this->mode_.reset();
99 }
100 }
101 if (this->custom_fan_mode_ != nullptr) {
102 if (!traits.supports_custom_fan_mode(this->custom_fan_mode_)) {
103 ESP_LOGW(TAG, " Fan Mode %s not supported", this->custom_fan_mode_);
104 this->custom_fan_mode_ = nullptr;
105 }
106 } else if (this->fan_mode_.has_value()) {
107 auto fan_mode = *this->fan_mode_;
108 if (!traits.supports_fan_mode(fan_mode)) {
109 ESP_LOGW(TAG, " Fan Mode %s not supported", LOG_STR_ARG(climate_fan_mode_to_string(fan_mode)));
110 this->fan_mode_.reset();
111 }
112 }
113 if (this->custom_preset_ != nullptr) {
114 if (!traits.supports_custom_preset(this->custom_preset_)) {
115 ESP_LOGW(TAG, " Preset %s not supported", this->custom_preset_);
116 this->custom_preset_ = nullptr;
117 }
118 } else if (this->preset_.has_value()) {
119 auto preset = *this->preset_;
120 if (!traits.supports_preset(preset)) {
121 ESP_LOGW(TAG, " Preset %s not supported", LOG_STR_ARG(climate_preset_to_string(preset)));
122 this->preset_.reset();
123 }
124 }
125 if (this->swing_mode_.has_value()) {
126 auto swing_mode = *this->swing_mode_;
127 if (!traits.supports_swing_mode(swing_mode)) {
128 ESP_LOGW(TAG, " Swing Mode %s not supported", LOG_STR_ARG(climate_swing_mode_to_string(swing_mode)));
129 this->swing_mode_.reset();
130 }
131 }
132 if (this->target_temperature_.has_value()) {
133 auto target = *this->target_temperature_;
134 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
136 ESP_LOGW(TAG, " Cannot set target temperature for climate device "
137 "with two-point target temperature");
139 } else if (std::isnan(target)) {
140 ESP_LOGW(TAG, " Target temperature must not be NAN");
142 }
143 }
144 if (this->target_temperature_low_.has_value() || this->target_temperature_high_.has_value()) {
145 if (!traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
147 ESP_LOGW(TAG, " Cannot set low/high target temperature");
150 }
151 }
152 if (this->target_temperature_low_.has_value() && std::isnan(*this->target_temperature_low_)) {
153 ESP_LOGW(TAG, " Target temperature low must not be NAN");
155 }
156 if (this->target_temperature_high_.has_value() && std::isnan(*this->target_temperature_high_)) {
157 ESP_LOGW(TAG, " Target temperature high must not be NAN");
159 }
160 if (this->target_temperature_low_.has_value() && this->target_temperature_high_.has_value()) {
161 float low = *this->target_temperature_low_;
162 float high = *this->target_temperature_high_;
163 if (low > high) {
164 ESP_LOGW(TAG, " Target temperature low %.2f must be less than target temperature high %.2f", low, high);
167 }
168 }
169}
170
172 this->mode_ = mode;
173 return *this;
174}
175
176ClimateCall &ClimateCall::set_mode(const std::string &mode) { return this->set_mode(mode.c_str(), mode.size()); }
177
179 StringRef mode_ref(mode, len);
180 for (const auto &mode_entry : CLIMATE_MODES_BY_STR) {
181 if (str_equals_case_insensitive(mode_ref, mode_entry.str)) {
182 this->set_mode(static_cast<ClimateMode>(mode_entry.value));
183 return *this;
184 }
185 }
186 ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", this->parent_->get_name().c_str(), (int) len, mode);
187 return *this;
188}
189
191 this->fan_mode_ = fan_mode;
192 this->custom_fan_mode_ = nullptr;
193 return *this;
194}
195
197 return this->set_fan_mode(custom_fan_mode, strlen(custom_fan_mode));
198}
199
201 return this->set_fan_mode(fan_mode.data(), fan_mode.size());
202}
203
205 // Check if it's a standard enum mode first
206 for (const auto &mode_entry : CLIMATE_FAN_MODES_BY_STR) {
207 if (strncasecmp(custom_fan_mode, mode_entry.str, len) == 0 && mode_entry.str[len] == '\0') {
208 return this->set_fan_mode(static_cast<ClimateFanMode>(mode_entry.value));
209 }
210 }
211 // Find the matching pointer from parent climate device
212 if (const char *mode_ptr = this->parent_->find_custom_fan_mode_(custom_fan_mode, len)) {
213 this->custom_fan_mode_ = mode_ptr;
214 this->fan_mode_.reset();
215 return *this;
216 }
217 ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %.*s", this->parent_->get_name().c_str(), (int) len, custom_fan_mode);
218 return *this;
219}
220
222 if (fan_mode.has_value()) {
223 this->set_fan_mode(fan_mode.value());
224 }
225 return *this;
226}
227
229 this->preset_ = preset;
230 this->custom_preset_ = nullptr;
231 return *this;
232}
233
235 return this->set_preset(custom_preset, strlen(custom_preset));
236}
237
239 return this->set_preset(preset.data(), preset.size());
240}
241
243 // Check if it's a standard enum preset first
244 for (const auto &preset_entry : CLIMATE_PRESETS_BY_STR) {
245 if (strncasecmp(custom_preset, preset_entry.str, len) == 0 && preset_entry.str[len] == '\0') {
246 return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
247 }
248 }
249 // Find the matching pointer from parent climate device
250 if (const char *preset_ptr = this->parent_->find_custom_preset_(custom_preset, len)) {
251 this->custom_preset_ = preset_ptr;
252 this->preset_.reset();
253 return *this;
254 }
255 ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", this->parent_->get_name().c_str(), (int) len, custom_preset);
256 return *this;
257}
258
260 if (preset.has_value()) {
261 this->set_preset(preset.value());
262 }
263 return *this;
264}
265
270
272 return this->set_swing_mode(swing_mode.c_str(), swing_mode.size());
273}
274
276 StringRef mode_ref(swing_mode, len);
277 for (const auto &mode_entry : CLIMATE_SWING_MODES_BY_STR) {
278 if (str_equals_case_insensitive(mode_ref, mode_entry.str)) {
279 this->set_swing_mode(static_cast<ClimateSwingMode>(mode_entry.value));
280 return *this;
281 }
282 }
283 ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %.*s", this->parent_->get_name().c_str(), (int) len, swing_mode);
284 return *this;
285}
286
291
296
301
306
311
312const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
316
321
326
331
336
341
343 this->fan_mode_ = fan_mode;
344 this->custom_fan_mode_ = nullptr;
345 return *this;
346}
347
349 this->preset_ = preset;
350 this->custom_preset_ = nullptr;
351 return *this;
352}
353
358
359void Climate::add_on_state_callback(std::function<void(Climate &)> &&callback) {
360 this->state_callback_.add(std::move(callback));
361}
362
363void Climate::add_on_control_callback(std::function<void(ClimateCall &)> &&callback) {
364 this->control_callback_.add(std::move(callback));
365}
366
367// Random 32bit value; If this changes existing restore preferences are invalidated
368static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
369
371 this->rtc_ = this->make_entity_preference<ClimateDeviceRestoreState>(RESTORE_STATE_VERSION);
372 ClimateDeviceRestoreState recovered{};
373 if (!this->rtc_.load(&recovered))
374 return {};
375 return recovered;
376}
377
379#if (defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
380 !defined(CLANG_TIDY)
381#pragma GCC diagnostic ignored "-Wclass-memaccess"
382#define TEMP_IGNORE_MEMACCESS
383#endif
385 // initialize as zero to prevent random data on stack triggering erase
386 memset(&state, 0, sizeof(ClimateDeviceRestoreState));
387#ifdef TEMP_IGNORE_MEMACCESS
388#pragma GCC diagnostic pop
389#undef TEMP_IGNORE_MEMACCESS
390#endif
391
392 state.mode = this->mode;
393 auto traits = this->get_traits();
396 state.target_temperature_low = this->target_temperature_low;
397 state.target_temperature_high = this->target_temperature_high;
398 } else {
399 state.target_temperature = this->target_temperature;
400 }
402 state.target_humidity = this->target_humidity;
403 }
405 state.uses_custom_fan_mode = false;
406 state.fan_mode = this->fan_mode.value();
407 }
408 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
409 state.uses_custom_fan_mode = true;
410 const auto &supported = traits.get_supported_custom_fan_modes();
411 // std::vector maintains insertion order
412 size_t i = 0;
413 for (const char *mode : supported) {
414 if (strcmp(mode, this->custom_fan_mode_) == 0) {
415 state.custom_fan_mode = i;
416 break;
417 }
418 i++;
419 }
420 }
422 state.uses_custom_preset = false;
423 state.preset = this->preset.value();
424 }
425 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
426 state.uses_custom_preset = true;
427 const auto &supported = traits.get_supported_custom_presets();
428 // std::vector maintains insertion order
429 size_t i = 0;
430 for (const char *preset : supported) {
431 if (strcmp(preset, this->custom_preset_) == 0) {
432 state.custom_preset = i;
433 break;
434 }
435 i++;
436 }
437 }
439 state.swing_mode = this->swing_mode;
440 }
441
442 this->rtc_.save(&state);
443}
444
446 ESP_LOGD(TAG, "'%s' >>", this->name_.c_str());
447 auto traits = this->get_traits();
448
449 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
451 ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
452 }
453 if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
454 ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
455 }
456 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
457 ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode_);
458 }
459 if (traits.get_supports_presets() && this->preset.has_value()) {
460 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
461 }
462 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
463 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
464 }
466 ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
467 }
469 ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
470 }
473 ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
475 } else {
476 ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
477 }
479 ESP_LOGD(TAG, " Current Humidity: %.0f%%", this->current_humidity);
480 }
482 ESP_LOGD(TAG, " Target Humidity: %.0f%%", this->target_humidity);
483 }
484
485 // Send state to frontend
486 this->state_callback_.call(*this);
487#if defined(USE_CLIMATE) && defined(USE_CONTROLLER_REGISTRY)
489#endif
490 // Save state
491 this->save_state_();
492}
493
516
517#ifdef USE_CLIMATE_VISUAL_OVERRIDES
518void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
519 this->visual_min_temperature_override_ = visual_min_temperature_override;
520}
521
522void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
523 this->visual_max_temperature_override_ = visual_max_temperature_override;
524}
525
530
531void Climate::set_visual_min_humidity_override(float visual_min_humidity_override) {
532 this->visual_min_humidity_override_ = visual_min_humidity_override;
533}
534
535void Climate::set_visual_max_humidity_override(float visual_max_humidity_override) {
536 this->visual_max_humidity_override_ = visual_max_humidity_override;
537}
538#endif
539
541
543 auto call = climate->make_call();
544 auto traits = climate->get_traits();
545 call.set_mode(this->mode);
546 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
548 call.set_target_temperature_low(this->target_temperature_low);
549 call.set_target_temperature_high(this->target_temperature_high);
550 } else {
551 call.set_target_temperature(this->target_temperature);
552 }
553 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
554 call.set_target_humidity(this->target_humidity);
555 }
556 if (this->uses_custom_fan_mode) {
557 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
558 call.fan_mode_.reset();
559 call.custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
560 }
561 } else if (traits.supports_fan_mode(this->fan_mode)) {
562 call.set_fan_mode(this->fan_mode);
563 }
564 if (this->uses_custom_preset) {
565 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
566 call.preset_.reset();
567 call.custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
568 }
569 } else if (traits.supports_preset(this->preset)) {
570 call.set_preset(this->preset);
571 }
572 if (traits.supports_swing_mode(this->swing_mode)) {
573 call.set_swing_mode(this->swing_mode);
574 }
575 return call;
576}
577
579 auto traits = climate->get_traits();
580 climate->mode = this->mode;
581 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
585 } else {
586 climate->target_temperature = this->target_temperature;
587 }
588 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
589 climate->target_humidity = this->target_humidity;
590 }
591 if (this->uses_custom_fan_mode) {
592 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
593 climate->fan_mode.reset();
594 climate->custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
595 }
596 } else if (traits.supports_fan_mode(this->fan_mode)) {
597 climate->fan_mode = this->fan_mode;
598 climate->clear_custom_fan_mode_();
599 }
600 if (this->uses_custom_preset) {
601 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
602 climate->preset.reset();
603 climate->custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
604 }
605 } else if (traits.supports_preset(this->preset)) {
606 climate->preset = this->preset;
607 climate->clear_custom_preset_();
608 }
609 if (traits.supports_swing_mode(this->swing_mode)) {
610 climate->swing_mode = this->swing_mode;
611 }
612 climate->publish_state();
613}
614
634template<typename T> bool set_primary_mode(optional<T> &primary, const char *&custom_ptr, T value) {
635 // Clear the custom mode (mutual exclusion)
636 bool changed = custom_ptr != nullptr;
637 custom_ptr = nullptr;
638 // Set the primary mode
639 if (changed || !primary.has_value() || primary.value() != value) {
640 primary = value;
641 return true;
642 }
643 return false;
644}
645
667template<typename T>
668bool set_custom_mode(const char *&custom_ptr, optional<T> &primary, const char *found_ptr, bool has_custom) {
669 if (found_ptr != nullptr) {
670 // Clear the primary mode (mutual exclusion)
671 bool changed = primary.has_value();
672 primary.reset();
673 // Set the custom mode (pointer is validated by caller from traits)
674 if (changed || custom_ptr != found_ptr) {
675 custom_ptr = found_ptr;
676 return true;
677 }
678 return false;
679 }
680 // Mode not found in supported modes, clear it if currently set
681 if (has_custom) {
682 custom_ptr = nullptr;
683 return true;
684 }
685 return false;
686}
687
689 return set_primary_mode(this->fan_mode, this->custom_fan_mode_, mode);
690}
691
692bool Climate::set_custom_fan_mode_(const char *mode, size_t len) {
693 auto traits = this->get_traits();
694 return set_custom_mode<ClimateFanMode>(this->custom_fan_mode_, this->fan_mode,
695 traits.find_custom_fan_mode_(mode, len), this->has_custom_fan_mode());
696}
697
698void Climate::clear_custom_fan_mode_() { this->custom_fan_mode_ = nullptr; }
699
700bool Climate::set_preset_(ClimatePreset preset) { return set_primary_mode(this->preset, this->custom_preset_, preset); }
701
702bool Climate::set_custom_preset_(const char *preset, size_t len) {
703 auto traits = this->get_traits();
704 return set_custom_mode<ClimatePreset>(this->custom_preset_, this->preset, traits.find_custom_preset_(preset, len),
705 this->has_custom_preset());
706}
707
708void Climate::clear_custom_preset_() { this->custom_preset_ = nullptr; }
709
711 return this->find_custom_fan_mode_(custom_fan_mode, strlen(custom_fan_mode));
712}
713
714const char *Climate::find_custom_fan_mode_(const char *custom_fan_mode, size_t len) {
715 return this->get_traits().find_custom_fan_mode_(custom_fan_mode, len);
716}
717
719 return this->find_custom_preset_(custom_preset, strlen(custom_preset));
720}
721
722const char *Climate::find_custom_preset_(const char *custom_preset, size_t len) {
723 return this->get_traits().find_custom_preset_(custom_preset, len);
724}
725
726void Climate::dump_traits_(const char *tag) {
727 auto traits = this->get_traits();
728 ESP_LOGCONFIG(tag, "ClimateTraits:");
729 ESP_LOGCONFIG(tag,
730 " Visual settings:\n"
731 " - Min temperature: %.1f\n"
732 " - Max temperature: %.1f\n"
733 " - Temperature step:\n"
734 " Target: %.1f",
738 ESP_LOGCONFIG(tag, " Current: %.1f", traits.get_visual_current_temperature_step());
739 }
742 ESP_LOGCONFIG(tag,
743 " - Min humidity: %.0f\n"
744 " - Max humidity: %.0f",
746 }
749 ESP_LOGCONFIG(tag, " Supports two-point target temperature");
750 }
752 ESP_LOGCONFIG(tag, " Supports current temperature");
753 }
755 ESP_LOGCONFIG(tag, " Supports target humidity");
756 }
758 ESP_LOGCONFIG(tag, " Supports current humidity");
759 }
761 ESP_LOGCONFIG(tag, " Supports action");
762 }
764 ESP_LOGCONFIG(tag, " Supported modes:");
766 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
767 }
769 ESP_LOGCONFIG(tag, " Supported fan modes:");
771 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
772 }
773 if (!traits.get_supported_custom_fan_modes().empty()) {
774 ESP_LOGCONFIG(tag, " Supported custom fan modes:");
775 for (const char *s : traits.get_supported_custom_fan_modes())
776 ESP_LOGCONFIG(tag, " - %s", s);
777 }
779 ESP_LOGCONFIG(tag, " Supported presets:");
781 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
782 }
783 if (!traits.get_supported_custom_presets().empty()) {
784 ESP_LOGCONFIG(tag, " Supported custom presets:");
785 for (const char *s : traits.get_supported_custom_presets())
786 ESP_LOGCONFIG(tag, " - %s", s);
787 }
789 ESP_LOGCONFIG(tag, " Supported swing modes:");
791 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
792 }
793}
794
795} // namespace esphome::climate
BedjetMode mode
BedJet operating mode.
uint8_t m
Definition bl0906.h:1
static void notify_climate_update(climate::Climate *obj)
bool save(const T *src)
Definition preferences.h:21
const StringRef & get_name() const
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
constexpr bool empty() const
Check if the set is empty.
StringRef is a reference to a string owned by something else.
Definition string_ref.h:26
constexpr const char * c_str() const
Definition string_ref.h:73
std::string str() const
Definition string_ref.h:79
This class is used to encode all control actions on a climate device.
Definition climate.h:33
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:314
optional< float > target_temperature_high_
Definition climate.h:129
const optional< float > & get_target_humidity() const
Definition climate.cpp:310
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition climate.cpp:287
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:308
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition climate.cpp:266
optional< ClimateFanMode > fan_mode_
Definition climate.h:132
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition climate.cpp:292
optional< float > target_temperature_
Definition climate.h:127
const optional< float > & get_target_temperature() const
Definition climate.cpp:307
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:315
optional< ClimateSwingMode > swing_mode_
Definition climate.h:133
optional< ClimateMode > mode_
Definition climate.h:131
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition climate.cpp:228
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:309
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:313
optional< float > target_humidity_
Definition climate.h:130
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition climate.cpp:190
optional< ClimatePreset > preset_
Definition climate.h:134
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
Definition climate.cpp:302
optional< float > target_temperature_low_
Definition climate.h:128
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition climate.cpp:297
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition climate.cpp:171
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:312
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:186
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
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:494
float target_temperature
The target temperature of the climate device.
Definition climate.h:247
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:243
float visual_min_humidity_override_
Definition climate.h:346
float visual_target_temperature_step_override_
Definition climate.h:344
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:531
void dump_traits_(const char *tag)
Definition climate.cpp:726
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:272
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:378
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:250
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:535
void add_on_state_callback(std::function< void(Climate &)> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition climate.cpp:359
float visual_current_temperature_step_override_
Definition climate.h:345
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition climate.cpp:700
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.h:298
const char * find_custom_fan_mode_(const char *custom_fan_mode)
Find and return the matching custom fan mode pointer from traits, or nullptr if not found.
Definition climate.cpp:710
float visual_min_temperature_override_
Definition climate.h:342
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:522
void clear_custom_preset_()
Clear custom preset.
Definition climate.cpp:708
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:688
LazyCallbackManager< void(Climate &)> state_callback_
Definition climate.h:338
const char * find_custom_preset_(const char *custom_preset)
Find and return the matching custom preset pointer from traits, or nullptr if not found.
Definition climate.cpp:718
void clear_custom_fan_mode_()
Clear custom fan mode.
Definition climate.cpp:698
void add_on_control_callback(std::function< void(ClimateCall &)> &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
Definition climate.cpp:363
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:240
float visual_max_humidity_override_
Definition climate.h:347
ClimateAction action
The active state of the climate device.
Definition climate.h:269
LazyCallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:339
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:540
float visual_max_temperature_override_
Definition climate.h:343
virtual void control(const ClimateCall &call)=0
Control the climate device, this is a virtual method that each climate integration must implement.
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:445
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:526
ESPPreferenceObject rtc_
Definition climate.h:340
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:263
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:518
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:370
float target_humidity
The target humidity of the climate device.
Definition climate.h:257
bool set_custom_fan_mode_(const char *mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
Definition climate.h:288
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:252
void set_visual_max_temperature(float visual_max_temperature)
const ClimatePresetMask & get_supported_presets() const
const std::vector< const char * > & get_supported_custom_fan_modes() const
const ClimateSwingModeMask & get_supported_swing_modes() const
void set_visual_target_temperature_step(float temperature_step)
float get_visual_current_temperature_step() const
void set_visual_min_temperature(float visual_min_temperature)
const ClimateFanModeMask & get_supported_fan_modes() const
float get_visual_target_temperature_step() const
void set_visual_min_humidity(float visual_min_humidity)
void set_visual_current_temperature_step(float temperature_step)
bool has_feature_flags(uint32_t feature_flags) const
void set_visual_max_humidity(float visual_max_humidity)
const char * find_custom_fan_mode_(const char *custom_fan_mode) const
Find and return the matching custom fan mode pointer from supported modes, or nullptr if not found Th...
const char * find_custom_preset_(const char *custom_preset) const
Find and return the matching custom preset pointer from supported presets, or nullptr if not found Th...
const std::vector< const char * > & get_supported_custom_presets() const
const ClimateModeMask & get_supported_modes() const
bool has_value() const
Definition optional.h:92
value_type const & value() const
Definition optional.h:94
float target_temperature_high
Definition climate.h:3
float target_humidity
Definition climate.h:19
ClimateSwingMode swing_mode
Definition climate.h:11
float target_temperature
Definition climate.h:0
uint8_t custom_preset
Definition climate.h:9
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
float target_temperature_low
Definition climate.h:2
uint8_t custom_fan_mode
Definition climate.h:4
bool state
Definition fan.h:2
const LogString * climate_action_to_string(ClimateAction action)
Convert the given ClimateAction to a human-readable string.
constexpr StringToUint8 CLIMATE_MODES_BY_STR[]
Definition climate.cpp:17
@ CLIMATE_SUPPORTS_CURRENT_HUMIDITY
@ CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.
constexpr StringToUint8 CLIMATE_PRESETS_BY_STR[]
Definition climate.cpp:34
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_AWAY
Device is in away preset.
@ CLIMATE_PRESET_BOOST
Device is in boost preset.
@ CLIMATE_PRESET_ACTIVITY
Device is reacting to activity (e.g., movement sensors)
@ CLIMATE_PRESET_SLEEP
Device is prepared for sleep.
@ CLIMATE_PRESET_HOME
Device is in home preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
constexpr StringToUint8 CLIMATE_FAN_MODES_BY_STR[]
Definition climate.cpp:27
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.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
bool set_primary_mode(optional< T > &primary, const char *&custom_ptr, T value)
Template helper for setting primary modes (fan_mode, preset) with mutual exclusion.
Definition climate.cpp:634
constexpr StringToUint8 CLIMATE_SWING_MODES_BY_STR[]
Definition climate.cpp:40
bool set_custom_mode(const char *&custom_ptr, optional< T > &primary, const char *found_ptr, bool has_custom)
Template helper for setting custom modes (custom_fan_mode_, custom_preset_) with mutual exclusion.
Definition climate.cpp:668
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_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
std::string size_t len
Definition helpers.h:817
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
Definition helpers.cpp:163
Struct used to save the state of the climate device in restore memory.
Definition climate.h:143
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:542
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:578