ESPHome 2026.2.3
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
363 this->rtc_ = this->make_entity_preference<ClimateDeviceRestoreState>(RESTORE_STATE_VERSION);
364 ClimateDeviceRestoreState recovered{};
365 if (!this->rtc_.load(&recovered))
366 return {};
367 return recovered;
368}
369
371#if (defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
372 !defined(CLANG_TIDY)
373#pragma GCC diagnostic ignored "-Wclass-memaccess"
374#define TEMP_IGNORE_MEMACCESS
375#endif
377 // initialize as zero to prevent random data on stack triggering erase
378 memset(&state, 0, sizeof(ClimateDeviceRestoreState));
379#ifdef TEMP_IGNORE_MEMACCESS
380#pragma GCC diagnostic pop
381#undef TEMP_IGNORE_MEMACCESS
382#endif
383
384 state.mode = this->mode;
385 auto traits = this->get_traits();
388 state.target_temperature_low = this->target_temperature_low;
389 state.target_temperature_high = this->target_temperature_high;
390 } else {
391 state.target_temperature = this->target_temperature;
392 }
394 state.target_humidity = this->target_humidity;
395 }
397 state.uses_custom_fan_mode = false;
398 state.fan_mode = this->fan_mode.value();
399 }
400 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
401 state.uses_custom_fan_mode = true;
402 const auto &supported = traits.get_supported_custom_fan_modes();
403 // std::vector maintains insertion order
404 size_t i = 0;
405 for (const char *mode : supported) {
406 if (strcmp(mode, this->custom_fan_mode_) == 0) {
407 state.custom_fan_mode = i;
408 break;
409 }
410 i++;
411 }
412 }
414 state.uses_custom_preset = false;
415 state.preset = this->preset.value();
416 }
417 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
418 state.uses_custom_preset = true;
419 const auto &supported = traits.get_supported_custom_presets();
420 // std::vector maintains insertion order
421 size_t i = 0;
422 for (const char *preset : supported) {
423 if (strcmp(preset, this->custom_preset_) == 0) {
424 state.custom_preset = i;
425 break;
426 }
427 i++;
428 }
429 }
431 state.swing_mode = this->swing_mode;
432 }
433
434 this->rtc_.save(&state);
435}
436
438 ESP_LOGD(TAG, "'%s' >>", this->name_.c_str());
439 auto traits = this->get_traits();
440
441 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
443 ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
444 }
445 if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
446 ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
447 }
448 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
449 ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode_);
450 }
451 if (traits.get_supports_presets() && this->preset.has_value()) {
452 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
453 }
454 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
455 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
456 }
458 ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
459 }
461 ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
462 }
465 ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
467 } else {
468 ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
469 }
471 ESP_LOGD(TAG, " Current Humidity: %.0f%%", this->current_humidity);
472 }
474 ESP_LOGD(TAG, " Target Humidity: %.0f%%", this->target_humidity);
475 }
476
477 // Send state to frontend
478 this->state_callback_.call(*this);
479#if defined(USE_CLIMATE) && defined(USE_CONTROLLER_REGISTRY)
481#endif
482 // Save state
483 this->save_state_();
484}
485
508
509#ifdef USE_CLIMATE_VISUAL_OVERRIDES
510void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
511 this->visual_min_temperature_override_ = visual_min_temperature_override;
512}
513
514void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
515 this->visual_max_temperature_override_ = visual_max_temperature_override;
516}
517
522
523void Climate::set_visual_min_humidity_override(float visual_min_humidity_override) {
524 this->visual_min_humidity_override_ = visual_min_humidity_override;
525}
526
527void Climate::set_visual_max_humidity_override(float visual_max_humidity_override) {
528 this->visual_max_humidity_override_ = visual_max_humidity_override;
529}
530#endif
531
533
535 auto call = climate->make_call();
536 auto traits = climate->get_traits();
537 call.set_mode(this->mode);
538 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
540 call.set_target_temperature_low(this->target_temperature_low);
541 call.set_target_temperature_high(this->target_temperature_high);
542 } else {
543 call.set_target_temperature(this->target_temperature);
544 }
545 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
546 call.set_target_humidity(this->target_humidity);
547 }
548 if (this->uses_custom_fan_mode) {
549 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
550 call.fan_mode_.reset();
551 call.custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
552 }
553 } else if (traits.supports_fan_mode(this->fan_mode)) {
554 call.set_fan_mode(this->fan_mode);
555 }
556 if (this->uses_custom_preset) {
557 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
558 call.preset_.reset();
559 call.custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
560 }
561 } else if (traits.supports_preset(this->preset)) {
562 call.set_preset(this->preset);
563 }
564 if (traits.supports_swing_mode(this->swing_mode)) {
565 call.set_swing_mode(this->swing_mode);
566 }
567 return call;
568}
569
571 auto traits = climate->get_traits();
572 climate->mode = this->mode;
573 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
577 } else {
578 climate->target_temperature = this->target_temperature;
579 }
580 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
581 climate->target_humidity = this->target_humidity;
582 }
583 if (this->uses_custom_fan_mode) {
584 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
585 climate->fan_mode.reset();
586 climate->custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
587 }
588 } else if (traits.supports_fan_mode(this->fan_mode)) {
589 climate->fan_mode = this->fan_mode;
590 climate->clear_custom_fan_mode_();
591 }
592 if (this->uses_custom_preset) {
593 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
594 climate->preset.reset();
595 climate->custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
596 }
597 } else if (traits.supports_preset(this->preset)) {
598 climate->preset = this->preset;
599 climate->clear_custom_preset_();
600 }
601 if (traits.supports_swing_mode(this->swing_mode)) {
602 climate->swing_mode = this->swing_mode;
603 }
604 climate->publish_state();
605}
606
626template<typename T> bool set_primary_mode(optional<T> &primary, const char *&custom_ptr, T value) {
627 // Clear the custom mode (mutual exclusion)
628 bool changed = custom_ptr != nullptr;
629 custom_ptr = nullptr;
630 // Set the primary mode
631 if (changed || !primary.has_value() || primary.value() != value) {
632 primary = value;
633 return true;
634 }
635 return false;
636}
637
659template<typename T>
660bool set_custom_mode(const char *&custom_ptr, optional<T> &primary, const char *found_ptr, bool has_custom) {
661 if (found_ptr != nullptr) {
662 // Clear the primary mode (mutual exclusion)
663 bool changed = primary.has_value();
664 primary.reset();
665 // Set the custom mode (pointer is validated by caller from traits)
666 if (changed || custom_ptr != found_ptr) {
667 custom_ptr = found_ptr;
668 return true;
669 }
670 return false;
671 }
672 // Mode not found in supported modes, clear it if currently set
673 if (has_custom) {
674 custom_ptr = nullptr;
675 return true;
676 }
677 return false;
678}
679
681 return set_primary_mode(this->fan_mode, this->custom_fan_mode_, mode);
682}
683
684bool Climate::set_custom_fan_mode_(const char *mode, size_t len) {
685 auto traits = this->get_traits();
686 return set_custom_mode<ClimateFanMode>(this->custom_fan_mode_, this->fan_mode,
687 traits.find_custom_fan_mode_(mode, len), this->has_custom_fan_mode());
688}
689
690void Climate::clear_custom_fan_mode_() { this->custom_fan_mode_ = nullptr; }
691
692bool Climate::set_preset_(ClimatePreset preset) { return set_primary_mode(this->preset, this->custom_preset_, preset); }
693
694bool Climate::set_custom_preset_(const char *preset, size_t len) {
695 auto traits = this->get_traits();
696 return set_custom_mode<ClimatePreset>(this->custom_preset_, this->preset, traits.find_custom_preset_(preset, len),
697 this->has_custom_preset());
698}
699
700void Climate::clear_custom_preset_() { this->custom_preset_ = nullptr; }
701
703 return this->find_custom_fan_mode_(custom_fan_mode, strlen(custom_fan_mode));
704}
705
706const char *Climate::find_custom_fan_mode_(const char *custom_fan_mode, size_t len) {
707 return this->get_traits().find_custom_fan_mode_(custom_fan_mode, len);
708}
709
711 return this->find_custom_preset_(custom_preset, strlen(custom_preset));
712}
713
714const char *Climate::find_custom_preset_(const char *custom_preset, size_t len) {
715 return this->get_traits().find_custom_preset_(custom_preset, len);
716}
717
718void Climate::dump_traits_(const char *tag) {
719 auto traits = this->get_traits();
720 ESP_LOGCONFIG(tag, "ClimateTraits:");
721 ESP_LOGCONFIG(tag,
722 " Visual settings:\n"
723 " - Min temperature: %.1f\n"
724 " - Max temperature: %.1f\n"
725 " - Temperature step:\n"
726 " Target: %.1f",
730 ESP_LOGCONFIG(tag, " Current: %.1f", traits.get_visual_current_temperature_step());
731 }
734 ESP_LOGCONFIG(tag,
735 " - Min humidity: %.0f\n"
736 " - Max humidity: %.0f",
738 }
741 ESP_LOGCONFIG(tag, " Supports two-point target temperature");
742 }
744 ESP_LOGCONFIG(tag, " Supports current temperature");
745 }
747 ESP_LOGCONFIG(tag, " Supports target humidity");
748 }
750 ESP_LOGCONFIG(tag, " Supports current humidity");
751 }
753 ESP_LOGCONFIG(tag, " Supports action");
754 }
756 ESP_LOGCONFIG(tag, " Supported modes:");
758 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
759 }
761 ESP_LOGCONFIG(tag, " Supported fan modes:");
763 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
764 }
765 if (!traits.get_supported_custom_fan_modes().empty()) {
766 ESP_LOGCONFIG(tag, " Supported custom fan modes:");
767 for (const char *s : traits.get_supported_custom_fan_modes())
768 ESP_LOGCONFIG(tag, " - %s", s);
769 }
771 ESP_LOGCONFIG(tag, " Supported presets:");
773 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
774 }
775 if (!traits.get_supported_custom_presets().empty()) {
776 ESP_LOGCONFIG(tag, " Supported custom presets:");
777 for (const char *s : traits.get_supported_custom_presets())
778 ESP_LOGCONFIG(tag, " - %s", s);
779 }
781 ESP_LOGCONFIG(tag, " Supported swing modes:");
783 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
784 }
785}
786
787} // 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.
constexpr const char * c_str() const
Definition string_ref.h:73
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:306
optional< float > target_temperature_high_
Definition climate.h:125
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:128
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:123
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:129
optional< ClimateMode > mode_
Definition climate.h:127
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:126
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:130
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:124
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:182
ClimateMode mode
The active mode of the climate device.
Definition climate.h:262
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:256
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:486
float target_temperature
The target temperature of the climate device.
Definition climate.h:243
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:239
float visual_min_humidity_override_
Definition climate.h:342
float visual_target_temperature_step_override_
Definition climate.h:340
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:523
void dump_traits_(const char *tag)
Definition climate.cpp:718
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:268
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:370
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:246
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:527
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:341
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:692
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.h:294
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:702
float visual_min_temperature_override_
Definition climate.h:338
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:514
void clear_custom_preset_()
Clear custom preset.
Definition climate.cpp:700
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:680
LazyCallbackManager< void(Climate &)> state_callback_
Definition climate.h:334
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:710
void clear_custom_fan_mode_()
Clear custom fan mode.
Definition climate.cpp:690
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:236
float visual_max_humidity_override_
Definition climate.h:343
ClimateAction action
The active state of the climate device.
Definition climate.h:265
LazyCallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:335
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:532
float visual_max_temperature_override_
Definition climate.h:339
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:437
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:518
ESPPreferenceObject rtc_
Definition climate.h:336
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:259
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:510
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:253
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:284
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:248
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:626
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:660
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:692
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:139
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:534
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:570