ESPHome 2025.5.0
Loading...
Searching...
No Matches
climate.h
Go to the documentation of this file.
1#pragma once
7#include "esphome/core/log.h"
8#include "climate_mode.h"
10
11namespace esphome {
12namespace climate {
13
14#define LOG_CLIMATE(prefix, type, obj) \
15 if ((obj) != nullptr) { \
16 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
17 }
18
19class Climate;
20
34 public:
35 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);
84 ClimateCall &set_swing_mode(const std::string &swing_mode);
90 ClimateCall &set_preset(const std::string &preset);
93
94 void perform();
95
96 const optional<ClimateMode> &get_mode() const;
104 const optional<ClimatePreset> &get_preset() const;
106
107 protected:
108 void validate_();
109
121};
122
128 union {
131 };
133 union {
136 };
146
148 ClimateCall to_call(Climate *climate);
150 void apply(Climate *climate);
151} __attribute__((packed));
152
168class Climate : public EntityBase {
169 public:
171
174
177
180
183
184 union {
187 struct {
192 };
193 };
194
197
200
203
206
209
212
218 void add_on_state_callback(std::function<void(Climate &)> &&callback);
219
226 void add_on_control_callback(std::function<void(ClimateCall &)> &&callback);
227
233
239 void publish_state();
240
247
248 void set_visual_min_temperature_override(float visual_min_temperature_override);
249 void set_visual_max_temperature_override(float visual_max_temperature_override);
250 void set_visual_temperature_step_override(float target, float current);
251 void set_visual_min_humidity_override(float visual_min_humidity_override);
252 void set_visual_max_humidity_override(float visual_max_humidity_override);
253
254 protected:
256
259
261 bool set_custom_fan_mode_(const std::string &mode);
262
265
267 bool set_custom_preset_(const std::string &preset);
268
275 virtual ClimateTraits traits() = 0;
276
285 virtual void control(const ClimateCall &call) = 0;
291 void save_state_();
292
293 void dump_traits_(const char *tag);
294
305
306} // namespace climate
307} // namespace esphome
BedjetMode mode
BedJet operating mode.
This class is used to encode all control actions on a climate device.
Definition climate.h:33
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:282
optional< float > target_temperature_high_
Definition climate.h:114
const optional< float > & get_target_humidity() const
Definition climate.cpp:277
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition climate.cpp:256
const optional< std::string > & get_custom_preset() const
Definition climate.cpp:281
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:275
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition climate.cpp:237
optional< ClimateFanMode > fan_mode_
Definition climate.h:116
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition climate.cpp:260
optional< float > target_temperature_
Definition climate.h:112
const optional< float > & get_target_temperature() const
Definition climate.cpp:274
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:280
optional< std::string > custom_fan_mode_
Definition climate.h:118
optional< ClimateSwingMode > swing_mode_
Definition climate.h:117
optional< ClimateMode > mode_
Definition climate.h:111
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition climate.cpp:199
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:276
optional< std::string > custom_preset_
Definition climate.h:120
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:278
optional< float > target_humidity_
Definition climate.h:115
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition climate.cpp:157
optional< ClimatePreset > preset_
Definition climate.h:119
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
Definition climate.cpp:268
ClimateCall(Climate *parent)
Definition climate.h:35
optional< float > target_temperature_low_
Definition climate.h:113
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition climate.cpp:264
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition climate.cpp:133
const optional< std::string > & get_custom_fan_mode() const
Definition climate.cpp:279
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:273
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
bool set_custom_fan_mode_(const std::string &mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
Definition climate.cpp:559
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:199
optional< float > visual_max_humidity_override_
Definition climate.h:303
bool set_custom_preset_(const std::string &preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.cpp:565
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:440
float target_temperature
The target temperature of the climate device.
Definition climate.h:186
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:182
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:472
optional< float > visual_current_temperature_step_override_
Definition climate.h:301
void dump_traits_(const char *tag)
Definition climate.cpp:569
CallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:296
CallbackManager< void(Climate &)> state_callback_
Definition climate.h:295
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Definition climate.h:205
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:202
optional< float > visual_target_temperature_step_override_
Definition climate.h:300
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:337
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:189
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:475
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:318
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:563
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition climate.h:211
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:465
optional< float > visual_min_humidity_override_
Definition climate.h:302
optional< float > visual_max_temperature_override_
Definition climate.h:299
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:555
optional< float > visual_min_temperature_override_
Definition climate.h:298
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:322
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:179
ClimateAction action
The active state of the climate device.
Definition climate.h:176
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:479
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:395
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:468
ESPPreferenceObject rtc_
Definition climate.h:297
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:208
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:462
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:329
float target_humidity
The target humidity of the climate device.
Definition climate.h:196
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:191
This class contains all static data for climate devices.
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
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
float target_temperature_low
Definition climate.h:2
ClimatePreset
Enum for all preset modes.
ClimateSwingMode
Enum for all modes a climate swing can be in.
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)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Struct used to save the state of the climate device in restore memory.
Definition climate.h:125
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:481
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:505
struct esphome::climate::ClimateDeviceRestoreState::@59::@60 __attribute__