ESPHome 2026.1.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
177 for (const auto &mode_entry : CLIMATE_MODES_BY_STR) {
178 if (str_equals_case_insensitive(mode, mode_entry.str)) {
179 this->set_mode(static_cast<ClimateMode>(mode_entry.value));
180 return *this;
181 }
182 }
183 ESP_LOGW(TAG, "'%s' - Unrecognized mode %s", this->parent_->get_name().c_str(), mode.c_str());
184 return *this;
185}
186
188 this->fan_mode_ = fan_mode;
189 this->custom_fan_mode_ = nullptr;
190 return *this;
191}
192
194 return this->set_fan_mode(custom_fan_mode, strlen(custom_fan_mode));
195}
196
198 return this->set_fan_mode(fan_mode.data(), fan_mode.size());
199}
200
202 // Check if it's a standard enum mode first
203 for (const auto &mode_entry : CLIMATE_FAN_MODES_BY_STR) {
204 if (strncasecmp(custom_fan_mode, mode_entry.str, len) == 0 && mode_entry.str[len] == '\0') {
205 return this->set_fan_mode(static_cast<ClimateFanMode>(mode_entry.value));
206 }
207 }
208 // Find the matching pointer from parent climate device
209 if (const char *mode_ptr = this->parent_->find_custom_fan_mode_(custom_fan_mode, len)) {
210 this->custom_fan_mode_ = mode_ptr;
211 this->fan_mode_.reset();
212 return *this;
213 }
214 ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %.*s", this->parent_->get_name().c_str(), (int) len, custom_fan_mode);
215 return *this;
216}
217
219 if (fan_mode.has_value()) {
220 this->set_fan_mode(fan_mode.value());
221 }
222 return *this;
223}
224
226 this->preset_ = preset;
227 this->custom_preset_ = nullptr;
228 return *this;
229}
230
232 return this->set_preset(custom_preset, strlen(custom_preset));
233}
234
236 return this->set_preset(preset.data(), preset.size());
237}
238
240 // Check if it's a standard enum preset first
241 for (const auto &preset_entry : CLIMATE_PRESETS_BY_STR) {
242 if (strncasecmp(custom_preset, preset_entry.str, len) == 0 && preset_entry.str[len] == '\0') {
243 return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
244 }
245 }
246 // Find the matching pointer from parent climate device
247 if (const char *preset_ptr = this->parent_->find_custom_preset_(custom_preset, len)) {
248 this->custom_preset_ = preset_ptr;
249 this->preset_.reset();
250 return *this;
251 }
252 ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", this->parent_->get_name().c_str(), (int) len, custom_preset);
253 return *this;
254}
255
257 if (preset.has_value()) {
258 this->set_preset(preset.value());
259 }
260 return *this;
261}
262
267
269 for (const auto &mode_entry : CLIMATE_SWING_MODES_BY_STR) {
270 if (str_equals_case_insensitive(swing_mode, mode_entry.str)) {
271 this->set_swing_mode(static_cast<ClimateSwingMode>(mode_entry.value));
272 return *this;
273 }
274 }
275 ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %s", this->parent_->get_name().c_str(), swing_mode.c_str());
276 return *this;
277}
278
283
288
293
298
303
304const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
308
313
318
323
328
333
335 this->fan_mode_ = fan_mode;
336 this->custom_fan_mode_ = nullptr;
337 return *this;
338}
339
341 this->preset_ = preset;
342 this->custom_preset_ = nullptr;
343 return *this;
344}
345
350
351void Climate::add_on_state_callback(std::function<void(Climate &)> &&callback) {
352 this->state_callback_.add(std::move(callback));
353}
354
355void Climate::add_on_control_callback(std::function<void(ClimateCall &)> &&callback) {
356 this->control_callback_.add(std::move(callback));
357}
358
359// Random 32bit value; If this changes existing restore preferences are invalidated
360static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
361
364 RESTORE_STATE_VERSION);
365 ClimateDeviceRestoreState recovered{};
366 if (!this->rtc_.load(&recovered))
367 return {};
368 return recovered;
369}
370
372#if (defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
373 !defined(CLANG_TIDY)
374#pragma GCC diagnostic ignored "-Wclass-memaccess"
375#define TEMP_IGNORE_MEMACCESS
376#endif
378 // initialize as zero to prevent random data on stack triggering erase
379 memset(&state, 0, sizeof(ClimateDeviceRestoreState));
380#ifdef TEMP_IGNORE_MEMACCESS
381#pragma GCC diagnostic pop
382#undef TEMP_IGNORE_MEMACCESS
383#endif
384
385 state.mode = this->mode;
386 auto traits = this->get_traits();
389 state.target_temperature_low = this->target_temperature_low;
390 state.target_temperature_high = this->target_temperature_high;
391 } else {
392 state.target_temperature = this->target_temperature;
393 }
395 state.target_humidity = this->target_humidity;
396 }
398 state.uses_custom_fan_mode = false;
399 state.fan_mode = this->fan_mode.value();
400 }
401 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
402 state.uses_custom_fan_mode = true;
403 const auto &supported = traits.get_supported_custom_fan_modes();
404 // std::vector maintains insertion order
405 size_t i = 0;
406 for (const char *mode : supported) {
407 if (strcmp(mode, this->custom_fan_mode_) == 0) {
408 state.custom_fan_mode = i;
409 break;
410 }
411 i++;
412 }
413 }
415 state.uses_custom_preset = false;
416 state.preset = this->preset.value();
417 }
418 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
419 state.uses_custom_preset = true;
420 const auto &supported = traits.get_supported_custom_presets();
421 // std::vector maintains insertion order
422 size_t i = 0;
423 for (const char *preset : supported) {
424 if (strcmp(preset, this->custom_preset_) == 0) {
425 state.custom_preset = i;
426 break;
427 }
428 i++;
429 }
430 }
432 state.swing_mode = this->swing_mode;
433 }
434
435 this->rtc_.save(&state);
436}
437
439 ESP_LOGD(TAG, "'%s' - Sending state:", this->name_.c_str());
440 auto traits = this->get_traits();
441
442 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
444 ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
445 }
446 if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
447 ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
448 }
449 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
450 ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode_);
451 }
452 if (traits.get_supports_presets() && this->preset.has_value()) {
453 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
454 }
455 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
456 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
457 }
459 ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
460 }
462 ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
463 }
466 ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
468 } else {
469 ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
470 }
472 ESP_LOGD(TAG, " Current Humidity: %.0f%%", this->current_humidity);
473 }
475 ESP_LOGD(TAG, " Target Humidity: %.0f%%", this->target_humidity);
476 }
477
478 // Send state to frontend
479 this->state_callback_.call(*this);
480#if defined(USE_CLIMATE) && defined(USE_CONTROLLER_REGISTRY)
482#endif
483 // Save state
484 this->save_state_();
485}
486
509
510#ifdef USE_CLIMATE_VISUAL_OVERRIDES
511void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
512 this->visual_min_temperature_override_ = visual_min_temperature_override;
513}
514
515void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
516 this->visual_max_temperature_override_ = visual_max_temperature_override;
517}
518
523
524void Climate::set_visual_min_humidity_override(float visual_min_humidity_override) {
525 this->visual_min_humidity_override_ = visual_min_humidity_override;
526}
527
528void Climate::set_visual_max_humidity_override(float visual_max_humidity_override) {
529 this->visual_max_humidity_override_ = visual_max_humidity_override;
530}
531#endif
532
534
536 auto call = climate->make_call();
537 auto traits = climate->get_traits();
538 call.set_mode(this->mode);
539 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
541 call.set_target_temperature_low(this->target_temperature_low);
542 call.set_target_temperature_high(this->target_temperature_high);
543 } else {
544 call.set_target_temperature(this->target_temperature);
545 }
546 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
547 call.set_target_humidity(this->target_humidity);
548 }
549 if (this->uses_custom_fan_mode) {
550 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
551 call.fan_mode_.reset();
552 call.custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
553 }
554 } else if (traits.supports_fan_mode(this->fan_mode)) {
555 call.set_fan_mode(this->fan_mode);
556 }
557 if (this->uses_custom_preset) {
558 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
559 call.preset_.reset();
560 call.custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
561 }
562 } else if (traits.supports_preset(this->preset)) {
563 call.set_preset(this->preset);
564 }
565 if (traits.supports_swing_mode(this->swing_mode)) {
566 call.set_swing_mode(this->swing_mode);
567 }
568 return call;
569}
570
572 auto traits = climate->get_traits();
573 climate->mode = this->mode;
574 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
578 } else {
579 climate->target_temperature = this->target_temperature;
580 }
581 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
582 climate->target_humidity = this->target_humidity;
583 }
584 if (this->uses_custom_fan_mode) {
585 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
586 climate->fan_mode.reset();
587 climate->custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
588 }
589 } else if (traits.supports_fan_mode(this->fan_mode)) {
590 climate->fan_mode = this->fan_mode;
591 climate->clear_custom_fan_mode_();
592 }
593 if (this->uses_custom_preset) {
594 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
595 climate->preset.reset();
596 climate->custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
597 }
598 } else if (traits.supports_preset(this->preset)) {
599 climate->preset = this->preset;
600 climate->clear_custom_preset_();
601 }
602 if (traits.supports_swing_mode(this->swing_mode)) {
603 climate->swing_mode = this->swing_mode;
604 }
605 climate->publish_state();
606}
607
627template<typename T> bool set_primary_mode(optional<T> &primary, const char *&custom_ptr, T value) {
628 // Clear the custom mode (mutual exclusion)
629 bool changed = custom_ptr != nullptr;
630 custom_ptr = nullptr;
631 // Set the primary mode
632 if (changed || !primary.has_value() || primary.value() != value) {
633 primary = value;
634 return true;
635 }
636 return false;
637}
638
660template<typename T>
661bool set_custom_mode(const char *&custom_ptr, optional<T> &primary, const char *found_ptr, bool has_custom) {
662 if (found_ptr != nullptr) {
663 // Clear the primary mode (mutual exclusion)
664 bool changed = primary.has_value();
665 primary.reset();
666 // Set the custom mode (pointer is validated by caller from traits)
667 if (changed || custom_ptr != found_ptr) {
668 custom_ptr = found_ptr;
669 return true;
670 }
671 return false;
672 }
673 // Mode not found in supported modes, clear it if currently set
674 if (has_custom) {
675 custom_ptr = nullptr;
676 return true;
677 }
678 return false;
679}
680
682 return set_primary_mode(this->fan_mode, this->custom_fan_mode_, mode);
683}
684
686 auto traits = this->get_traits();
687 return set_custom_mode<ClimateFanMode>(this->custom_fan_mode_, this->fan_mode, traits.find_custom_fan_mode_(mode),
688 this->has_custom_fan_mode());
689}
690
691void Climate::clear_custom_fan_mode_() { this->custom_fan_mode_ = nullptr; }
692
693bool Climate::set_preset_(ClimatePreset preset) { return set_primary_mode(this->preset, this->custom_preset_, preset); }
694
696 auto traits = this->get_traits();
697 return set_custom_mode<ClimatePreset>(this->custom_preset_, this->preset, traits.find_custom_preset_(preset),
698 this->has_custom_preset());
699}
700
701void Climate::clear_custom_preset_() { this->custom_preset_ = nullptr; }
702
704 return this->find_custom_fan_mode_(custom_fan_mode, strlen(custom_fan_mode));
705}
706
707const char *Climate::find_custom_fan_mode_(const char *custom_fan_mode, size_t len) {
708 return this->get_traits().find_custom_fan_mode_(custom_fan_mode, len);
709}
710
712 return this->find_custom_preset_(custom_preset, strlen(custom_preset));
713}
714
715const char *Climate::find_custom_preset_(const char *custom_preset, size_t len) {
716 return this->get_traits().find_custom_preset_(custom_preset, len);
717}
718
719void Climate::dump_traits_(const char *tag) {
720 auto traits = this->get_traits();
721 ESP_LOGCONFIG(tag, "ClimateTraits:");
722 ESP_LOGCONFIG(tag,
723 " Visual settings:\n"
724 " - Min temperature: %.1f\n"
725 " - Max temperature: %.1f\n"
726 " - Temperature step:\n"
727 " Target: %.1f",
731 ESP_LOGCONFIG(tag, " Current: %.1f", traits.get_visual_current_temperature_step());
732 }
735 ESP_LOGCONFIG(tag,
736 " - Min humidity: %.0f\n"
737 " - Max humidity: %.0f",
739 }
742 ESP_LOGCONFIG(tag, " Supports two-point target temperature");
743 }
745 ESP_LOGCONFIG(tag, " Supports current temperature");
746 }
748 ESP_LOGCONFIG(tag, " Supports target humidity");
749 }
751 ESP_LOGCONFIG(tag, " Supports current humidity");
752 }
754 ESP_LOGCONFIG(tag, " Supports action");
755 }
757 ESP_LOGCONFIG(tag, " Supported modes:");
759 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
760 }
762 ESP_LOGCONFIG(tag, " Supported fan modes:");
764 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
765 }
766 if (!traits.get_supported_custom_fan_modes().empty()) {
767 ESP_LOGCONFIG(tag, " Supported custom fan modes:");
768 for (const char *s : traits.get_supported_custom_fan_modes())
769 ESP_LOGCONFIG(tag, " - %s", s);
770 }
772 ESP_LOGCONFIG(tag, " Supported presets:");
774 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
775 }
776 if (!traits.get_supported_custom_presets().empty()) {
777 ESP_LOGCONFIG(tag, " Supported custom presets:");
778 for (const char *s : traits.get_supported_custom_presets())
779 ESP_LOGCONFIG(tag, " - %s", s);
780 }
782 ESP_LOGCONFIG(tag, " Supported swing modes:");
784 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
785 }
786}
787
788} // 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
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
const StringRef & get_name() const
uint32_t get_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
constexpr bool empty() const
Check if the set is empty.
constexpr const char * c_str() const
Definition string_ref.h:69
This class is used to encode all control actions on a climate device.
Definition climate.h:32
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:306
optional< float > target_temperature_high_
Definition climate.h:124
const optional< float > & get_target_humidity() const
Definition climate.cpp:302
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition climate.cpp:279
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:300
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition climate.cpp:263
optional< ClimateFanMode > fan_mode_
Definition climate.h:127
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition climate.cpp:284
optional< float > target_temperature_
Definition climate.h:122
const optional< float > & get_target_temperature() const
Definition climate.cpp:299
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:307
optional< ClimateSwingMode > swing_mode_
Definition climate.h:128
optional< ClimateMode > mode_
Definition climate.h:126
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition climate.cpp:225
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:301
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:305
optional< float > target_humidity_
Definition climate.h:125
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition climate.cpp:187
optional< ClimatePreset > preset_
Definition climate.h:129
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
Definition climate.cpp:294
optional< float > target_temperature_low_
Definition climate.h:123
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition climate.cpp:289
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:304
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:181
ClimateMode mode
The active mode of the climate device.
Definition climate.h:261
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:255
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:487
float target_temperature
The target temperature of the climate device.
Definition climate.h:242
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:238
float visual_min_humidity_override_
Definition climate.h:337
float visual_target_temperature_step_override_
Definition climate.h:335
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:524
void dump_traits_(const char *tag)
Definition climate.cpp:719
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:267
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:371
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:245
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:528
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:351
float visual_current_temperature_step_override_
Definition climate.h:336
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:693
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.cpp:695
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:703
float visual_min_temperature_override_
Definition climate.h:333
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:515
void clear_custom_preset_()
Clear custom preset.
Definition climate.cpp:701
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:681
LazyCallbackManager< void(Climate &)> state_callback_
Definition climate.h:329
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:711
void clear_custom_fan_mode_()
Clear custom fan mode.
Definition climate.cpp:691
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:355
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:235
float visual_max_humidity_override_
Definition climate.h:338
ClimateAction action
The active state of the climate device.
Definition climate.h:264
LazyCallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:330
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:533
float visual_max_temperature_override_
Definition climate.h:334
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:438
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:519
ESPPreferenceObject rtc_
Definition climate.h:331
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:258
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:511
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:362
float target_humidity
The target humidity of the climate device.
Definition climate.h:252
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.cpp:685
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:247
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:0
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:627
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:661
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:533
ESPPreferences * global_preferences
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
Definition helpers.cpp:162
Struct used to save the state of the climate device in restore memory.
Definition climate.h:138
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:535
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:571