ESPHome  2024.3.2
thermostat_climate.cpp
Go to the documentation of this file.
1 #include "thermostat_climate.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace thermostat {
6 
7 static const char *const TAG = "thermostat.climate";
8 
10  if (this->use_startup_delay_) {
11  // start timers so that no actions are called for a moment
17  }
18  // add a callback so that whenever the sensor state changes we can take action
19  this->sensor_->add_on_state_callback([this](float state) {
20  this->current_temperature = state;
21  // required action may have changed, recompute, refresh, we'll publish_state() later
22  this->switch_to_action_(this->compute_action_(), false);
24  // current temperature and possibly action changed, so publish the new state
25  this->publish_state();
26  });
27  this->current_temperature = this->sensor_->state;
28 
29  // register for humidity values and get initial state
30  if (this->humidity_sensor_ != nullptr) {
31  this->humidity_sensor_->add_on_state_callback([this](float state) {
32  this->current_humidity = state;
33  this->publish_state();
34  });
36  }
37 
38  auto use_default_preset = true;
39 
41  // restore all climate data, if possible
42  auto restore = this->restore_state_();
43  if (restore.has_value()) {
44  use_default_preset = false;
45  restore->to_call(this).perform();
46  }
47  }
48 
49  // Either we failed to restore state or the user has requested we always apply the default preset
50  if (use_default_preset) {
52  this->change_preset_(this->default_preset_);
53  } else if (!this->default_custom_preset_.empty()) {
55  }
56  }
57 
58  // refresh the climate action based on the restored settings, we'll publish_state() later
59  this->switch_to_action_(this->compute_action_(), false);
61  this->setup_complete_ = true;
62  this->publish_state();
63 }
64 
66  for (auto &timer : this->timer_) {
67  if (timer.active && (timer.started + timer.time < millis())) {
68  timer.active = false;
69  timer.func();
70  }
71  }
72 }
73 
78 
80  this->switch_to_mode_(this->mode, false);
81  this->switch_to_action_(this->compute_action_(), false);
83  this->switch_to_fan_mode_(this->fan_mode.value(), false);
84  this->switch_to_swing_mode_(this->swing_mode, false);
86  this->publish_state();
87 }
88 
90  bool state_mismatch = this->action != this->compute_action_(true);
91 
92  switch (this->compute_action_(true)) {
95  return state_mismatch && (!this->idle_action_ready_());
97  return state_mismatch && (!this->cooling_action_ready_());
99  return state_mismatch && (!this->heating_action_ready_());
101  return state_mismatch && (!this->fanning_action_ready_());
103  return state_mismatch && (!this->drying_action_ready_());
104  default:
105  break;
106  }
107  return false;
108 }
109 
111  bool state_mismatch = this->fan_mode.value_or(climate::CLIMATE_FAN_ON) != this->prev_fan_mode_;
112  return state_mismatch && (!this->fan_mode_ready_());
113 }
114 
116 
118 
120  if ((this->supports_cool_ || (this->supports_fan_only_ && this->supports_fan_only_cooling_)) &&
121  (std::isnan(this->cooling_deadband_) || std::isnan(this->cooling_overrun_)))
122  return false;
123 
124  if (this->supports_heat_ && (std::isnan(this->heating_deadband_) || std::isnan(this->heating_overrun_)))
125  return false;
126 
127  return true;
128 }
129 
131  if (std::isnan(this->target_temperature)) {
132  this->target_temperature =
135  } else {
136  // target_temperature must be between the visual minimum and the visual maximum
137  if (this->target_temperature < this->get_traits().get_visual_min_temperature())
139  if (this->target_temperature > this->get_traits().get_visual_max_temperature())
141  }
142 }
143 
145  if (this->supports_two_points_) {
148  } else {
150  }
151 }
152 
154  if (std::isnan(this->target_temperature_low)) {
156  } else {
157  // target_temperature_low must not be lower than the visual minimum
158  if (this->target_temperature_low < this->get_traits().get_visual_min_temperature())
160  // target_temperature_low must not be greater than the visual maximum minus set_point_minimum_differential_
161  if (this->target_temperature_low >
162  this->get_traits().get_visual_max_temperature() - this->set_point_minimum_differential_) {
163  this->target_temperature_low =
165  }
166  // if target_temperature_low is set greater than target_temperature_high, move up target_temperature_high
169  }
170 }
171 
173  if (std::isnan(this->target_temperature_high)) {
175  } else {
176  // target_temperature_high must not be lower than the visual maximum
177  if (this->target_temperature_high > this->get_traits().get_visual_max_temperature())
179  // target_temperature_high must not be lower than the visual minimum plus set_point_minimum_differential_
180  if (this->target_temperature_high <
181  this->get_traits().get_visual_min_temperature() + this->set_point_minimum_differential_) {
184  }
185  // if target_temperature_high is set less than target_temperature_low, move down target_temperature_low
186  if (this->target_temperature_high < this->target_temperature_low + this->set_point_minimum_differential_)
188  }
189 }
190 
192  if (call.get_preset().has_value()) {
193  // setup_complete_ blocks modifying/resetting the temps immediately after boot
194  if (this->setup_complete_) {
195  this->change_preset_(*call.get_preset());
196  } else {
197  this->preset = *call.get_preset();
198  }
199  }
200  if (call.get_custom_preset().has_value()) {
201  // setup_complete_ blocks modifying/resetting the temps immediately after boot
202  if (this->setup_complete_) {
204  } else {
205  this->custom_preset = *call.get_custom_preset();
206  }
207  }
208 
209  if (call.get_mode().has_value())
210  this->mode = *call.get_mode();
211  if (call.get_fan_mode().has_value())
212  this->fan_mode = *call.get_fan_mode();
213  if (call.get_swing_mode().has_value())
214  this->swing_mode = *call.get_swing_mode();
215  if (this->supports_two_points_) {
216  if (call.get_target_temperature_low().has_value()) {
219  }
220  if (call.get_target_temperature_high().has_value()) {
223  }
224  } else {
225  if (call.get_target_temperature().has_value()) {
228  }
229  }
230  // make any changes happen
231  refresh();
232 }
233 
237  if (this->humidity_sensor_ != nullptr)
239 
240  if (supports_auto_)
244  if (supports_cool_)
246  if (supports_dry_)
248  if (supports_fan_only_)
250  if (supports_heat_)
252 
273 
282 
283  for (auto &it : this->preset_config_) {
284  traits.add_supported_preset(it.first);
285  }
286  for (auto &it : this->custom_preset_config_) {
288  }
289 
292  return traits;
293 }
294 
296  auto target_action = climate::CLIMATE_ACTION_IDLE;
297  // if any hysteresis values or current_temperature is not valid, we go to OFF;
298  if (std::isnan(this->current_temperature) || !this->hysteresis_valid()) {
300  }
301  // do not change the action if an "ON" timer is running
302  if ((!ignore_timers) &&
305  return this->action;
306  }
307 
308  // ensure set point(s) is/are valid before computing the action
310  // everything has been validated so we can now safely compute the action
311  switch (this->mode) {
312  // if the climate mode is OFF then the climate action must be OFF
314  target_action = climate::CLIMATE_ACTION_OFF;
315  break;
317  if (this->fanning_required_())
318  target_action = climate::CLIMATE_ACTION_FAN;
319  break;
321  target_action = climate::CLIMATE_ACTION_DRYING;
322  break;
324  if (this->cooling_required_() && this->heating_required_()) {
325  // this is bad and should never happen, so just stop.
326  // target_action = climate::CLIMATE_ACTION_IDLE;
327  } else if (this->cooling_required_()) {
328  target_action = climate::CLIMATE_ACTION_COOLING;
329  } else if (this->heating_required_()) {
330  target_action = climate::CLIMATE_ACTION_HEATING;
331  }
332  break;
334  if (this->cooling_required_()) {
335  target_action = climate::CLIMATE_ACTION_COOLING;
336  }
337  break;
339  if (this->heating_required_()) {
340  target_action = climate::CLIMATE_ACTION_HEATING;
341  }
342  break;
343  default:
344  break;
345  }
346  // do not abruptly switch actions. cycle through IDLE, first. we'll catch this at the next update.
348  (target_action == climate::CLIMATE_ACTION_HEATING)) ||
350  ((target_action == climate::CLIMATE_ACTION_COOLING) || (target_action == climate::CLIMATE_ACTION_DRYING)))) {
352  }
353 
354  return target_action;
355 }
356 
358  auto target_action = climate::CLIMATE_ACTION_IDLE;
359  // if any hysteresis values or current_temperature is not valid, we go to OFF;
360  if (std::isnan(this->current_temperature) || !this->hysteresis_valid()) {
362  }
363 
364  // ensure set point(s) is/are valid before computing the action
366  // everything has been validated so we can now safely compute the action
367  switch (this->mode) {
368  // if the climate mode is OFF then the climate action must be OFF
370  target_action = climate::CLIMATE_ACTION_OFF;
371  break;
374  // this is bad and should never happen, so just stop.
375  // target_action = climate::CLIMATE_ACTION_IDLE;
376  } else if (this->supplemental_cooling_required_()) {
377  target_action = climate::CLIMATE_ACTION_COOLING;
378  } else if (this->supplemental_heating_required_()) {
379  target_action = climate::CLIMATE_ACTION_HEATING;
380  }
381  break;
383  if (this->supplemental_cooling_required_()) {
384  target_action = climate::CLIMATE_ACTION_COOLING;
385  }
386  break;
388  if (this->supplemental_heating_required_()) {
389  target_action = climate::CLIMATE_ACTION_HEATING;
390  }
391  break;
392  default:
393  break;
394  }
395 
396  return target_action;
397 }
398 
400  // setup_complete_ helps us ensure an action is called immediately after boot
401  if ((action == this->action) && this->setup_complete_) {
402  // already in target mode
403  return;
404  }
405 
406  if (((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) ||
407  (action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) &&
408  this->setup_complete_) {
409  // switching from OFF to IDLE or vice-versa -- this is only a visual difference.
410  // OFF means user manually disabled, IDLE means the temperature is in target range.
411  this->action = action;
412  if (publish_state)
413  this->publish_state();
414  return;
415  }
416 
417  bool action_ready = false;
418  Trigger<> *trig = this->idle_action_trigger_, *trig_fan = nullptr;
419  switch (action) {
422  if (this->idle_action_ready_()) {
424  if (this->action == climate::CLIMATE_ACTION_COOLING)
426  if (this->action == climate::CLIMATE_ACTION_FAN) {
429  } else {
431  }
432  }
433  if (this->action == climate::CLIMATE_ACTION_HEATING)
435  // trig = this->idle_action_trigger_;
436  ESP_LOGVV(TAG, "Switching to IDLE/OFF action");
437  this->cooling_max_runtime_exceeded_ = false;
438  this->heating_max_runtime_exceeded_ = false;
439  action_ready = true;
440  }
441  break;
443  if (this->cooling_action_ready_()) {
446  if (this->supports_fan_with_cooling_) {
448  trig_fan = this->fan_only_action_trigger_;
449  }
450  this->cooling_max_runtime_exceeded_ = false;
451  trig = this->cool_action_trigger_;
452  ESP_LOGVV(TAG, "Switching to COOLING action");
453  action_ready = true;
454  }
455  break;
457  if (this->heating_action_ready_()) {
460  if (this->supports_fan_with_heating_) {
462  trig_fan = this->fan_only_action_trigger_;
463  }
464  this->heating_max_runtime_exceeded_ = false;
465  trig = this->heat_action_trigger_;
466  ESP_LOGVV(TAG, "Switching to HEATING action");
467  action_ready = true;
468  }
469  break;
471  if (this->fanning_action_ready_()) {
474  } else {
476  }
477  trig = this->fan_only_action_trigger_;
478  ESP_LOGVV(TAG, "Switching to FAN_ONLY action");
479  action_ready = true;
480  }
481  break;
483  if (this->drying_action_ready_()) {
486  trig = this->dry_action_trigger_;
487  ESP_LOGVV(TAG, "Switching to DRYING action");
488  action_ready = true;
489  }
490  break;
491  default:
492  // we cannot report an invalid mode back to HA (even if it asked for one)
493  // and must assume some valid value
495  // trig = this->idle_action_trigger_;
496  }
497 
498  if (action_ready) {
499  if (this->prev_action_trigger_ != nullptr) {
501  this->prev_action_trigger_ = nullptr;
502  }
503  this->action = action;
504  this->prev_action_trigger_ = trig;
505  assert(trig != nullptr);
506  trig->trigger();
507  // if enabled, call the fan_only action with cooling/heating actions
508  if (trig_fan != nullptr) {
509  ESP_LOGVV(TAG, "Calling FAN_ONLY action with HEATING/COOLING action");
510  trig_fan->trigger();
511  }
512  if (publish_state)
513  this->publish_state();
514  }
515 }
516 
518  // setup_complete_ helps us ensure an action is called immediately after boot
519  if ((action == this->supplemental_action_) && this->setup_complete_) {
520  // already in target mode
521  return;
522  }
523 
524  switch (action) {
529  break;
532  break;
535  break;
536  default:
537  return;
538  }
539  ESP_LOGVV(TAG, "Updating supplemental action...");
542 }
543 
545  Trigger<> *trig = nullptr;
546 
547  switch (this->supplemental_action_) {
551  }
553  ESP_LOGVV(TAG, "Calling supplemental COOLING action");
554  break;
558  }
560  ESP_LOGVV(TAG, "Calling supplemental HEATING action");
561  break;
562  default:
563  break;
564  }
565 
566  if (trig != nullptr) {
567  assert(trig != nullptr);
568  trig->trigger();
569  }
570 }
571 
573  // setup_complete_ helps us ensure an action is called immediately after boot
574  if ((fan_mode == this->prev_fan_mode_) && this->setup_complete_) {
575  // already in target mode
576  return;
577  }
578 
579  this->fan_mode = fan_mode;
580  if (publish_state)
581  this->publish_state();
582 
583  if (this->fan_mode_ready_()) {
584  Trigger<> *trig = this->fan_mode_auto_trigger_;
585  switch (fan_mode) {
587  trig = this->fan_mode_on_trigger_;
588  ESP_LOGVV(TAG, "Switching to FAN_ON mode");
589  break;
591  trig = this->fan_mode_off_trigger_;
592  ESP_LOGVV(TAG, "Switching to FAN_OFF mode");
593  break;
595  // trig = this->fan_mode_auto_trigger_;
596  ESP_LOGVV(TAG, "Switching to FAN_AUTO mode");
597  break;
599  trig = this->fan_mode_low_trigger_;
600  ESP_LOGVV(TAG, "Switching to FAN_LOW mode");
601  break;
603  trig = this->fan_mode_medium_trigger_;
604  ESP_LOGVV(TAG, "Switching to FAN_MEDIUM mode");
605  break;
607  trig = this->fan_mode_high_trigger_;
608  ESP_LOGVV(TAG, "Switching to FAN_HIGH mode");
609  break;
611  trig = this->fan_mode_middle_trigger_;
612  ESP_LOGVV(TAG, "Switching to FAN_MIDDLE mode");
613  break;
615  trig = this->fan_mode_focus_trigger_;
616  ESP_LOGVV(TAG, "Switching to FAN_FOCUS mode");
617  break;
619  trig = this->fan_mode_diffuse_trigger_;
620  ESP_LOGVV(TAG, "Switching to FAN_DIFFUSE mode");
621  break;
623  trig = this->fan_mode_quiet_trigger_;
624  ESP_LOGVV(TAG, "Switching to FAN_QUIET mode");
625  break;
626  default:
627  // we cannot report an invalid mode back to HA (even if it asked for one)
628  // and must assume some valid value
629  fan_mode = climate::CLIMATE_FAN_AUTO;
630  // trig = this->fan_mode_auto_trigger_;
631  }
632  if (this->prev_fan_mode_trigger_ != nullptr) {
634  this->prev_fan_mode_trigger_ = nullptr;
635  }
637  assert(trig != nullptr);
638  trig->trigger();
639  this->prev_fan_mode_ = fan_mode;
640  this->prev_fan_mode_trigger_ = trig;
641  }
642 }
643 
645  // setup_complete_ helps us ensure an action is called immediately after boot
646  if ((mode == this->prev_mode_) && this->setup_complete_) {
647  // already in target mode
648  return;
649  }
650 
651  if (this->prev_mode_trigger_ != nullptr) {
653  this->prev_mode_trigger_ = nullptr;
654  }
655  Trigger<> *trig = this->auto_mode_trigger_;
656  switch (mode) {
658  trig = this->off_mode_trigger_;
659  break;
661  // trig = this->auto_mode_trigger_;
662  break;
664  trig = this->cool_mode_trigger_;
665  break;
667  trig = this->heat_mode_trigger_;
668  break;
670  trig = this->fan_only_mode_trigger_;
671  break;
673  trig = this->dry_mode_trigger_;
674  break;
675  default:
676  // we cannot report an invalid mode back to HA (even if it asked for one)
677  // and must assume some valid value
679  // trig = this->auto_mode_trigger_;
680  }
681  assert(trig != nullptr);
682  trig->trigger();
683  this->mode = mode;
684  this->prev_mode_ = mode;
685  this->prev_mode_trigger_ = trig;
686  if (publish_state)
687  this->publish_state();
688 }
689 
691  // setup_complete_ helps us ensure an action is called immediately after boot
692  if ((swing_mode == this->prev_swing_mode_) && this->setup_complete_) {
693  // already in target mode
694  return;
695  }
696 
697  if (this->prev_swing_mode_trigger_ != nullptr) {
699  this->prev_swing_mode_trigger_ = nullptr;
700  }
701  Trigger<> *trig = this->swing_mode_off_trigger_;
702  switch (swing_mode) {
704  trig = this->swing_mode_both_trigger_;
705  break;
707  trig = this->swing_mode_horizontal_trigger_;
708  break;
710  // trig = this->swing_mode_off_trigger_;
711  break;
713  trig = this->swing_mode_vertical_trigger_;
714  break;
715  default:
716  // we cannot report an invalid mode back to HA (even if it asked for one)
717  // and must assume some valid value
718  swing_mode = climate::CLIMATE_SWING_OFF;
719  // trig = this->swing_mode_off_trigger_;
720  }
721  assert(trig != nullptr);
722  trig->trigger();
723  this->swing_mode = swing_mode;
725  this->prev_swing_mode_trigger_ = trig;
726  if (publish_state)
727  this->publish_state();
728 }
729 
734  }
737 }
738 
742 }
743 
747 }
748 
750 
753  return !(this->timer_active_(thermostat::TIMER_FAN_MODE));
754  }
756 }
757 
761 }
762 
764  if (this->timer_duration_(timer_index) > 0) {
765  this->timer_[timer_index].started = millis();
766  this->timer_[timer_index].active = true;
767  }
768 }
769 
771  auto ret = this->timer_[timer_index].active;
772  this->timer_[timer_index].active = false;
773  return ret;
774 }
775 
777  return this->timer_[timer_index].active;
778 }
779 
781  return this->timer_[timer_index].time;
782 }
783 
784 std::function<void()> ThermostatClimate::timer_cbf_(ThermostatClimateTimerIndex timer_index) {
785  return this->timer_[timer_index].func;
786 }
787 
789  ESP_LOGVV(TAG, "cooling_max_run_time timer expired");
790  this->cooling_max_runtime_exceeded_ = true;
793 }
794 
796  ESP_LOGVV(TAG, "cooling_off timer expired");
797  this->switch_to_action_(this->compute_action_());
799 }
800 
802  ESP_LOGVV(TAG, "cooling_on timer expired");
803  this->switch_to_action_(this->compute_action_());
805 }
806 
808  ESP_LOGVV(TAG, "fan_mode timer expired");
811  this->switch_to_action_(this->compute_action_());
812 }
813 
815  ESP_LOGVV(TAG, "fanning_off timer expired");
816  this->switch_to_action_(this->compute_action_());
817 }
818 
820  ESP_LOGVV(TAG, "fanning_on timer expired");
821  this->switch_to_action_(this->compute_action_());
822 }
823 
825  ESP_LOGVV(TAG, "heating_max_run_time timer expired");
826  this->heating_max_runtime_exceeded_ = true;
829 }
830 
832  ESP_LOGVV(TAG, "heating_off timer expired");
833  this->switch_to_action_(this->compute_action_());
835 }
836 
838  ESP_LOGVV(TAG, "heating_on timer expired");
839  this->switch_to_action_(this->compute_action_());
841 }
842 
844  ESP_LOGVV(TAG, "idle_on timer expired");
845  this->switch_to_action_(this->compute_action_());
847 }
848 
850  if (this->supports_two_points_) {
851  // setup_complete_ helps us ensure an action is called immediately after boot
854  return; // nothing changed, no reason to trigger
855  } else {
856  // save the new temperatures so we can check them again later; the trigger will fire below
859  }
860  } else {
861  if ((this->prev_target_temperature_ == this->target_temperature) && this->setup_complete_) {
862  return; // nothing changed, no reason to trigger
863  } else {
864  // save the new temperature so we can check it again later; the trigger will fire below
866  }
867  }
868  // trigger the action
870  assert(trig != nullptr);
871  trig->trigger();
872 }
873 
876 
877  if (this->supports_cool_) {
878  if (this->current_temperature > temperature + this->cooling_deadband_) {
879  // if the current temperature exceeds the target + deadband, cooling is required
880  return true;
881  } else if (this->current_temperature < temperature - this->cooling_overrun_) {
882  // if the current temperature is less than the target - overrun, cooling should stop
883  return false;
884  } else {
885  // if we get here, the current temperature is between target + deadband and target - overrun,
886  // so the action should not change unless it conflicts with the current mode
887  return (this->action == climate::CLIMATE_ACTION_COOLING) &&
889  }
890  }
891  return false;
892 }
893 
896 
897  if (this->supports_fan_only_) {
898  if (this->supports_fan_only_cooling_) {
899  if (this->current_temperature > temperature + this->cooling_deadband_) {
900  // if the current temperature exceeds the target + deadband, fanning is required
901  return true;
902  } else if (this->current_temperature < temperature - this->cooling_overrun_) {
903  // if the current temperature is less than the target - overrun, fanning should stop
904  return false;
905  } else {
906  // if we get here, the current temperature is between target + deadband and target - overrun,
907  // so the action should not change unless it conflicts with the current mode
909  }
910  } else {
911  return true;
912  }
913  }
914  return false;
915 }
916 
919 
920  if (this->supports_heat_) {
921  if (this->current_temperature < temperature - this->heating_deadband_) {
922  // if the current temperature is below the target - deadband, heating is required
923  return true;
924  } else if (this->current_temperature > temperature + this->heating_overrun_) {
925  // if the current temperature is above the target + overrun, heating should stop
926  return false;
927  } else {
928  // if we get here, the current temperature is between target - deadband and target + overrun,
929  // so the action should not change unless it conflicts with the current mode
930  return (this->action == climate::CLIMATE_ACTION_HEATING) &&
932  }
933  }
934  return false;
935 }
936 
939  // the component must supports_cool_ and the climate action must be climate::CLIMATE_ACTION_COOLING. then...
940  // supplemental cooling is required if the max delta or max runtime was exceeded or the action is already engaged
941  return this->supports_cool_ && (this->action == climate::CLIMATE_ACTION_COOLING) &&
945 }
946 
949  // the component must supports_heat_ and the climate action must be climate::CLIMATE_ACTION_HEATING. then...
950  // supplemental heating is required if the max delta or max runtime was exceeded or the action is already engaged
951  return this->supports_heat_ && (this->action == climate::CLIMATE_ACTION_HEATING) &&
953  (this->current_temperature < temperature - this->supplemental_heat_delta_) ||
955 }
956 
958  bool is_default_preset) {
959  ESP_LOGCONFIG(TAG, " %s Is Default: %s", preset_name, YESNO(is_default_preset));
960 
961  if (this->supports_heat_) {
962  if (this->supports_two_points_) {
963  ESP_LOGCONFIG(TAG, " %s Default Target Temperature Low: %.1f°C", preset_name,
964  config.default_temperature_low);
965  } else {
966  ESP_LOGCONFIG(TAG, " %s Default Target Temperature Low: %.1f°C", preset_name, config.default_temperature);
967  }
968  }
969  if ((this->supports_cool_) || (this->supports_fan_only_)) {
970  if (this->supports_two_points_) {
971  ESP_LOGCONFIG(TAG, " %s Default Target Temperature High: %.1f°C", preset_name,
972  config.default_temperature_high);
973  } else {
974  ESP_LOGCONFIG(TAG, " %s Default Target Temperature High: %.1f°C", preset_name, config.default_temperature);
975  }
976  }
977 
978  if (config.mode_.has_value()) {
979  ESP_LOGCONFIG(TAG, " %s Default Mode: %s", preset_name,
980  LOG_STR_ARG(climate::climate_mode_to_string(*config.mode_)));
981  }
982  if (config.fan_mode_.has_value()) {
983  ESP_LOGCONFIG(TAG, " %s Default Fan Mode: %s", preset_name,
984  LOG_STR_ARG(climate::climate_fan_mode_to_string(*config.fan_mode_)));
985  }
986  if (config.swing_mode_.has_value()) {
987  ESP_LOGCONFIG(TAG, " %s Default Swing Mode: %s", preset_name,
988  LOG_STR_ARG(climate::climate_swing_mode_to_string(*config.swing_mode_)));
989  }
990 }
991 
993  auto config = this->preset_config_.find(preset);
994 
995  if (config != this->preset_config_.end()) {
996  ESP_LOGI(TAG, "Preset %s requested", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
997  if (this->change_preset_internal_(config->second) || (!this->preset.has_value()) ||
998  this->preset.value() != preset) {
999  // Fire any preset changed trigger if defined
1000  Trigger<> *trig = this->preset_change_trigger_;
1001  assert(trig != nullptr);
1002  this->preset = preset;
1003  trig->trigger();
1004 
1005  this->refresh();
1006  ESP_LOGI(TAG, "Preset %s applied", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
1007  } else {
1008  ESP_LOGI(TAG, "No changes required to apply preset %s", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
1009  }
1010  this->custom_preset.reset();
1011  this->preset = preset;
1012  } else {
1013  ESP_LOGE(TAG, "Preset %s is not configured, ignoring.", LOG_STR_ARG(climate::climate_preset_to_string(preset)));
1014  }
1015 }
1016 
1018  auto config = this->custom_preset_config_.find(custom_preset);
1019 
1020  if (config != this->custom_preset_config_.end()) {
1021  ESP_LOGI(TAG, "Custom preset %s requested", custom_preset.c_str());
1022  if (this->change_preset_internal_(config->second) || (!this->custom_preset.has_value()) ||
1023  this->custom_preset.value() != custom_preset) {
1024  // Fire any preset changed trigger if defined
1025  Trigger<> *trig = this->preset_change_trigger_;
1026  assert(trig != nullptr);
1027  this->custom_preset = custom_preset;
1028  trig->trigger();
1029 
1030  this->refresh();
1031  ESP_LOGI(TAG, "Custom preset %s applied", custom_preset.c_str());
1032  } else {
1033  ESP_LOGI(TAG, "No changes required to apply custom preset %s", custom_preset.c_str());
1034  }
1035  this->preset.reset();
1036  this->custom_preset = custom_preset;
1037  } else {
1038  ESP_LOGE(TAG, "Custom Preset %s is not configured, ignoring.", custom_preset.c_str());
1039  }
1040 }
1041 
1043  bool something_changed = false;
1044 
1045  if (this->supports_two_points_) {
1046  if (this->target_temperature_low != config.default_temperature_low) {
1048  something_changed = true;
1049  }
1050  if (this->target_temperature_high != config.default_temperature_high) {
1052  something_changed = true;
1053  }
1054  } else {
1055  if (this->target_temperature != config.default_temperature) {
1056  this->target_temperature = config.default_temperature;
1057  something_changed = true;
1058  }
1059  }
1060 
1061  // Note: The mode, fan_mode and swing_mode can all be defined in the preset but if the climate.control call
1062  // also specifies them then the climate.control call's values will override the preset's values for that call
1063  if (config.mode_.has_value() && (this->mode != config.mode_.value())) {
1064  ESP_LOGV(TAG, "Setting mode to %s", LOG_STR_ARG(climate::climate_mode_to_string(*config.mode_)));
1065  this->mode = *config.mode_;
1066  something_changed = true;
1067  }
1068 
1069  if (config.fan_mode_.has_value() && (this->fan_mode != config.fan_mode_.value())) {
1070  ESP_LOGV(TAG, "Setting fan mode to %s", LOG_STR_ARG(climate::climate_fan_mode_to_string(*config.fan_mode_)));
1071  this->fan_mode = *config.fan_mode_;
1072  something_changed = true;
1073  }
1074 
1075  if (config.swing_mode_.has_value() && (this->swing_mode != config.swing_mode_.value())) {
1076  ESP_LOGV(TAG, "Setting swing mode to %s", LOG_STR_ARG(climate::climate_swing_mode_to_string(*config.swing_mode_)));
1077  this->swing_mode = *config.swing_mode_;
1078  something_changed = true;
1079  }
1080 
1081  return something_changed;
1082 }
1083 
1085  const ThermostatClimateTargetTempConfig &config) {
1086  this->preset_config_[preset] = config;
1087 }
1088 
1090  const ThermostatClimateTargetTempConfig &config) {
1091  this->custom_preset_config_[name] = config;
1092 }
1093 
1095  : cool_action_trigger_(new Trigger<>()),
1097  cool_mode_trigger_(new Trigger<>()),
1098  dry_action_trigger_(new Trigger<>()),
1099  dry_mode_trigger_(new Trigger<>()),
1100  heat_action_trigger_(new Trigger<>()),
1102  heat_mode_trigger_(new Trigger<>()),
1103  auto_mode_trigger_(new Trigger<>()),
1104  idle_action_trigger_(new Trigger<>()),
1105  off_mode_trigger_(new Trigger<>()),
1108  fan_mode_on_trigger_(new Trigger<>()),
1109  fan_mode_off_trigger_(new Trigger<>()),
1111  fan_mode_low_trigger_(new Trigger<>()),
1123  preset_change_trigger_(new Trigger<>()) {}
1124 
1127 }
1128 
1130 
1132  this->on_boot_restore_from_ = on_boot_restore_from;
1133 }
1135  this->set_point_minimum_differential_ = differential;
1136 }
1137 void ThermostatClimate::set_cool_deadband(float deadband) { this->cooling_deadband_ = deadband; }
1138 void ThermostatClimate::set_cool_overrun(float overrun) { this->cooling_overrun_ = overrun; }
1139 void ThermostatClimate::set_heat_deadband(float deadband) { this->heating_deadband_ = deadband; }
1140 void ThermostatClimate::set_heat_overrun(float overrun) { this->heating_overrun_ = overrun; }
1145  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1146 }
1149  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1150 }
1152  this->timer_[thermostat::TIMER_COOLING_ON].time =
1153  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1154 }
1156  this->timer_[thermostat::TIMER_FAN_MODE].time =
1157  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1158 }
1161  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1162 }
1164  this->timer_[thermostat::TIMER_FANNING_ON].time =
1165  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1166 }
1169  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1170 }
1173  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1174 }
1176  this->timer_[thermostat::TIMER_HEATING_ON].time =
1177  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1178 }
1180  this->timer_[thermostat::TIMER_IDLE_ON].time =
1181  1000 * (time < this->min_timer_duration_ ? this->min_timer_duration_ : time);
1182 }
1183 void ThermostatClimate::set_sensor(sensor::Sensor *sensor) { this->sensor_ = sensor; }
1185  this->humidity_sensor_ = humidity_sensor;
1186 }
1187 void ThermostatClimate::set_use_startup_delay(bool use_startup_delay) { this->use_startup_delay_ = use_startup_delay; }
1188 void ThermostatClimate::set_supports_heat_cool(bool supports_heat_cool) {
1189  this->supports_heat_cool_ = supports_heat_cool;
1190 }
1191 void ThermostatClimate::set_supports_auto(bool supports_auto) { this->supports_auto_ = supports_auto; }
1192 void ThermostatClimate::set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; }
1193 void ThermostatClimate::set_supports_dry(bool supports_dry) { this->supports_dry_ = supports_dry; }
1194 void ThermostatClimate::set_supports_fan_only(bool supports_fan_only) { this->supports_fan_only_ = supports_fan_only; }
1196  bool supports_fan_only_action_uses_fan_mode_timer) {
1197  this->supports_fan_only_action_uses_fan_mode_timer_ = supports_fan_only_action_uses_fan_mode_timer;
1198 }
1199 void ThermostatClimate::set_supports_fan_only_cooling(bool supports_fan_only_cooling) {
1200  this->supports_fan_only_cooling_ = supports_fan_only_cooling;
1201 }
1202 void ThermostatClimate::set_supports_fan_with_cooling(bool supports_fan_with_cooling) {
1203  this->supports_fan_with_cooling_ = supports_fan_with_cooling;
1204 }
1205 void ThermostatClimate::set_supports_fan_with_heating(bool supports_fan_with_heating) {
1206  this->supports_fan_with_heating_ = supports_fan_with_heating;
1207 }
1208 void ThermostatClimate::set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; }
1209 void ThermostatClimate::set_supports_fan_mode_on(bool supports_fan_mode_on) {
1210  this->supports_fan_mode_on_ = supports_fan_mode_on;
1211 }
1212 void ThermostatClimate::set_supports_fan_mode_off(bool supports_fan_mode_off) {
1213  this->supports_fan_mode_off_ = supports_fan_mode_off;
1214 }
1215 void ThermostatClimate::set_supports_fan_mode_auto(bool supports_fan_mode_auto) {
1216  this->supports_fan_mode_auto_ = supports_fan_mode_auto;
1217 }
1218 void ThermostatClimate::set_supports_fan_mode_low(bool supports_fan_mode_low) {
1219  this->supports_fan_mode_low_ = supports_fan_mode_low;
1220 }
1221 void ThermostatClimate::set_supports_fan_mode_medium(bool supports_fan_mode_medium) {
1222  this->supports_fan_mode_medium_ = supports_fan_mode_medium;
1223 }
1224 void ThermostatClimate::set_supports_fan_mode_high(bool supports_fan_mode_high) {
1225  this->supports_fan_mode_high_ = supports_fan_mode_high;
1226 }
1227 void ThermostatClimate::set_supports_fan_mode_middle(bool supports_fan_mode_middle) {
1228  this->supports_fan_mode_middle_ = supports_fan_mode_middle;
1229 }
1230 void ThermostatClimate::set_supports_fan_mode_focus(bool supports_fan_mode_focus) {
1231  this->supports_fan_mode_focus_ = supports_fan_mode_focus;
1232 }
1233 void ThermostatClimate::set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse) {
1234  this->supports_fan_mode_diffuse_ = supports_fan_mode_diffuse;
1235 }
1236 void ThermostatClimate::set_supports_fan_mode_quiet(bool supports_fan_mode_quiet) {
1237  this->supports_fan_mode_quiet_ = supports_fan_mode_quiet;
1238 }
1239 void ThermostatClimate::set_supports_swing_mode_both(bool supports_swing_mode_both) {
1240  this->supports_swing_mode_both_ = supports_swing_mode_both;
1241 }
1242 void ThermostatClimate::set_supports_swing_mode_off(bool supports_swing_mode_off) {
1243  this->supports_swing_mode_off_ = supports_swing_mode_off;
1244 }
1245 void ThermostatClimate::set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal) {
1246  this->supports_swing_mode_horizontal_ = supports_swing_mode_horizontal;
1247 }
1248 void ThermostatClimate::set_supports_swing_mode_vertical(bool supports_swing_mode_vertical) {
1249  this->supports_swing_mode_vertical_ = supports_swing_mode_vertical;
1250 }
1251 void ThermostatClimate::set_supports_two_points(bool supports_two_points) {
1252  this->supports_two_points_ = supports_two_points;
1253 }
1254 
1257  return this->supplemental_cool_action_trigger_;
1258 }
1263  return this->supplemental_heat_action_trigger_;
1264 }
1288 
1290  LOG_CLIMATE("", "Thermostat", this);
1291 
1292  if (this->supports_two_points_) {
1293  ESP_LOGCONFIG(TAG, " Minimum Set Point Differential: %.1f°C", this->set_point_minimum_differential_);
1294  }
1295  ESP_LOGCONFIG(TAG, " Start-up Delay Enabled: %s", YESNO(this->use_startup_delay_));
1296  if (this->supports_cool_) {
1297  ESP_LOGCONFIG(TAG, " Cooling Parameters:");
1298  ESP_LOGCONFIG(TAG, " Deadband: %.1f°C", this->cooling_deadband_);
1299  ESP_LOGCONFIG(TAG, " Overrun: %.1f°C", this->cooling_overrun_);
1301  ESP_LOGCONFIG(TAG, " Supplemental Delta: %.1f°C", this->supplemental_cool_delta_);
1302  ESP_LOGCONFIG(TAG, " Maximum Run Time: %" PRIu32 "s",
1304  }
1305  ESP_LOGCONFIG(TAG, " Minimum Off Time: %" PRIu32 "s",
1307  ESP_LOGCONFIG(TAG, " Minimum Run Time: %" PRIu32 "s",
1309  }
1310  if (this->supports_heat_) {
1311  ESP_LOGCONFIG(TAG, " Heating Parameters:");
1312  ESP_LOGCONFIG(TAG, " Deadband: %.1f°C", this->heating_deadband_);
1313  ESP_LOGCONFIG(TAG, " Overrun: %.1f°C", this->heating_overrun_);
1315  ESP_LOGCONFIG(TAG, " Supplemental Delta: %.1f°C", this->supplemental_heat_delta_);
1316  ESP_LOGCONFIG(TAG, " Maximum Run Time: %" PRIu32 "s",
1318  }
1319  ESP_LOGCONFIG(TAG, " Minimum Off Time: %" PRIu32 "s",
1321  ESP_LOGCONFIG(TAG, " Minimum Run Time: %" PRIu32 "s",
1323  }
1324  if (this->supports_fan_only_) {
1325  ESP_LOGCONFIG(TAG, " Fanning Minimum Off Time: %" PRIu32 "s",
1327  ESP_LOGCONFIG(TAG, " Fanning Minimum Run Time: %" PRIu32 "s",
1329  }
1333  this->supports_fan_mode_quiet_) {
1334  ESP_LOGCONFIG(TAG, " Minimum Fan Mode Switching Time: %" PRIu32 "s",
1336  }
1337  ESP_LOGCONFIG(TAG, " Minimum Idle Time: %" PRIu32 "s", this->timer_[thermostat::TIMER_IDLE_ON].time / 1000);
1338  ESP_LOGCONFIG(TAG, " Supports AUTO: %s", YESNO(this->supports_auto_));
1339  ESP_LOGCONFIG(TAG, " Supports HEAT/COOL: %s", YESNO(this->supports_heat_cool_));
1340  ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(this->supports_cool_));
1341  ESP_LOGCONFIG(TAG, " Supports DRY: %s", YESNO(this->supports_dry_));
1342  ESP_LOGCONFIG(TAG, " Supports FAN_ONLY: %s", YESNO(this->supports_fan_only_));
1343  ESP_LOGCONFIG(TAG, " Supports FAN_ONLY_ACTION_USES_FAN_MODE_TIMER: %s",
1345  ESP_LOGCONFIG(TAG, " Supports FAN_ONLY_COOLING: %s", YESNO(this->supports_fan_only_cooling_));
1346  if (this->supports_cool_) {
1347  ESP_LOGCONFIG(TAG, " Supports FAN_WITH_COOLING: %s", YESNO(this->supports_fan_with_cooling_));
1348  }
1349  if (this->supports_heat_) {
1350  ESP_LOGCONFIG(TAG, " Supports FAN_WITH_HEATING: %s", YESNO(this->supports_fan_with_heating_));
1351  }
1352  ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(this->supports_heat_));
1353  ESP_LOGCONFIG(TAG, " Supports FAN MODE ON: %s", YESNO(this->supports_fan_mode_on_));
1354  ESP_LOGCONFIG(TAG, " Supports FAN MODE OFF: %s", YESNO(this->supports_fan_mode_off_));
1355  ESP_LOGCONFIG(TAG, " Supports FAN MODE AUTO: %s", YESNO(this->supports_fan_mode_auto_));
1356  ESP_LOGCONFIG(TAG, " Supports FAN MODE LOW: %s", YESNO(this->supports_fan_mode_low_));
1357  ESP_LOGCONFIG(TAG, " Supports FAN MODE MEDIUM: %s", YESNO(this->supports_fan_mode_medium_));
1358  ESP_LOGCONFIG(TAG, " Supports FAN MODE HIGH: %s", YESNO(this->supports_fan_mode_high_));
1359  ESP_LOGCONFIG(TAG, " Supports FAN MODE MIDDLE: %s", YESNO(this->supports_fan_mode_middle_));
1360  ESP_LOGCONFIG(TAG, " Supports FAN MODE FOCUS: %s", YESNO(this->supports_fan_mode_focus_));
1361  ESP_LOGCONFIG(TAG, " Supports FAN MODE DIFFUSE: %s", YESNO(this->supports_fan_mode_diffuse_));
1362  ESP_LOGCONFIG(TAG, " Supports FAN MODE QUIET: %s", YESNO(this->supports_fan_mode_quiet_));
1363  ESP_LOGCONFIG(TAG, " Supports SWING MODE BOTH: %s", YESNO(this->supports_swing_mode_both_));
1364  ESP_LOGCONFIG(TAG, " Supports SWING MODE OFF: %s", YESNO(this->supports_swing_mode_off_));
1365  ESP_LOGCONFIG(TAG, " Supports SWING MODE HORIZONTAL: %s", YESNO(this->supports_swing_mode_horizontal_));
1366  ESP_LOGCONFIG(TAG, " Supports SWING MODE VERTICAL: %s", YESNO(this->supports_swing_mode_vertical_));
1367  ESP_LOGCONFIG(TAG, " Supports TWO SET POINTS: %s", YESNO(this->supports_two_points_));
1368 
1369  ESP_LOGCONFIG(TAG, " Supported PRESETS: ");
1370  for (auto &it : this->preset_config_) {
1371  const auto *preset_name = LOG_STR_ARG(climate::climate_preset_to_string(it.first));
1372 
1373  ESP_LOGCONFIG(TAG, " Supports %s: %s", preset_name, YESNO(true));
1374  this->dump_preset_config_(preset_name, it.second, it.first == this->default_preset_);
1375  }
1376 
1377  ESP_LOGCONFIG(TAG, " Supported CUSTOM PRESETS: ");
1378  for (auto &it : this->custom_preset_config_) {
1379  const auto *preset_name = it.first.c_str();
1380 
1381  ESP_LOGCONFIG(TAG, " Supports %s: %s", preset_name, YESNO(true));
1382  this->dump_preset_config_(preset_name, it.second, it.first == this->default_custom_preset_);
1383  }
1384  ESP_LOGCONFIG(TAG, " On boot, restore from: %s",
1385  this->on_boot_restore_from_ == thermostat::DEFAULT_PRESET ? "DEFAULT_PRESET" : "MEMORY");
1386 }
1387 
1389 
1391  : default_temperature(default_temperature) {}
1392 
1395  : default_temperature_low(default_temperature_low), default_temperature_high(default_temperature_high) {}
1396 
1397 } // namespace thermostat
1398 } // namespace esphome
Trigger * swing_mode_vertical_trigger_
The trigger to call when the controller should switch the swing mode to "vertical".
float set_point_minimum_differential_
Minimum differential required between set points.
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal)
The fan mode is set to Low.
Definition: climate_mode.h:54
value_type const & value() const
Definition: optional.h:89
The climate device is off (inactive or no power)
Definition: climate_mode.h:33
Trigger * cool_action_trigger_
The trigger to call when the controller should switch to cooling action/mode.
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition: climate.h:182
The fan mode is set to Quiet.
Definition: climate_mode.h:66
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:202
climate::ClimateTraits traits() override
Return the traits of this controller.
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
const char * name
Definition: stm32flash.h:78
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition: sensor.cpp:52
Trigger * swing_mode_both_trigger_
The trigger to call when the controller should switch the swing mode to "both".
std::map< std::string, ThermostatClimateTargetTempConfig > custom_preset_config_
The set of custom preset configurations this thermostat supports (eg. "My Custom Preset") ...
void set_supports_fan_mode_on(bool supports_fan_mode_on)
The fan mode is set to Both.
Definition: climate_mode.h:74
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:82
The climate device is drying.
Definition: climate_mode.h:41
void set_supports_fan_mode_auto(bool supports_fan_mode_auto)
void switch_to_action_(climate::ClimateAction action, bool publish_state=true)
Switch the climate device to the given climate action.
Trigger * prev_action_trigger_
A reference to the trigger that was previously active.
Trigger * fan_mode_auto_trigger_
The trigger to call when the controller should switch the fan to "auto" mode.
float target_temperature
The target temperature of the climate device.
Definition: climate.h:186
void set_supports_fan_with_cooling(bool supports_fan_with_cooling)
Trigger * dry_action_trigger_
The trigger to call when the controller should switch to dry (dehumidification) mode.
bool supports_fan_mode_auto_
Whether the controller supports fan auto mode.
void switch_to_supplemental_action_(climate::ClimateAction action)
The climate device is in fan only mode.
Definition: climate_mode.h:43
void set_supports_fan_only(bool supports_fan_only)
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:273
The fan mode is set to Middle.
Definition: climate_mode.h:60
float prev_target_temperature_
Store previously-known temperatures.
void set_supports_current_humidity(bool supports_current_humidity)
This class contains all static data for climate devices.
bool supports_auto_
Whether the controller supports auto/cooling/drying/fanning/heating.
Trigger * fan_mode_middle_trigger_
The trigger to call when the controller should switch the fan to "middle" position.
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
Definition: climate_mode.cpp:6
void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse)
void add_supported_custom_preset(const std::string &preset)
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:173
Trigger * heat_action_trigger_
The trigger to call when the controller should switch to heating action/mode.
float temperature
Definition: qmp6988.h:71
void set_supports_fan_mode_medium(bool supports_fan_mode_medium)
void set_supports_fan_mode_middle(bool supports_fan_mode_middle)
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:275
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:191
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition: climate.h:179
The fan mode is set to Diffuse.
Definition: climate_mode.h:64
void set_supports_two_points(bool supports_two_points)
bool has_value() const
Definition: optional.h:87
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
optional< climate::ClimateSwingMode > swing_mode_
void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical)
void set_supports_fan_mode_focus(bool supports_fan_mode_focus)
thermostat::OnBootRestoreFrom on_boot_restore_from_
If set to DEFAULT_PRESET then the default preset is always used.
void set_fan_mode_minimum_switching_time_in_sec(uint32_t time)
climate::ClimateAction compute_supplemental_action_()
void set_default_preset(const std::string &custom_preset)
void refresh()
Call triggers based on updated climate states (modes/actions)
void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer)
void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state=true)
Switch the climate device to the given climate swing mode.
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
bool hysteresis_valid()
Set point and hysteresis validation.
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:70
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
std::string default_custom_preset_
Default custom preset to use on start up.
uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index)
Trigger * preset_change_trigger_
The triggr to call when the preset mode changes.
void add_supported_preset(ClimatePreset preset)
Trigger * fan_mode_quiet_trigger_
The trigger to call when the controller should switch the fan to "quiet" position.
void set_supports_heat_cool(bool supports_heat_cool)
Trigger * fan_mode_high_trigger_
The trigger to call when the controller should switch the fan to "high" speed.
float cooling_deadband_
Hysteresis values used for computing climate actions.
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
bool supports_fan_with_cooling_
Special flags – enables fan_only action to be called with cooling/heating actions.
void add_supported_swing_mode(ClimateSwingMode mode)
void set_supports_swing_mode_off(bool supports_swing_mode_off)
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:281
The fan mode is set to Horizontal.
Definition: climate_mode.h:78
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
void set_supports_fan_only_cooling(bool supports_fan_only_cooling)
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:280
sensor::Sensor * humidity_sensor_
The sensor used for getting the current humidity.
The fan mode is set to Auto.
Definition: climate_mode.h:52
void cooling_max_run_time_timer_callback_()
set_timeout() callbacks for various actions (see above)
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:208
bool supports_fan_mode_low_
Whether the controller supports various fan speeds and/or positions.
Trigger * fan_mode_low_trigger_
The trigger to call when the controller should switch the fan to "low" speed.
Trigger * fan_only_action_trigger_
The trigger to call when the controller should switch to fan-only action/mode.
void set_on_boot_restore_from(thermostat::OnBootRestoreFrom on_boot_restore_from)
bool idle_action_ready_()
Is the action ready to be called? Returns true if so.
void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config)
Trigger * temperature_change_trigger_
The trigger to call when the target temperature(s) change(es).
bool cooling_required_()
Check if cooling/fanning/heating actions are required; returns true if so.
bool supports_swing_mode_both_
Whether the controller supports various swing modes.
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
Definition: climate_mode.h:31
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition: climate.cpp:440
bool cancel_timer_(ThermostatClimateTimerIndex timer_index)
Trigger * fan_mode_medium_trigger_
The trigger to call when the controller should switch the fan to "medium" speed.
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
The climate device is adjusting the temperatre dynamically.
Definition: climate_mode.h:27
Trigger * swing_mode_off_trigger_
The trigger to call when the controller should switch the swing mode to "off".
The climate device is set to heat/cool to reach the target temperature.
Definition: climate_mode.h:14
The fan mode is set to Vertical.
Definition: climate_mode.h:76
bool timer_active_(ThermostatClimateTimerIndex timer_index)
The climate device is actively heating.
Definition: climate_mode.h:37
The fan mode is set to Focus.
Definition: climate_mode.h:62
climate::ClimateAction supplemental_action_
Store previously-known states.
The fan mode is set to Off.
Definition: climate_mode.h:50
void add_supported_fan_mode(ClimateFanMode mode)
Trigger * idle_action_trigger_
The trigger to call when the controller should switch to idle action/off mode.
Trigger * auto_mode_trigger_
The trigger to call when the controller should switch to auto mode.
const optional< float > & get_target_temperature() const
Definition: climate.cpp:274
climate::ClimateAction delayed_climate_action()
Returns the climate action that is being delayed (check climate_action_change_delayed(), first!)
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition: climate.cpp:395
Trigger * fan_mode_off_trigger_
The trigger to call when the controller should switch off the fan.
void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config)
The fan mode is set to High.
Definition: climate_mode.h:58
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
The swing mode is set to Off.
Definition: climate_mode.h:72
The climate device is off.
Definition: climate_mode.h:12
void set_use_startup_delay(bool use_startup_delay)
bool climate_action_change_delayed()
Returns true if a climate action/fan mode transition is being delayed.
void set_supports_fan_with_heating(bool supports_fan_with_heating)
void set_supports_action(bool supports_action)
void change_custom_preset_(const std::string &custom_preset)
Change to a provided custom preset setting; will reset temperature, mode, fan, and swing modes accord...
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition: climate.h:211
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
bool cooling_max_runtime_exceeded_
Flags indicating if maximum allowable run time was exceeded.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition: climate.h:199
void switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state=true)
Switch the climate device to the given climate fan mode.
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:278
void set_supports_fan_mode_low(bool supports_fan_mode_low)
void set_supports_fan_mode_quiet(bool supports_fan_mode_quiet)
Trigger * fan_mode_focus_trigger_
The trigger to call when the controller should switch the fan to "focus" position.
The fan mode is set to On.
Definition: climate_mode.h:48
climate::ClimateAction compute_action_(bool ignore_timers=false)
Re-compute the required action of this climate controller.
float cool_deadband()
Get current hysteresis values.
Trigger * swing_mode_horizontal_trigger_
The trigger to call when the controller should switch the swing mode to "horizontal".
std::function< void()> timer_cbf_(ThermostatClimateTimerIndex timer_index)
void set_supports_fan_mode_off(bool supports_fan_mode_off)
sensor::Sensor * sensor_
The sensor used for getting the current temperature.
std::vector< ThermostatClimateTimer > timer_
Climate action timers.
void start_timer_(ThermostatClimateTimerIndex timer_index)
Start/cancel/get status of climate action timer.
float supplemental_cool_delta_
Maximum allowable temperature deltas before engauging supplemental cooling/heating actions...
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:282
std::map< climate::ClimatePreset, ThermostatClimateTargetTempConfig > preset_config_
The set of standard preset configurations this thermostat supports (Eg. AWAY, ECO, etc)
climate::ClimateSwingMode prev_swing_mode_
bool change_preset_internal_(const ThermostatClimateTargetTempConfig &config)
Applies the temperature, mode, fan, and swing modes of the provided config.
bool supports_two_points_
Whether the controller supports two set points.
climate::ClimateFanMode locked_fan_mode()
Returns the fan mode that is locked in (check fan_mode_change_delayed(), first!)
void set_set_point_minimum_differential(float differential)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void check_temperature_change_trigger_()
Check if the temperature change trigger should be called.
void switch_to_mode_(climate::ClimateMode mode, bool publish_state=true)
Switch the climate device to the given climate mode.
The climate device is idle (monitoring climate but no action needed)
Definition: climate_mode.h:39
void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature)
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition: climate.cpp:329
Trigger * fan_mode_on_trigger_
The trigger to call when the controller should switch on the fan.
bool supports_fan_mode_on_
Whether the controller supports turning on or off just the fan.
Trigger * fan_mode_diffuse_trigger_
The trigger to call when the controller should switch the fan to "diffuse" position.
void set_supports_current_temperature(bool supports_current_temperature)
The fan mode is set to Medium.
Definition: climate_mode.h:56
const optional< float > & get_target_temperature_high() const
Definition: climate.cpp:276
bool supports_fan_only_action_uses_fan_mode_timer_
Special flag – enables fan_modes to share timer with fan_only climate action.
Base-class for all sensors.
Definition: sensor.h:57
void set_supports_fan_mode_high(bool supports_fan_mode_high)
void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config, bool is_default_preset)
void set_supports_swing_mode_both(bool supports_swing_mode_both)
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
const uint8_t min_timer_duration_
Minimum allowable duration in seconds for action timers.
void change_preset_(climate::ClimatePreset preset)
Change to a provided preset setting; will reset temperature, mode, fan, and swing modes accordingly...
The climate device is actively cooling.
Definition: climate_mode.h:35
value_type value_or(U const &v) const
Definition: optional.h:93
void add_supported_mode(ClimateMode mode)
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:189
void stop_action()
Stop any action connected to this trigger.
Definition: automation.h:103
bool use_startup_delay_
Used to start "off" delay timers at boot.
ClimateAction action
The active state of the climate device.
Definition: climate.h:176
bool setup_complete_
setup_complete_ blocks modifying/resetting the temps immediately after boot
climate::ClimatePreset default_preset_
Default standard preset to use on start up.
bool state
Definition: fan.h:34
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.
bool supports_fan_only_cooling_
Special flag – enables fan to be switched based on target_temperature_high.