ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
climate.h
Go to the documentation of this file.
1#pragma once
8#include "climate_mode.h"
10
12
13#define LOG_CLIMATE(prefix, type, obj) \
14 if ((obj) != nullptr) { \
15 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
16 }
18class Climate;
33 public:
34 explicit ClimateCall(Climate *parent) : parent_(parent) {}
36
42 ClimateCall &set_mode(const std::string &mode);
76 ClimateCall &set_fan_mode(const std::string &fan_mode);
82 ClimateCall &set_fan_mode(const char *custom_fan_mode, size_t len);
88 ClimateCall &set_swing_mode(const std::string &swing_mode);
94 ClimateCall &set_preset(const std::string &preset);
100 ClimateCall &set_preset(const char *custom_preset, size_t len);
101
102 void perform();
103
108
109 const optional<ClimateMode> &get_mode() const;
112 const optional<ClimatePreset> &get_preset() const;
113 const char *get_custom_fan_mode() const { return this->custom_fan_mode_; }
114 const char *get_custom_preset() const { return this->custom_preset_; }
115 bool has_custom_fan_mode() const { return this->custom_fan_mode_ != nullptr; }
116 bool has_custom_preset() const { return this->custom_preset_ != nullptr; }
117
118 protected:
119 void validate_();
120
130
131 private:
132 const char *custom_fan_mode_{nullptr};
133 const char *custom_preset_{nullptr};
134};
135
141 union {
144 };
146 union {
149 };
159
161 ClimateCall to_call(Climate *climate);
163 void apply(Climate *climate);
164} __attribute__((packed));
165
181class Climate : public EntityBase {
182 public:
184
190 void add_on_state_callback(std::function<void(Climate &)> &&callback);
191
198 void add_on_control_callback(std::function<void(ClimateCall &)> &&callback);
199
205
211 void publish_state();
212
219
220#ifdef USE_CLIMATE_VISUAL_OVERRIDES
221 void set_visual_min_temperature_override(float visual_min_temperature_override);
222 void set_visual_max_temperature_override(float visual_max_temperature_override);
223 void set_visual_temperature_step_override(float target, float current);
224 void set_visual_min_humidity_override(float visual_min_humidity_override);
225 void set_visual_max_humidity_override(float visual_max_humidity_override);
226#endif
227
229 bool has_custom_fan_mode() const { return this->custom_fan_mode_ != nullptr; }
230
232 bool has_custom_preset() const { return this->custom_preset_ != nullptr; }
233
236
239
240 union {
243 struct {
248 };
249 };
250
253
256
259
262
265
268
270 const char *get_custom_fan_mode() const { return this->custom_fan_mode_; }
271
273 const char *get_custom_preset() const { return this->custom_preset_; }
274
275 protected:
278
281
283 bool set_custom_fan_mode_(const char *mode);
286
289
291 bool set_custom_preset_(const char *preset);
294
296 const char *find_custom_fan_mode_(const char *custom_fan_mode);
297 const char *find_custom_fan_mode_(const char *custom_fan_mode, size_t len);
298
300 const char *find_custom_preset_(const char *custom_preset);
301 const char *find_custom_preset_(const char *custom_preset, size_t len);
302
309 virtual ClimateTraits traits() = 0;
310
319 virtual void control(const ClimateCall &call) = 0;
325 void save_state_();
326
327 void dump_traits_(const char *tag);
328
332#ifdef USE_CLIMATE_VISUAL_OVERRIDES
339#endif
340
341 private:
347 const char *custom_fan_mode_{nullptr};
348
354 const char *custom_preset_{nullptr};
356
357} // namespace esphome::climate
BedjetMode mode
BedJet operating mode.
This class is used to encode all control actions on a climate device.
Definition climate.h:32
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:306
optional< float > target_temperature_high_
Definition climate.h:124
bool has_custom_fan_mode() const
Definition climate.h:115
const optional< float > & get_target_humidity() const
Definition climate.cpp:302
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition climate.cpp:279
const char * get_custom_fan_mode() const
Definition climate.h:113
bool has_custom_preset() const
Definition climate.h:116
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:300
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition climate.cpp:263
optional< ClimateFanMode > fan_mode_
Definition climate.h:127
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition climate.cpp:284
optional< float > target_temperature_
Definition climate.h:122
const optional< float > & get_target_temperature() const
Definition climate.cpp:299
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:307
optional< ClimateSwingMode > swing_mode_
Definition climate.h:128
optional< ClimateMode > mode_
Definition climate.h:126
const char * get_custom_preset() const
Definition climate.h:114
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition climate.cpp:225
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:301
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:305
optional< float > target_humidity_
Definition climate.h:125
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition climate.cpp:187
optional< ClimatePreset > preset_
Definition climate.h:129
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
Definition climate.cpp:294
ClimateCall(Climate *parent)
Definition climate.h:34
optional< float > target_temperature_low_
Definition climate.h:123
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition climate.cpp:289
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition climate.cpp:171
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:304
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
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:487
float target_temperature
The target temperature of the climate device.
Definition climate.h:242
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:238
float visual_min_humidity_override_
Definition climate.h:337
float visual_target_temperature_step_override_
Definition climate.h:335
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:524
void dump_traits_(const char *tag)
Definition climate.cpp:719
const char * get_custom_fan_mode() const
Get the active custom fan mode (read-only access).
Definition climate.h:270
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:267
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:371
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:245
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:528
void add_on_state_callback(std::function< void(Climate &)> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition climate.cpp:351
float visual_current_temperature_step_override_
Definition climate.h:336
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition climate.cpp:693
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.cpp:695
const char * find_custom_fan_mode_(const char *custom_fan_mode)
Find and return the matching custom fan mode pointer from traits, or nullptr if not found.
Definition climate.cpp:703
const char * get_custom_preset() const
Get the active custom preset (read-only access).
Definition climate.h:273
float visual_min_temperature_override_
Definition climate.h:333
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:515
void clear_custom_preset_()
Clear custom preset.
Definition climate.cpp:701
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:681
LazyCallbackManager< void(Climate &)> state_callback_
Definition climate.h:329
bool has_custom_preset() const
Check if a custom preset is currently active.
Definition climate.h:232
const char * find_custom_preset_(const char *custom_preset)
Find and return the matching custom preset pointer from traits, or nullptr if not found.
Definition climate.cpp:711
void clear_custom_fan_mode_()
Clear custom fan mode.
Definition climate.cpp:691
void add_on_control_callback(std::function< void(ClimateCall &)> &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
Definition climate.cpp:355
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:235
float visual_max_humidity_override_
Definition climate.h:338
ClimateAction action
The active state of the climate device.
Definition climate.h:264
LazyCallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:330
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:533
float visual_max_temperature_override_
Definition climate.h:334
virtual void control(const ClimateCall &call)=0
Control the climate device, this is a virtual method that each climate integration must implement.
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:438
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:519
bool has_custom_fan_mode() const
Check if a custom fan mode is currently active.
Definition climate.h:229
ESPPreferenceObject rtc_
Definition climate.h:331
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:258
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:511
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:362
float target_humidity
The target humidity of the climate device.
Definition climate.h:252
bool set_custom_fan_mode_(const char *mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
Definition climate.cpp:685
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:247
float target_temperature_high
Definition climate.h:3
float target_humidity
Definition climate.h:19
ClimateSwingMode swing_mode
Definition climate.h:11
float target_temperature
Definition climate.h:0
uint8_t custom_preset
Definition climate.h:9
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
float target_temperature_low
Definition climate.h:2
uint8_t custom_fan_mode
Definition climate.h:4
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.
esphome::climate::Climate __attribute__
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.
std::string size_t len
Definition helpers.h:533
Struct used to save the state of the climate device in restore memory.
Definition climate.h:138
struct esphome::climate::ClimateDeviceRestoreState::@57::@58 __attribute__
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:535
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:571