ESPHome 2025.5.0
Loading...
Searching...
No Matches
thermostat_climate.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
8
9#include <cinttypes>
10#include <map>
11#include <vector>
12
13namespace esphome {
14namespace thermostat {
15
28
29enum OnBootRestoreFrom : size_t { MEMORY = 0, DEFAULT_PRESET = 1 };
31 bool active;
32 uint32_t time;
33 uint32_t started;
34 std::function<void()> func;
35};
36
58
60 public:
62 void setup() override;
63 void dump_config() override;
64 void loop() override;
65
66 void set_default_preset(const std::string &custom_preset);
69 void set_set_point_minimum_differential(float differential);
70 void set_cool_deadband(float deadband);
71 void set_cool_overrun(float overrun);
72 void set_heat_deadband(float deadband);
73 void set_heat_overrun(float overrun);
74 void set_supplemental_cool_delta(float delta);
75 void set_supplemental_heat_delta(float delta);
76 void set_cooling_maximum_run_time_in_sec(uint32_t time);
77 void set_heating_maximum_run_time_in_sec(uint32_t time);
78 void set_cooling_minimum_off_time_in_sec(uint32_t time);
79 void set_cooling_minimum_run_time_in_sec(uint32_t time);
81 void set_fanning_minimum_off_time_in_sec(uint32_t time);
82 void set_fanning_minimum_run_time_in_sec(uint32_t time);
83 void set_heating_minimum_off_time_in_sec(uint32_t time);
84 void set_heating_minimum_run_time_in_sec(uint32_t time);
85 void set_idle_minimum_time_in_sec(uint32_t time);
86 void set_sensor(sensor::Sensor *sensor);
87 void set_humidity_sensor(sensor::Sensor *humidity_sensor);
88 void set_use_startup_delay(bool use_startup_delay);
89 void set_supports_auto(bool supports_auto);
90 void set_supports_heat_cool(bool supports_heat_cool);
91 void set_supports_cool(bool supports_cool);
92 void set_supports_dry(bool supports_dry);
93 void set_supports_fan_only(bool supports_fan_only);
94 void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer);
95 void set_supports_fan_only_cooling(bool supports_fan_only_cooling);
96 void set_supports_fan_with_cooling(bool supports_fan_with_cooling);
97 void set_supports_fan_with_heating(bool supports_fan_with_heating);
98 void set_supports_heat(bool supports_heat);
99 void set_supports_fan_mode_on(bool supports_fan_mode_on);
100 void set_supports_fan_mode_off(bool supports_fan_mode_off);
101 void set_supports_fan_mode_auto(bool supports_fan_mode_auto);
102 void set_supports_fan_mode_low(bool supports_fan_mode_low);
103 void set_supports_fan_mode_medium(bool supports_fan_mode_medium);
104 void set_supports_fan_mode_high(bool supports_fan_mode_high);
105 void set_supports_fan_mode_middle(bool supports_fan_mode_middle);
106 void set_supports_fan_mode_focus(bool supports_fan_mode_focus);
107 void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse);
108 void set_supports_fan_mode_quiet(bool supports_fan_mode_quiet);
109 void set_supports_swing_mode_both(bool supports_swing_mode_both);
110 void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal);
111 void set_supports_swing_mode_off(bool supports_swing_mode_off);
112 void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical);
113 void set_supports_two_points(bool supports_two_points);
114
116 void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config);
117
148 float cool_deadband();
149 float cool_overrun();
150 float heat_deadband();
151 float heat_overrun();
153 void refresh();
162 bool hysteresis_valid(); // returns true if valid
167
168 protected:
170 void control(const climate::ClimateCall &call) override;
171
175 void change_custom_preset_(const std::string &custom_preset);
176
181
184
186 climate::ClimateAction compute_action_(bool ignore_timers = false);
188
193
196
199
202
205
207 bool idle_action_ready_();
210 bool fan_mode_ready_();
213
218 uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index);
219 std::function<void()> timer_cbf_(ThermostatClimateTimerIndex timer_index);
220
232
234 bool cooling_required_();
235 bool fanning_required_();
236 bool heating_required_();
239
240 void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config,
241 bool is_default_preset);
242
247
252 bool supports_auto_{false};
254 bool supports_cool_{false};
255 bool supports_dry_{false};
257 bool supports_heat_{false};
265
272
278
289
297
302
306
309
311 bool setup_complete_{false};
312
321
328
337
343
349
356
359
362
365
368
371
374
377
380
383
386
389
392
395
398
401
404
413
421
428
431
437
441
443 const uint8_t min_timer_duration_{1};
444
446 std::vector<ThermostatClimateTimer> timer_{
447 {false, 0, 0, std::bind(&ThermostatClimate::cooling_max_run_time_timer_callback_, this)},
448 {false, 0, 0, std::bind(&ThermostatClimate::cooling_off_timer_callback_, this)},
449 {false, 0, 0, std::bind(&ThermostatClimate::cooling_on_timer_callback_, this)},
450 {false, 0, 0, std::bind(&ThermostatClimate::fan_mode_timer_callback_, this)},
451 {false, 0, 0, std::bind(&ThermostatClimate::fanning_off_timer_callback_, this)},
452 {false, 0, 0, std::bind(&ThermostatClimate::fanning_on_timer_callback_, this)},
453 {false, 0, 0, std::bind(&ThermostatClimate::heating_max_run_time_timer_callback_, this)},
454 {false, 0, 0, std::bind(&ThermostatClimate::heating_off_timer_callback_, this)},
455 {false, 0, 0, std::bind(&ThermostatClimate::heating_on_timer_callback_, this)},
456 {false, 0, 0, std::bind(&ThermostatClimate::idle_on_timer_callback_, this)},
457 };
458
460 std::map<climate::ClimatePreset, ThermostatClimateTargetTempConfig> preset_config_{};
462 std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
463
468
472};
473
474} // namespace thermostat
475} // namespace esphome
BedjetMode mode
BedJet operating mode.
This class is used to encode all control actions on a climate device.
Definition climate.h:33
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:168
ClimateMode mode
The active mode of the climate device.
Definition climate.h:173
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:199
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:202
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition climate.h:211
ClimateAction action
The active state of the climate device.
Definition climate.h:176
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:395
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:208
This class contains all static data for climate devices.
Base-class for all sensors.
Definition sensor.h:57
Trigger * swing_mode_off_trigger_
The trigger to call when the controller should switch the swing mode to "off".
void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal)
Trigger * idle_action_trigger_
The trigger to call when the controller should switch to idle action/off mode.
void switch_to_action_(climate::ClimateAction action, bool publish_state=true)
Switch the climate device to the given climate action.
void set_supports_fan_mode_on(bool supports_fan_mode_on)
Trigger * preset_change_trigger_
The triggr to call when the preset mode changes.
float cooling_deadband_
Hysteresis values used for computing climate actions.
Trigger * heat_action_trigger_
The trigger to call when the controller should switch to heating action/mode.
thermostat::OnBootRestoreFrom on_boot_restore_from_
If set to DEFAULT_PRESET then the default preset is always used.
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
bool use_startup_delay_
Used to start "off" delay timers at boot.
float cool_deadband()
Get current hysteresis values.
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)
bool cooling_max_runtime_exceeded_
Flags indicating if maximum allowable run time was exceeded.
const uint8_t min_timer_duration_
Minimum allowable duration in seconds for action timers.
Trigger * fan_mode_low_trigger_
The trigger to call when the controller should switch the fan to "low" speed.
void set_supports_two_points(bool supports_two_points)
Trigger * fan_mode_auto_trigger_
The trigger to call when the controller should switch the fan to "auto" mode.
void set_supports_fan_only_cooling(bool supports_fan_only_cooling)
bool supports_fan_mode_on_
Whether the controller supports turning on or off just the fan.
void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer)
float set_point_minimum_differential_
Minimum differential required between set points.
bool supports_fan_with_cooling_
Special flags – enables fan_only action to be called with cooling/heating actions.
void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse)
void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state=true)
Switch the climate device to the given climate swing mode.
Trigger * fan_mode_diffuse_trigger_
The trigger to call when the controller should switch the fan to "diffuse" position.
Trigger * fan_only_action_trigger_
The trigger to call when the controller should switch to fan-only action/mode.
Trigger * cool_action_trigger_
The trigger to call when the controller should switch to cooling action/mode.
Trigger * swing_mode_vertical_trigger_
The trigger to call when the controller should switch the swing mode to "vertical".
std::vector< ThermostatClimateTimer > timer_
Climate action timers.
bool change_preset_internal_(const ThermostatClimateTargetTempConfig &config)
Applies the temperature, mode, fan, and swing modes of the provided config.
bool hysteresis_valid()
Set point and hysteresis validation.
void set_supports_fan_mode_auto(bool supports_fan_mode_auto)
void switch_to_supplemental_action_(climate::ClimateAction action)
Trigger * dry_action_trigger_
The trigger to call when the controller should switch to dry (dehumidification) mode.
void switch_to_mode_(climate::ClimateMode mode, bool publish_state=true)
Switch the climate device to the given climate mode.
Trigger * swing_mode_both_trigger_
The trigger to call when the controller should switch the swing mode to "both".
void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical)
void set_supports_fan_only(bool supports_fan_only)
bool supports_fan_only_action_uses_fan_mode_timer_
Special flag – enables fan_modes to share timer with fan_only climate action.
void set_supports_swing_mode_off(bool supports_swing_mode_off)
void switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state=true)
Switch the climate device to the given climate fan mode.
bool supports_swing_mode_both_
Whether the controller supports various swing modes.
climate::ClimateTraits traits() override
Return the traits of this controller.
Trigger * swing_mode_horizontal_trigger_
The trigger to call when the controller should switch the swing mode to "horizontal".
Trigger * fan_mode_focus_trigger_
The trigger to call when the controller should switch the fan to "focus" position.
climate::ClimateFanMode locked_fan_mode()
Returns the fan mode that is locked in (check fan_mode_change_delayed(), first!)
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
void set_supports_fan_mode_middle(bool supports_fan_mode_middle)
Trigger * temperature_change_trigger_
The trigger to call when the target temperature(s) change(es).
void set_supports_fan_mode_low(bool supports_fan_mode_low)
Trigger * fan_mode_off_trigger_
The trigger to call when the controller should switch off the fan.
bool timer_active_(ThermostatClimateTimerIndex timer_index)
float supplemental_cool_delta_
Maximum allowable temperature deltas before engauging supplemental cooling/heating actions.
std::map< std::string, ThermostatClimateTargetTempConfig > custom_preset_config_
The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
void set_supports_heat_cool(bool supports_heat_cool)
void set_supports_fan_mode_quiet(bool supports_fan_mode_quiet)
climate::ClimateAction delayed_climate_action()
Returns the climate action that is being delayed (check climate_action_change_delayed(),...
sensor::Sensor * sensor_
The sensor used for getting the current temperature.
void set_supports_fan_mode_medium(bool supports_fan_mode_medium)
void set_on_boot_restore_from(thermostat::OnBootRestoreFrom on_boot_restore_from)
uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index)
void set_supports_swing_mode_both(bool supports_swing_mode_both)
void start_timer_(ThermostatClimateTimerIndex timer_index)
Start/cancel/get status of climate action timer.
Trigger * fan_mode_high_trigger_
The trigger to call when the controller should switch the fan to "high" speed.
void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config, bool is_default_preset)
void set_set_point_minimum_differential(float differential)
void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config)
bool supports_fan_mode_low_
Whether the controller supports various fan speeds and/or positions.
bool supports_fan_only_cooling_
Special flag – enables fan to be switched based on target_temperature_high.
Trigger * prev_action_trigger_
A reference to the trigger that was previously active.
bool supports_auto_
Whether the controller supports auto/cooling/drying/fanning/heating.
climate::ClimateAction supplemental_action_
Store previously-known states.
void set_fan_mode_minimum_switching_time_in_sec(uint32_t time)
void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config)
void set_supports_fan_with_cooling(bool supports_fan_with_cooling)
Trigger * fan_mode_medium_trigger_
The trigger to call when the controller should switch the fan to "medium" speed.
Trigger * fan_mode_middle_trigger_
The trigger to call when the controller should switch the fan to "middle" position.
void set_supports_fan_mode_focus(bool supports_fan_mode_focus)
void check_temperature_change_trigger_()
Check if the temperature change trigger should be called.
Trigger * fan_mode_on_trigger_
The trigger to call when the controller should switch on the fan.
void set_supports_fan_mode_off(bool supports_fan_mode_off)
void set_use_startup_delay(bool use_startup_delay)
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...
bool cancel_timer_(ThermostatClimateTimerIndex timer_index)
climate::ClimateAction compute_supplemental_action_()
float prev_target_temperature_
Store previously-known temperatures.
climate::ClimatePreset default_preset_
Default standard preset to use on start up.
sensor::Sensor * humidity_sensor_
The sensor used for getting the current humidity.
void cooling_max_run_time_timer_callback_()
set_timeout() callbacks for various actions (see above)
bool supports_fan_mode_auto_
Whether the controller supports fan auto mode.
climate::ClimateAction compute_action_(bool ignore_timers=false)
Re-compute the required action of this climate controller.
std::map< climate::ClimatePreset, ThermostatClimateTargetTempConfig > preset_config_
The set of standard preset configurations this thermostat supports (Eg. AWAY, ECO,...
bool supports_two_points_
Whether the controller supports two set points.
std::string default_custom_preset_
Default custom preset to use on start up.
bool setup_complete_
setup_complete_ blocks modifying/resetting the temps immediately after boot
void set_supports_fan_mode_high(bool supports_fan_mode_high)
bool idle_action_ready_()
Is the action ready to be called? Returns true if so.
void change_preset_(climate::ClimatePreset preset)
Change to a provided preset setting; will reset temperature, mode, fan, and swing modes accordingly.
void refresh()
Call triggers based on updated climate states (modes/actions)
void set_default_preset(const std::string &custom_preset)
Trigger * fan_mode_quiet_trigger_
The trigger to call when the controller should switch the fan to "quiet" position.
std::function< void()> timer_cbf_(ThermostatClimateTimerIndex timer_index)
Trigger * auto_mode_trigger_
The trigger to call when the controller should switch to auto mode.
bool cooling_required_()
Check if cooling/fanning/heating actions are required; returns true if so.
ClimateSwingMode swing_mode
Definition climate.h:11
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset
Enum for all preset modes.
ClimateSwingMode
Enum for all modes a climate swing can be in.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_OFF
The climate device is off.
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
@ CLIMATE_ACTION_OFF
The climate device is off (inactive or no power)
@ CLIMATE_FAN_ON
The fan mode is set to On.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void set_swing_mode(climate::ClimateSwingMode swing_mode)
optional< climate::ClimateSwingMode > swing_mode_
void set_fan_mode(climate::ClimateFanMode fan_mode)