ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
thermostat_climate.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
9
10#include <array>
11#include <cinttypes>
12
13namespace esphome::thermostat {
14
21
35
36enum OnBootRestoreFrom : uint8_t {
37 MEMORY = 0,
39};
40
44
45 bool active;
46 uint32_t time;
47 uint32_t started;
48};
49
71
77
83
85 public:
88
90 void setup() override;
91 void dump_config() override;
92 void loop() override;
93
94 void set_default_preset(const char *custom_preset);
96 void set_on_boot_restore_from(OnBootRestoreFrom on_boot_restore_from);
97 void set_set_point_minimum_differential(float differential);
98 void set_cool_deadband(float deadband);
99 void set_cool_overrun(float overrun);
100 void set_heat_deadband(float deadband);
101 void set_heat_overrun(float overrun);
102 void set_supplemental_cool_delta(float delta);
103 void set_supplemental_heat_delta(float delta);
104 void set_cooling_maximum_run_time_in_sec(uint32_t time);
105 void set_heating_maximum_run_time_in_sec(uint32_t time);
106 void set_cooling_minimum_off_time_in_sec(uint32_t time);
107 void set_cooling_minimum_run_time_in_sec(uint32_t time);
109 void set_fanning_minimum_off_time_in_sec(uint32_t time);
110 void set_fanning_minimum_run_time_in_sec(uint32_t time);
111 void set_heating_minimum_off_time_in_sec(uint32_t time);
112 void set_heating_minimum_run_time_in_sec(uint32_t time);
113 void set_idle_minimum_time_in_sec(uint32_t time);
114 void set_sensor(sensor::Sensor *sensor);
115 void set_humidity_sensor(sensor::Sensor *humidity_sensor);
116 void set_humidity_hysteresis(float humidity_hysteresis);
117 void set_use_startup_delay(bool use_startup_delay);
118 void set_supports_auto(bool supports_auto);
119 void set_supports_heat_cool(bool supports_heat_cool);
120 void set_supports_cool(bool supports_cool);
121 void set_supports_dry(bool supports_dry);
122 void set_supports_fan_only(bool supports_fan_only);
123 void set_supports_fan_only_action_uses_fan_mode_timer(bool fan_only_action_uses_fan_mode_timer);
124 void set_supports_fan_only_cooling(bool supports_fan_only_cooling);
125 void set_supports_fan_with_cooling(bool supports_fan_with_cooling);
126 void set_supports_fan_with_heating(bool supports_fan_with_heating);
127 void set_supports_heat(bool supports_heat);
128 void set_supports_fan_mode_on(bool supports_fan_mode_on);
129 void set_supports_fan_mode_off(bool supports_fan_mode_off);
130 void set_supports_fan_mode_auto(bool supports_fan_mode_auto);
131 void set_supports_fan_mode_low(bool supports_fan_mode_low);
132 void set_supports_fan_mode_medium(bool supports_fan_mode_medium);
133 void set_supports_fan_mode_high(bool supports_fan_mode_high);
134 void set_supports_fan_mode_middle(bool supports_fan_mode_middle);
135 void set_supports_fan_mode_focus(bool supports_fan_mode_focus);
136 void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse);
137 void set_supports_fan_mode_quiet(bool supports_fan_mode_quiet);
138 void set_supports_swing_mode_both(bool supports_swing_mode_both);
139 void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal);
140 void set_supports_swing_mode_off(bool supports_swing_mode_off);
141 void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical);
142 void set_supports_dehumidification(bool supports_dehumidification);
143 void set_supports_humidification(bool supports_humidification);
144 void set_supports_two_points(bool supports_two_points);
145
146 void set_preset_config(std::initializer_list<PresetEntry> presets);
147 void set_custom_preset_config(std::initializer_list<CustomPresetEntry> presets);
148
184 float cool_deadband();
185 float cool_overrun();
186 float heat_deadband();
187 float heat_overrun();
189 void refresh();
198 bool hysteresis_valid(); // returns true if valid
199 bool humidity_hysteresis_valid(); // returns true if valid
200 bool limit_setpoints_for_heat_cool(); // returns true if set points should be further limited within visual range
202 void validate_target_temperatures(bool pin_target_temperature_high);
206
209
210 protected:
212 void control(const climate::ClimateCall &call) override;
213
217 void change_custom_preset_(const char *custom_preset);
218
223
226
228 climate::ClimateAction compute_action_(bool ignore_timers = false);
231
237
240
243
246
249
252
254 bool idle_action_ready_();
257 bool fan_mode_ready_();
260
265 uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index);
269 void set_timer_duration_in_sec_(ThermostatClimateTimerIndex timer_index, uint32_t time);
270
282
284 bool cooling_required_();
285 bool fanning_required_();
286 bool heating_required_();
291
292 void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config);
293
295 const uint8_t min_timer_duration_{1};
296
303
306
309
313
318 bool supports_auto_{false};
320 bool supports_cool_{false};
321 bool supports_dry_{false};
323 bool supports_heat_{false};
331
338
344
355
363
368
374
378
381
383 bool setup_complete_{false};
384
392
395
401
404
408
413
422
429
438
444
450
456
463
466
469
472
475
478
481
484
487
490
493
496
499
502
505
508
511
514
517
520
523
533
535 std::array<ThermostatClimateTimer, THERMOSTAT_TIMER_COUNT> timer_{};
536
541
542 private:
544 const char *default_custom_preset_{nullptr};
545};
546
547} // namespace esphome::thermostat
BedjetMode mode
BedJet operating mode.
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:184
This class is used to encode all control actions on a climate device.
Definition climate.h:32
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:181
ClimateMode mode
The active mode of the climate device.
Definition climate.h:261
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:255
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:267
ClimateAction action
The active state of the climate device.
Definition climate.h:264
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:438
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:258
Base-class for all sensors.
Definition sensor.h:43
Trigger * swing_mode_off_trigger_
The trigger to call when the controller should switch the swing mode to "off".
void set_supports_humidification(bool supports_humidification)
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_custom_preset_config(std::initializer_list< CustomPresetEntry > presets)
void set_supports_fan_mode_on(bool supports_fan_mode_on)
FixedVector< CustomPresetEntry > custom_preset_config_
The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
Trigger * preset_change_trigger_
The trigger 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.
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
void validate_target_temperatures(bool pin_target_temperature_high)
HumidificationAction humidification_action
The current humidification action.
void set_timer_duration_in_sec_(ThermostatClimateTimerIndex timer_index, uint32_t time)
Enhanced timer duration setter with running timer adjustment.
Trigger * humidity_control_dehumidify_action_trigger_
The trigger to call when dehumidification is required.
bool use_startup_delay_
Used to start "off" delay timers at boot.
void set_on_boot_restore_from(OnBootRestoreFrom on_boot_restore_from)
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.
OnBootRestoreFrom on_boot_restore_from_
If set to DEFAULT_PRESET then the default preset is always used.
void change_custom_preset_(const char *custom_preset)
Change to a provided custom preset setting; will reset temperature, mode, fan, and swing modes accord...
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_preset_config(std::initializer_list< PresetEntry > presets)
void set_supports_fan_only_cooling(bool supports_fan_only_cooling)
bool supports_dehumidification_
Whether the controller supports dehumidification and/or humidification.
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)
Trigger * humidity_control_off_action_trigger_
The trigger to call when (de)humidification should stop.
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".
bool change_preset_internal_(const ThermostatClimateTargetTempConfig &config)
Applies the temperature, mode, fan, and swing modes of the provided config.
void set_supports_dehumidification(bool supports_dehumidification)
bool hysteresis_valid()
Set point and hysteresis validation.
float humidity_hysteresis_
Hysteresis values used for computing humidification action.
void set_supports_fan_mode_auto(bool supports_fan_mode_auto)
float prev_target_humidity_
Store previously-known humidity and temperatures.
void check_humidity_change_trigger_()
Check if the humidity change trigger should be called.
Trigger * humidity_control_humidify_action_trigger_
The trigger to call when humidification is required.
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 switch_to_humidity_control_action_(HumidificationAction 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.
void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config)
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 engaging supplemental cooling/heating actions.
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_default_preset(const char *custom_preset)
void call_timer_callback_(ThermostatClimateTimerIndex timer_index)
Call the appropriate timer callback based on timer index.
void set_supports_fan_mode_medium(bool supports_fan_mode_medium)
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 set_set_point_minimum_differential(float differential)
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_
The current supplemental action.
std::array< ThermostatClimateTimer, THERMOSTAT_TIMER_COUNT > timer_
Climate action timers.
void set_fan_mode_minimum_switching_time_in_sec(uint32_t time)
Trigger * humidity_change_trigger_
The trigger to call when the target humidity changes.
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.
HumidificationAction compute_humidity_control_action_()
void set_supports_fan_mode_off(bool supports_fan_mode_off)
FixedVector< PresetEntry > preset_config_
The set of standard preset configurations this thermostat supports (Eg. AWAY, ECO,...
climate::ClimateFanMode prev_fan_mode_
Store previously-known states.
void set_use_startup_delay(bool use_startup_delay)
void set_humidity_hysteresis(float humidity_hysteresis)
bool cancel_timer_(ThermostatClimateTimerIndex timer_index)
climate::ClimateAction compute_supplemental_action_()
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.
bool supports_two_points_
Whether the controller supports two set points.
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)
Trigger * fan_mode_quiet_trigger_
The trigger to call when the controller should switch the fan to "quiet" position.
Trigger * heat_cool_mode_trigger_
The trigger to call when the controller should switch to heat/cool mode.
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
uint8_t custom_preset
Definition climate.h:9
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
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)
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_ON
The fan mode is set to On.
void set_swing_mode(climate::ClimateSwingMode swing_mode)
optional< climate::ClimateSwingMode > swing_mode_
void set_fan_mode(climate::ClimateFanMode fan_mode)
ThermostatClimateTimer(bool active, uint32_t time, uint32_t started)
Entry for custom preset lookup.
const char * name
ThermostatClimateTargetTempConfig config
Entry for standard preset lookup.
ThermostatClimateTargetTempConfig config
climate::ClimatePreset preset