ESPHome  2021.11.3
thermostat_climate.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace thermostat {
10 
22 };
23 
25  const std::string name;
26  bool active;
27  uint32_t time;
28  std::function<void()> func;
29 };
30 
32  public:
34  ThermostatClimateTargetTempConfig(float default_temperature);
35  ThermostatClimateTargetTempConfig(float default_temperature_low, float default_temperature_high);
36 
37  float default_temperature{NAN};
38  float default_temperature_low{NAN};
39  float default_temperature_high{NAN};
40  float cool_deadband_{NAN};
41  float cool_overrun_{NAN};
42  float heat_deadband_{NAN};
43  float heat_overrun_{NAN};
44 };
45 
47  public:
49  void setup() override;
50  void dump_config() override;
51 
52  void set_default_mode(climate::ClimateMode default_mode);
53  void set_set_point_minimum_differential(float differential);
54  void set_cool_deadband(float deadband);
55  void set_cool_overrun(float overrun);
56  void set_heat_deadband(float deadband);
57  void set_heat_overrun(float overrun);
58  void set_supplemental_cool_delta(float delta);
59  void set_supplemental_heat_delta(float delta);
60  void set_cooling_maximum_run_time_in_sec(uint32_t time);
61  void set_heating_maximum_run_time_in_sec(uint32_t time);
62  void set_cooling_minimum_off_time_in_sec(uint32_t time);
63  void set_cooling_minimum_run_time_in_sec(uint32_t time);
64  void set_fan_mode_minimum_switching_time_in_sec(uint32_t time);
65  void set_fanning_minimum_off_time_in_sec(uint32_t time);
66  void set_fanning_minimum_run_time_in_sec(uint32_t time);
67  void set_heating_minimum_off_time_in_sec(uint32_t time);
68  void set_heating_minimum_run_time_in_sec(uint32_t time);
69  void set_idle_minimum_time_in_sec(uint32_t time);
70  void set_sensor(sensor::Sensor *sensor);
71  void set_use_startup_delay(bool use_startup_delay);
72  void set_supports_auto(bool supports_auto);
73  void set_supports_heat_cool(bool supports_heat_cool);
74  void set_supports_cool(bool supports_cool);
75  void set_supports_dry(bool supports_dry);
76  void set_supports_fan_only(bool supports_fan_only);
77  void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer);
78  void set_supports_fan_only_cooling(bool supports_fan_only_cooling);
79  void set_supports_fan_with_cooling(bool supports_fan_with_cooling);
80  void set_supports_fan_with_heating(bool supports_fan_with_heating);
81  void set_supports_heat(bool supports_heat);
82  void set_supports_fan_mode_on(bool supports_fan_mode_on);
83  void set_supports_fan_mode_off(bool supports_fan_mode_off);
84  void set_supports_fan_mode_auto(bool supports_fan_mode_auto);
85  void set_supports_fan_mode_low(bool supports_fan_mode_low);
86  void set_supports_fan_mode_medium(bool supports_fan_mode_medium);
87  void set_supports_fan_mode_high(bool supports_fan_mode_high);
88  void set_supports_fan_mode_middle(bool supports_fan_mode_middle);
89  void set_supports_fan_mode_focus(bool supports_fan_mode_focus);
90  void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse);
91  void set_supports_swing_mode_both(bool supports_swing_mode_both);
92  void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal);
93  void set_supports_swing_mode_off(bool supports_swing_mode_off);
94  void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical);
95  void set_supports_two_points(bool supports_two_points);
96 
97  void set_normal_config(const ThermostatClimateTargetTempConfig &normal_config);
98  void set_away_config(const ThermostatClimateTargetTempConfig &away_config);
99 
100  Trigger<> *get_cool_action_trigger() const;
101  Trigger<> *get_supplemental_cool_action_trigger() const;
102  Trigger<> *get_dry_action_trigger() const;
103  Trigger<> *get_fan_only_action_trigger() const;
104  Trigger<> *get_heat_action_trigger() const;
105  Trigger<> *get_supplemental_heat_action_trigger() const;
106  Trigger<> *get_idle_action_trigger() const;
107  Trigger<> *get_auto_mode_trigger() const;
108  Trigger<> *get_cool_mode_trigger() const;
109  Trigger<> *get_dry_mode_trigger() const;
110  Trigger<> *get_fan_only_mode_trigger() const;
111  Trigger<> *get_heat_mode_trigger() const;
112  Trigger<> *get_off_mode_trigger() const;
113  Trigger<> *get_fan_mode_on_trigger() const;
114  Trigger<> *get_fan_mode_off_trigger() const;
115  Trigger<> *get_fan_mode_auto_trigger() const;
116  Trigger<> *get_fan_mode_low_trigger() const;
117  Trigger<> *get_fan_mode_medium_trigger() const;
118  Trigger<> *get_fan_mode_high_trigger() const;
119  Trigger<> *get_fan_mode_middle_trigger() const;
120  Trigger<> *get_fan_mode_focus_trigger() const;
121  Trigger<> *get_fan_mode_diffuse_trigger() const;
122  Trigger<> *get_swing_mode_both_trigger() const;
123  Trigger<> *get_swing_mode_horizontal_trigger() const;
124  Trigger<> *get_swing_mode_off_trigger() const;
125  Trigger<> *get_swing_mode_vertical_trigger() const;
126  Trigger<> *get_temperature_change_trigger() const;
128  float cool_deadband();
129  float cool_overrun();
130  float heat_deadband();
131  float heat_overrun();
133  void refresh();
135  bool climate_action_change_delayed();
136  bool fan_mode_change_delayed();
138  climate::ClimateAction delayed_climate_action();
140  climate::ClimateFanMode locked_fan_mode();
142  bool hysteresis_valid(); // returns true if valid
143  void validate_target_temperature();
144  void validate_target_temperatures();
145  void validate_target_temperature_low();
146  void validate_target_temperature_high();
147 
148  protected:
150  void control(const climate::ClimateCall &call) override;
151 
153  void change_away_(bool away);
154 
156  climate::ClimateTraits traits() override;
157 
159  climate::ClimateAction compute_action_(bool ignore_timers = false);
160  climate::ClimateAction compute_supplemental_action_();
161 
163  void switch_to_action_(climate::ClimateAction action, bool publish_state = true);
164  void switch_to_supplemental_action_(climate::ClimateAction action);
165  void trigger_supplemental_action_();
166 
168  void switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state = true);
169 
171  void switch_to_mode_(climate::ClimateMode mode, bool publish_state = true);
172 
174  void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state = true);
175 
177  void check_temperature_change_trigger_();
178 
180  bool idle_action_ready_();
181  bool cooling_action_ready_();
182  bool drying_action_ready_();
183  bool fan_mode_ready_();
184  bool fanning_action_ready_();
185  bool heating_action_ready_();
186 
188  void start_timer_(ThermostatClimateTimerIndex timer_index);
189  bool cancel_timer_(ThermostatClimateTimerIndex timer_index);
190  bool timer_active_(ThermostatClimateTimerIndex timer_index);
191  uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index);
192  std::function<void()> timer_cbf_(ThermostatClimateTimerIndex timer_index);
193 
195  void cooling_max_run_time_timer_callback_();
196  void cooling_off_timer_callback_();
197  void cooling_on_timer_callback_();
198  void fan_mode_timer_callback_();
199  void fanning_off_timer_callback_();
200  void fanning_on_timer_callback_();
201  void heating_max_run_time_timer_callback_();
202  void heating_off_timer_callback_();
203  void heating_on_timer_callback_();
204  void idle_on_timer_callback_();
205 
207  bool cooling_required_();
208  bool fanning_required_();
209  bool heating_required_();
210  bool supplemental_cooling_required_();
211  bool supplemental_heating_required_();
212 
214  sensor::Sensor *sensor_{nullptr};
215 
220  bool supports_auto_{false};
221  bool supports_heat_cool_{false};
222  bool supports_cool_{false};
223  bool supports_dry_{false};
224  bool supports_fan_only_{false};
225  bool supports_heat_{false};
227  bool supports_fan_only_action_uses_fan_mode_timer_{false};
229  bool supports_fan_only_cooling_{false};
231  bool supports_fan_with_cooling_{false};
232  bool supports_fan_with_heating_{false};
233 
238  bool supports_fan_mode_on_{false};
239  bool supports_fan_mode_off_{false};
240 
245  bool supports_fan_mode_auto_{false};
246 
250  bool supports_fan_mode_low_{false};
251  bool supports_fan_mode_medium_{false};
252  bool supports_fan_mode_high_{false};
253  bool supports_fan_mode_middle_{false};
254  bool supports_fan_mode_focus_{false};
255  bool supports_fan_mode_diffuse_{false};
256 
260  bool supports_swing_mode_both_{false};
261  bool supports_swing_mode_off_{false};
262  bool supports_swing_mode_horizontal_{false};
263  bool supports_swing_mode_vertical_{false};
264 
268  bool supports_two_points_{false};
269 
273  bool supports_away_{false};
274 
276  bool cooling_max_runtime_exceeded_{false};
277  bool heating_max_runtime_exceeded_{false};
278 
280  bool use_startup_delay_{false};
281 
283  bool setup_complete_{false};
284 
290  Trigger<> *cool_action_trigger_{nullptr};
291  Trigger<> *supplemental_cool_action_trigger_{nullptr};
292  Trigger<> *cool_mode_trigger_{nullptr};
293 
298  Trigger<> *dry_action_trigger_{nullptr};
299  Trigger<> *dry_mode_trigger_{nullptr};
300 
306  Trigger<> *heat_action_trigger_{nullptr};
307  Trigger<> *supplemental_heat_action_trigger_{nullptr};
308  Trigger<> *heat_mode_trigger_{nullptr};
309 
314  Trigger<> *auto_mode_trigger_{nullptr};
315 
319  Trigger<> *idle_action_trigger_{nullptr};
320  Trigger<> *off_mode_trigger_{nullptr};
321 
326  Trigger<> *fan_only_action_trigger_{nullptr};
327  Trigger<> *fan_only_mode_trigger_{nullptr};
328 
330  Trigger<> *fan_mode_on_trigger_{nullptr};
331 
333  Trigger<> *fan_mode_off_trigger_{nullptr};
334 
336  Trigger<> *fan_mode_auto_trigger_{nullptr};
337 
339  Trigger<> *fan_mode_low_trigger_{nullptr};
340 
342  Trigger<> *fan_mode_medium_trigger_{nullptr};
343 
345  Trigger<> *fan_mode_high_trigger_{nullptr};
346 
348  Trigger<> *fan_mode_middle_trigger_{nullptr};
349 
351  Trigger<> *fan_mode_focus_trigger_{nullptr};
352 
354  Trigger<> *fan_mode_diffuse_trigger_{nullptr};
355 
357  Trigger<> *swing_mode_both_trigger_{nullptr};
358 
360  Trigger<> *swing_mode_off_trigger_{nullptr};
361 
363  Trigger<> *swing_mode_horizontal_trigger_{nullptr};
364 
366  Trigger<> *swing_mode_vertical_trigger_{nullptr};
367 
369  Trigger<> *temperature_change_trigger_{nullptr};
370 
375  Trigger<> *prev_action_trigger_{nullptr};
376  Trigger<> *prev_fan_mode_trigger_{nullptr};
377  Trigger<> *prev_mode_trigger_{nullptr};
378  Trigger<> *prev_swing_mode_trigger_{nullptr};
379 
388 
392  float prev_target_temperature_{NAN};
393  float prev_target_temperature_low_{NAN};
394  float prev_target_temperature_high_{NAN};
395 
397  float set_point_minimum_differential_{0};
398 
400  float cooling_deadband_{0};
401  float cooling_overrun_{0};
402  float heating_deadband_{0};
403  float heating_overrun_{0};
404 
406  float supplemental_cool_delta_{0};
407  float supplemental_heat_delta_{0};
408 
410  const uint8_t min_timer_duration_{1};
411 
415 
417  std::vector<ThermostatClimateTimer> timer_{
418  {"cool_run", false, 0, std::bind(&ThermostatClimate::cooling_max_run_time_timer_callback_, this)},
419  {"cool_off", false, 0, std::bind(&ThermostatClimate::cooling_off_timer_callback_, this)},
420  {"cool_on", false, 0, std::bind(&ThermostatClimate::cooling_on_timer_callback_, this)},
421  {"fan_mode", false, 0, std::bind(&ThermostatClimate::fan_mode_timer_callback_, this)},
422  {"fan_off", false, 0, std::bind(&ThermostatClimate::fanning_off_timer_callback_, this)},
423  {"fan_on", false, 0, std::bind(&ThermostatClimate::fanning_on_timer_callback_, this)},
424  {"heat_run", false, 0, std::bind(&ThermostatClimate::heating_max_run_time_timer_callback_, this)},
425  {"heat_off", false, 0, std::bind(&ThermostatClimate::heating_off_timer_callback_, this)},
426  {"heat_on", false, 0, std::bind(&ThermostatClimate::heating_on_timer_callback_, this)},
427  {"idle_on", false, 0, std::bind(&ThermostatClimate::idle_on_timer_callback_, this)}};
428 };
429 
430 } // namespace thermostat
431 } // 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
This class contains all static data for climate devices.
ClimateSwingMode swing_mode
Definition: climate.h:545
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)
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:537
The fan mode is set to On.
Definition: climate_mode.h:48
ClimateMode mode
Definition: climate.h:534
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:47
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167