ESPHome  2022.6.3
thermostat_climate.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <map>
8 
9 namespace esphome {
10 namespace thermostat {
11 
23 };
24 
26  const std::string name;
27  bool active;
28  uint32_t time;
29  std::function<void()> func;
30 };
31 
33  public:
35  ThermostatClimateTargetTempConfig(float default_temperature);
36  ThermostatClimateTargetTempConfig(float default_temperature_low, float default_temperature_high);
37 
40  void set_mode(climate::ClimateMode mode) { this->mode_ = mode; }
41 
42  float default_temperature{NAN};
43  float default_temperature_low{NAN};
44  float default_temperature_high{NAN};
45  float cool_deadband_{NAN};
46  float cool_overrun_{NAN};
47  float heat_deadband_{NAN};
48  float heat_overrun_{NAN};
52 };
53 
55  public:
57  void setup() override;
58  void dump_config() override;
59 
60  void set_default_mode(climate::ClimateMode default_mode);
61  void set_set_point_minimum_differential(float differential);
62  void set_cool_deadband(float deadband);
63  void set_cool_overrun(float overrun);
64  void set_heat_deadband(float deadband);
65  void set_heat_overrun(float overrun);
66  void set_supplemental_cool_delta(float delta);
67  void set_supplemental_heat_delta(float delta);
68  void set_cooling_maximum_run_time_in_sec(uint32_t time);
69  void set_heating_maximum_run_time_in_sec(uint32_t time);
70  void set_cooling_minimum_off_time_in_sec(uint32_t time);
71  void set_cooling_minimum_run_time_in_sec(uint32_t time);
72  void set_fan_mode_minimum_switching_time_in_sec(uint32_t time);
73  void set_fanning_minimum_off_time_in_sec(uint32_t time);
74  void set_fanning_minimum_run_time_in_sec(uint32_t time);
75  void set_heating_minimum_off_time_in_sec(uint32_t time);
76  void set_heating_minimum_run_time_in_sec(uint32_t time);
77  void set_idle_minimum_time_in_sec(uint32_t time);
78  void set_sensor(sensor::Sensor *sensor);
79  void set_use_startup_delay(bool use_startup_delay);
80  void set_supports_auto(bool supports_auto);
81  void set_supports_heat_cool(bool supports_heat_cool);
82  void set_supports_cool(bool supports_cool);
83  void set_supports_dry(bool supports_dry);
84  void set_supports_fan_only(bool supports_fan_only);
85  void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer);
86  void set_supports_fan_only_cooling(bool supports_fan_only_cooling);
87  void set_supports_fan_with_cooling(bool supports_fan_with_cooling);
88  void set_supports_fan_with_heating(bool supports_fan_with_heating);
89  void set_supports_heat(bool supports_heat);
90  void set_supports_fan_mode_on(bool supports_fan_mode_on);
91  void set_supports_fan_mode_off(bool supports_fan_mode_off);
92  void set_supports_fan_mode_auto(bool supports_fan_mode_auto);
93  void set_supports_fan_mode_low(bool supports_fan_mode_low);
94  void set_supports_fan_mode_medium(bool supports_fan_mode_medium);
95  void set_supports_fan_mode_high(bool supports_fan_mode_high);
96  void set_supports_fan_mode_middle(bool supports_fan_mode_middle);
97  void set_supports_fan_mode_focus(bool supports_fan_mode_focus);
98  void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse);
99  void set_supports_swing_mode_both(bool supports_swing_mode_both);
100  void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal);
101  void set_supports_swing_mode_off(bool supports_swing_mode_off);
102  void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical);
103  void set_supports_two_points(bool supports_two_points);
104 
105  void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config);
106  void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config);
107 
108  Trigger<> *get_cool_action_trigger() const;
109  Trigger<> *get_supplemental_cool_action_trigger() const;
110  Trigger<> *get_dry_action_trigger() const;
111  Trigger<> *get_fan_only_action_trigger() const;
112  Trigger<> *get_heat_action_trigger() const;
113  Trigger<> *get_supplemental_heat_action_trigger() const;
114  Trigger<> *get_idle_action_trigger() const;
115  Trigger<> *get_auto_mode_trigger() const;
116  Trigger<> *get_cool_mode_trigger() const;
117  Trigger<> *get_dry_mode_trigger() const;
118  Trigger<> *get_fan_only_mode_trigger() const;
119  Trigger<> *get_heat_mode_trigger() const;
120  Trigger<> *get_off_mode_trigger() const;
121  Trigger<> *get_fan_mode_on_trigger() const;
122  Trigger<> *get_fan_mode_off_trigger() const;
123  Trigger<> *get_fan_mode_auto_trigger() const;
124  Trigger<> *get_fan_mode_low_trigger() const;
125  Trigger<> *get_fan_mode_medium_trigger() const;
126  Trigger<> *get_fan_mode_high_trigger() const;
127  Trigger<> *get_fan_mode_middle_trigger() const;
128  Trigger<> *get_fan_mode_focus_trigger() const;
129  Trigger<> *get_fan_mode_diffuse_trigger() const;
130  Trigger<> *get_swing_mode_both_trigger() const;
131  Trigger<> *get_swing_mode_horizontal_trigger() const;
132  Trigger<> *get_swing_mode_off_trigger() const;
133  Trigger<> *get_swing_mode_vertical_trigger() const;
134  Trigger<> *get_temperature_change_trigger() const;
135  Trigger<> *get_preset_change_trigger() const;
137  float cool_deadband();
138  float cool_overrun();
139  float heat_deadband();
140  float heat_overrun();
142  void refresh();
144  bool climate_action_change_delayed();
145  bool fan_mode_change_delayed();
147  climate::ClimateAction delayed_climate_action();
149  climate::ClimateFanMode locked_fan_mode();
151  bool hysteresis_valid(); // returns true if valid
152  void validate_target_temperature();
153  void validate_target_temperatures();
154  void validate_target_temperature_low();
155  void validate_target_temperature_high();
156 
157  protected:
159  void control(const climate::ClimateCall &call) override;
160 
162  void change_preset_(climate::ClimatePreset preset);
164  void change_custom_preset_(const std::string &custom_preset);
165 
168  void change_preset_internal_(const ThermostatClimateTargetTempConfig &config);
169 
171  climate::ClimateTraits traits() override;
172 
174  climate::ClimateAction compute_action_(bool ignore_timers = false);
175  climate::ClimateAction compute_supplemental_action_();
176 
178  void switch_to_action_(climate::ClimateAction action, bool publish_state = true);
179  void switch_to_supplemental_action_(climate::ClimateAction action);
180  void trigger_supplemental_action_();
181 
183  void switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state = true);
184 
186  void switch_to_mode_(climate::ClimateMode mode, bool publish_state = true);
187 
189  void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state = true);
190 
192  void check_temperature_change_trigger_();
193 
195  bool idle_action_ready_();
196  bool cooling_action_ready_();
197  bool drying_action_ready_();
198  bool fan_mode_ready_();
199  bool fanning_action_ready_();
200  bool heating_action_ready_();
201 
203  void start_timer_(ThermostatClimateTimerIndex timer_index);
204  bool cancel_timer_(ThermostatClimateTimerIndex timer_index);
205  bool timer_active_(ThermostatClimateTimerIndex timer_index);
206  uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index);
207  std::function<void()> timer_cbf_(ThermostatClimateTimerIndex timer_index);
208 
210  void cooling_max_run_time_timer_callback_();
211  void cooling_off_timer_callback_();
212  void cooling_on_timer_callback_();
213  void fan_mode_timer_callback_();
214  void fanning_off_timer_callback_();
215  void fanning_on_timer_callback_();
216  void heating_max_run_time_timer_callback_();
217  void heating_off_timer_callback_();
218  void heating_on_timer_callback_();
219  void idle_on_timer_callback_();
220 
222  bool cooling_required_();
223  bool fanning_required_();
224  bool heating_required_();
225  bool supplemental_cooling_required_();
226  bool supplemental_heating_required_();
227 
228  void dump_preset_config_(const std::string &preset_name, const ThermostatClimateTargetTempConfig &config);
229 
231  sensor::Sensor *sensor_{nullptr};
232 
237  bool supports_auto_{false};
238  bool supports_heat_cool_{false};
239  bool supports_cool_{false};
240  bool supports_dry_{false};
241  bool supports_fan_only_{false};
242  bool supports_heat_{false};
244  bool supports_fan_only_action_uses_fan_mode_timer_{false};
246  bool supports_fan_only_cooling_{false};
248  bool supports_fan_with_cooling_{false};
249  bool supports_fan_with_heating_{false};
250 
255  bool supports_fan_mode_on_{false};
256  bool supports_fan_mode_off_{false};
257 
262  bool supports_fan_mode_auto_{false};
263 
267  bool supports_fan_mode_low_{false};
268  bool supports_fan_mode_medium_{false};
269  bool supports_fan_mode_high_{false};
270  bool supports_fan_mode_middle_{false};
271  bool supports_fan_mode_focus_{false};
272  bool supports_fan_mode_diffuse_{false};
273 
277  bool supports_swing_mode_both_{false};
278  bool supports_swing_mode_off_{false};
279  bool supports_swing_mode_horizontal_{false};
280  bool supports_swing_mode_vertical_{false};
281 
285  bool supports_two_points_{false};
286 
288  bool cooling_max_runtime_exceeded_{false};
289  bool heating_max_runtime_exceeded_{false};
290 
292  bool use_startup_delay_{false};
293 
295  bool setup_complete_{false};
296 
302  Trigger<> *cool_action_trigger_{nullptr};
303  Trigger<> *supplemental_cool_action_trigger_{nullptr};
304  Trigger<> *cool_mode_trigger_{nullptr};
305 
310  Trigger<> *dry_action_trigger_{nullptr};
311  Trigger<> *dry_mode_trigger_{nullptr};
312 
318  Trigger<> *heat_action_trigger_{nullptr};
319  Trigger<> *supplemental_heat_action_trigger_{nullptr};
320  Trigger<> *heat_mode_trigger_{nullptr};
321 
326  Trigger<> *auto_mode_trigger_{nullptr};
327 
331  Trigger<> *idle_action_trigger_{nullptr};
332  Trigger<> *off_mode_trigger_{nullptr};
333 
338  Trigger<> *fan_only_action_trigger_{nullptr};
339  Trigger<> *fan_only_mode_trigger_{nullptr};
340 
342  Trigger<> *fan_mode_on_trigger_{nullptr};
343 
345  Trigger<> *fan_mode_off_trigger_{nullptr};
346 
348  Trigger<> *fan_mode_auto_trigger_{nullptr};
349 
351  Trigger<> *fan_mode_low_trigger_{nullptr};
352 
354  Trigger<> *fan_mode_medium_trigger_{nullptr};
355 
357  Trigger<> *fan_mode_high_trigger_{nullptr};
358 
360  Trigger<> *fan_mode_middle_trigger_{nullptr};
361 
363  Trigger<> *fan_mode_focus_trigger_{nullptr};
364 
366  Trigger<> *fan_mode_diffuse_trigger_{nullptr};
367 
369  Trigger<> *swing_mode_both_trigger_{nullptr};
370 
372  Trigger<> *swing_mode_off_trigger_{nullptr};
373 
375  Trigger<> *swing_mode_horizontal_trigger_{nullptr};
376 
378  Trigger<> *swing_mode_vertical_trigger_{nullptr};
379 
381  Trigger<> *temperature_change_trigger_{nullptr};
382 
384  Trigger<> *preset_change_trigger_{nullptr};
385 
390  Trigger<> *prev_action_trigger_{nullptr};
391  Trigger<> *prev_fan_mode_trigger_{nullptr};
392  Trigger<> *prev_mode_trigger_{nullptr};
393  Trigger<> *prev_swing_mode_trigger_{nullptr};
394 
403 
407  float prev_target_temperature_{NAN};
408  float prev_target_temperature_low_{NAN};
409  float prev_target_temperature_high_{NAN};
410 
412  float set_point_minimum_differential_{0};
413 
415  float cooling_deadband_{0};
416  float cooling_overrun_{0};
417  float heating_deadband_{0};
418  float heating_overrun_{0};
419 
421  float supplemental_cool_delta_{0};
422  float supplemental_heat_delta_{0};
423 
425  const uint8_t min_timer_duration_{1};
426 
428  std::vector<ThermostatClimateTimer> timer_{
429  {"cool_run", false, 0, std::bind(&ThermostatClimate::cooling_max_run_time_timer_callback_, this)},
430  {"cool_off", false, 0, std::bind(&ThermostatClimate::cooling_off_timer_callback_, this)},
431  {"cool_on", false, 0, std::bind(&ThermostatClimate::cooling_on_timer_callback_, this)},
432  {"fan_mode", false, 0, std::bind(&ThermostatClimate::fan_mode_timer_callback_, this)},
433  {"fan_off", false, 0, std::bind(&ThermostatClimate::fanning_off_timer_callback_, this)},
434  {"fan_on", false, 0, std::bind(&ThermostatClimate::fanning_on_timer_callback_, this)},
435  {"heat_run", false, 0, std::bind(&ThermostatClimate::heating_max_run_time_timer_callback_, this)},
436  {"heat_off", false, 0, std::bind(&ThermostatClimate::heating_off_timer_callback_, this)},
437  {"heat_on", false, 0, std::bind(&ThermostatClimate::heating_on_timer_callback_, this)},
438  {"idle_on", false, 0, std::bind(&ThermostatClimate::idle_on_timer_callback_, this)}};
439 
441  std::map<climate::ClimatePreset, ThermostatClimateTargetTempConfig> preset_config_{};
443  std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
444 };
445 
446 } // namespace thermostat
447 } // namespace esphome
void setup()
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
The climate device is off (inactive or no power)
Definition: climate_mode.h:33
BedjetMode mode
BedJet operating mode.
Definition: bedjet_base.h:102
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:80
void set_fan_mode(climate::ClimateFanMode fan_mode)
This class contains all static data for climate devices.
void set_swing_mode(climate::ClimateSwingMode swing_mode)
ClimateSwingMode swing_mode
Definition: climate.h:548
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:68
void cooling_max_run_time_timer_callback_()
set_timeout() callbacks for various actions (see above)
uint8_t custom_preset
Definition: climate.h:546
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
Definition: climate_mode.h:31
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:70
The climate device is off.
Definition: climate_mode.h:12
ClimateFanMode fan_mode
Definition: climate.h:540
The fan mode is set to On.
Definition: climate_mode.h:48
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:47
ClimatePreset preset
Definition: climate.h:545
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167