ESPHome 2026.11.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
49
79
85
91
92class ThermostatClimate final : public climate::Climate, public Component {
93 public:
96
98 void setup() override;
99 void dump_config() override;
100 void loop() override;
101
102 void set_default_preset(const char *custom_preset);
105 this->on_boot_restore_from_ = on_boot_restore_from;
106 }
107 void set_set_point_minimum_differential(float differential) { this->set_point_minimum_differential_ = differential; }
108 void set_cool_deadband(float deadband) { this->cooling_deadband_ = deadband; }
109 void set_cool_overrun(float overrun) { this->cooling_overrun_ = overrun; }
110 void set_heat_deadband(float deadband) { this->heating_deadband_ = deadband; }
111 void set_heat_overrun(float overrun) { this->heating_overrun_ = overrun; }
112 void set_supplemental_cool_delta(float delta) { this->supplemental_cool_delta_ = delta; }
113 void set_supplemental_heat_delta(float delta) { this->supplemental_heat_delta_ = delta; }
124 void set_sensor(sensor::Sensor *sensor) { this->sensor_ = sensor; }
125 void set_humidity_sensor(sensor::Sensor *humidity_sensor) { this->humidity_sensor_ = humidity_sensor; }
126 void set_humidity_hysteresis(float humidity_hysteresis);
127 void set_use_startup_delay(bool use_startup_delay) { this->use_startup_delay_ = use_startup_delay; }
128 void set_supports_auto(bool supports_auto) { this->supports_auto_ = supports_auto; }
129 void set_supports_heat_cool(bool supports_heat_cool) { this->supports_heat_cool_ = supports_heat_cool; }
130 void set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; }
131 void set_supports_dry(bool supports_dry) { this->supports_dry_ = supports_dry; }
132 void set_supports_fan_only(bool supports_fan_only) { this->supports_fan_only_ = supports_fan_only; }
133 void set_supports_fan_only_action_uses_fan_mode_timer(bool supports_fan_only_action_uses_fan_mode_timer) {
134 this->supports_fan_only_action_uses_fan_mode_timer_ = supports_fan_only_action_uses_fan_mode_timer;
135 }
136 void set_supports_fan_only_cooling(bool supports_fan_only_cooling) {
137 this->supports_fan_only_cooling_ = supports_fan_only_cooling;
138 }
139 void set_supports_fan_with_cooling(bool supports_fan_with_cooling) {
140 this->supports_fan_with_cooling_ = supports_fan_with_cooling;
141 }
142 void set_supports_fan_with_heating(bool supports_fan_with_heating) {
143 this->supports_fan_with_heating_ = supports_fan_with_heating;
144 }
145 void set_supports_heat(bool supports_heat) { this->supports_heat_ = supports_heat; }
146 void set_supports_fan_mode_on(bool supports_fan_mode_on) { this->supports_fan_mode_on_ = supports_fan_mode_on; }
147 void set_supports_fan_mode_off(bool supports_fan_mode_off) { this->supports_fan_mode_off_ = supports_fan_mode_off; }
148 void set_supports_fan_mode_auto(bool supports_fan_mode_auto) {
149 this->supports_fan_mode_auto_ = supports_fan_mode_auto;
150 }
151 void set_supports_fan_mode_low(bool supports_fan_mode_low) { this->supports_fan_mode_low_ = supports_fan_mode_low; }
152 void set_supports_fan_mode_medium(bool supports_fan_mode_medium) {
153 this->supports_fan_mode_medium_ = supports_fan_mode_medium;
154 }
155 void set_supports_fan_mode_high(bool supports_fan_mode_high) {
156 this->supports_fan_mode_high_ = supports_fan_mode_high;
157 }
158 void set_supports_fan_mode_middle(bool supports_fan_mode_middle) {
159 this->supports_fan_mode_middle_ = supports_fan_mode_middle;
160 }
161 void set_supports_fan_mode_focus(bool supports_fan_mode_focus) {
162 this->supports_fan_mode_focus_ = supports_fan_mode_focus;
163 }
164 void set_supports_fan_mode_diffuse(bool supports_fan_mode_diffuse) {
165 this->supports_fan_mode_diffuse_ = supports_fan_mode_diffuse;
166 }
167 void set_supports_fan_mode_quiet(bool supports_fan_mode_quiet) {
168 this->supports_fan_mode_quiet_ = supports_fan_mode_quiet;
169 }
170 void set_supports_swing_mode_both(bool supports_swing_mode_both) {
171 this->supports_swing_mode_both_ = supports_swing_mode_both;
172 }
173 void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal) {
174 this->supports_swing_mode_horizontal_ = supports_swing_mode_horizontal;
175 }
176 void set_supports_swing_mode_off(bool supports_swing_mode_off) {
177 this->supports_swing_mode_off_ = supports_swing_mode_off;
178 }
179 void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical) {
180 this->supports_swing_mode_vertical_ = supports_swing_mode_vertical;
181 }
182 void set_supports_dehumidification(bool supports_dehumidification);
183 void set_supports_humidification(bool supports_humidification);
184 void set_supports_two_points(bool supports_two_points) { this->supports_two_points_ = supports_two_points; }
185
187 void set_preset_config(const PresetEntry *presets, uint8_t count) {
188 this->preset_config_ = presets;
189 this->preset_count_ = count;
190 }
191 void set_custom_preset_config(const CustomPresetEntry *presets, uint8_t count);
192
228 float cool_deadband() { return this->cooling_deadband_; }
229 float cool_overrun() { return this->cooling_overrun_; }
230 float heat_deadband() { return this->heating_deadband_; }
231 float heat_overrun() { return this->heating_overrun_; }
233 void refresh();
242 bool hysteresis_valid(); // returns true if valid
243 bool humidity_hysteresis_valid(); // returns true if valid
244 bool limit_setpoints_for_heat_cool(); // returns true if set points should be further limited within visual range
246 void validate_target_temperatures(bool pin_target_temperature_high);
250
253
254 protected:
256 void control(const climate::ClimateCall &call) override;
257
262 this->change_custom_preset_(custom_preset, strlen(custom_preset));
263 }
264 void change_custom_preset_(const char *custom_preset, size_t len);
268
273
276
278 climate::ClimateAction compute_action_(bool ignore_timers = false);
281
287
290
293
296
299
302
304 bool idle_action_ready_();
307 bool fan_mode_ready_();
310
320
332
334 bool cooling_required_();
335 bool fanning_required_();
336 bool heating_required_();
341
342 void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config);
344 PresetEntry preset_entry_(uint8_t index) const;
345 CustomPresetEntry custom_preset_entry_(uint8_t index) const;
346
348 const uint8_t min_timer_duration_{1};
349
356
359
362
366
367 uint8_t preset_count_{0};
369
374 bool supports_auto_{false};
376 bool supports_cool_{false};
377 bool supports_dry_{false};
379 bool supports_heat_{false};
387
394
400
411
419
424
430
434
437
439 bool setup_complete_{false};
440
448
451
457
460
464
469
474
478
483
486
489
493
497
509
515
518
521
524
529
539
541 std::array<ThermostatClimateTimer, THERMOSTAT_TIMER_COUNT> timer_{};
542
547
548 private:
550 const char *default_custom_preset_{nullptr};
551};
552
553} // namespace esphome::thermostat
BedjetMode mode
BedJet operating mode.
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
constexpr const char * c_str() const
Definition string_ref.h:78
This class is used to encode all control actions on a climate device.
Definition climate.h:31
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:192
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:311
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:323
ClimateAction action
The active state of the climate device.
Definition climate.h:320
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:314
Base-class for all sensors.
Definition sensor.h:47
void set_supports_humidification(bool supports_humidification)
void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal)
void switch_to_action_(climate::ClimateAction action, bool publish_state=true)
Switch the climate device to the given climate action.
void change_custom_preset_(StringRef custom_preset)
void set_supports_fan_mode_on(bool supports_fan_mode_on)
float cooling_deadband_
Hysteresis values used for computing climate actions.
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.
void set_supports_fan_only_action_uses_fan_mode_timer(bool supports_fan_only_action_uses_fan_mode_timer)
bool use_startup_delay_
Used to start "off" delay timers at boot.
Trigger temperature_change_trigger_
Trigger for target temperature changes.
float cool_deadband()
Get current hysteresis values.
bool climate_action_change_delayed()
Returns true if a climate action/fan mode transition is being delayed.
CustomPresetEntry custom_preset_entry_(uint8_t index) const
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.
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)
void set_supports_fan_only_cooling(bool supports_fan_only_cooling)
bool supports_dehumidification_
Whether the controller supports dehumidification and/or humidification.
const CustomPresetEntry * custom_preset_config_
Custom preset configurations (eg. "My Custom Preset"), a PROGMEM table of custom_preset_count_ entrie...
bool supports_fan_mode_on_
Whether the controller supports turning on or off just the fan.
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)
ThermostatCustomPresetEntry CustomPresetEntry
void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state=true)
Switch the climate device to the given climate swing mode.
void set_preset_config(const PresetEntry *presets, uint8_t count)
presets is a PROGMEM table that outlives the thermostat.
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)
Trigger cool_action_trigger_
Trigger for cooling action/mode.
float prev_target_humidity_
Store previously-known humidity and temperatures.
void check_humidity_change_trigger_()
Check if the humidity change trigger should be called.
void switch_to_supplemental_action_(climate::ClimateAction action)
void switch_to_mode_(climate::ClimateMode mode, bool publish_state=true)
Switch the climate device to the given climate mode.
void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical)
void set_custom_preset_config(const CustomPresetEntry *presets, uint8_t count)
void set_supports_fan_only(bool supports_fan_only)
void set_sensor(sensor::Sensor *sensor)
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.
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)
Trigger humidity_change_trigger_
Trigger for target humidity changes.
void set_supports_fan_mode_middle(bool supports_fan_mode_middle)
void set_supports_fan_mode_low(bool supports_fan_mode_low)
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_default_preset(climate::ClimatePreset preset)
void set_supports_fan_mode_medium(bool supports_fan_mode_medium)
Trigger idle_action_trigger_
Trigger for idle action/off mode.
void set_on_boot_restore_from(thermostat::OnBootRestoreFrom on_boot_restore_from)
uint32_t timer_duration_(ThermostatClimateTimerIndex timer_index)
Trigger humidity_control_dehumidify_action_trigger_
Humidity control triggers.
Trigger fan_only_action_trigger_
Trigger for fan-only action/mode.
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.
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.
Trigger swing_mode_both_trigger_
Swing mode triggers.
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 heat_cool_mode_trigger_
Trigger for heat/cool mode.
void set_supports_fan_with_cooling(bool supports_fan_with_cooling)
void set_supports_fan_mode_focus(bool supports_fan_mode_focus)
Trigger preset_change_trigger_
Trigger for preset mode changes.
void check_temperature_change_trigger_()
Check if the temperature change trigger should be called.
HumidificationAction compute_humidity_control_action_()
void set_supports_fan_mode_off(bool supports_fan_mode_off)
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.
const PresetEntry * preset_config_
Standard preset configurations (Eg. AWAY, ECO, etc), a PROGMEM table of preset_count_ entries.
void cooling_max_run_time_timer_callback_()
set_timeout() callbacks for various actions (see above)
PresetEntry preset_entry_(uint8_t index) const
Copies of table entries; the tables live in PROGMEM and hold byte-sized fields.
bool supports_fan_mode_auto_
Whether the controller supports fan auto mode.
Trigger fan_mode_on_trigger_
Fan mode triggers.
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)
Trigger auto_mode_trigger_
Trigger for auto mode.
bool idle_action_ready_()
Is the action ready to be called? Returns true if so.
Trigger dry_action_trigger_
Trigger for dry (dehumidification) mode.
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 heat_action_trigger_
Trigger for heating action/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
unsigned count
Definition gif.cpp:51
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.
const void size_t len
Definition hal.h:68
static void uint32_t
void set_swing_mode(climate::ClimateSwingMode swing_mode)
optional< climate::ClimateSwingMode > swing_mode_
constexpr ThermostatClimateTargetTempConfig(float default_temperature)
constexpr ThermostatClimateTargetTempConfig(float default_temperature, float default_temperature_low, float default_temperature_high, optional< climate::ClimateMode > mode, optional< climate::ClimateFanMode > fan_mode, optional< climate::ClimateSwingMode > swing_mode)
Full form used by the generated preset tables in flash.
constexpr ThermostatClimateTargetTempConfig(float default_temperature_low, float default_temperature_high)
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