ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
demo_climate.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace demo {
8
9enum class DemoClimateType {
10 TYPE_1,
11 TYPE_2,
12 TYPE_3,
13};
14
15class DemoClimate : public climate::Climate, public Component {
16 public:
18 void setup() override {
19 // Set custom modes once during setup — stored on Climate base class, wired via get_traits()
20 switch (type_) {
22 break;
24 this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
25 this->set_supported_custom_presets({"My Preset"});
26 break;
28 this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
29 break;
30 }
31 // Set initial state
32 switch (type_) {
34 this->current_temperature = 20.0;
35 this->target_temperature = 21.0;
38 break;
40 this->target_temperature = 21.5;
44 this->set_custom_preset_("My Preset");
45 break;
47 this->current_temperature = 21.5;
48 this->target_temperature_low = 21.0;
49 this->target_temperature_high = 22.5;
51 this->set_custom_fan_mode_("Auto Low");
54 break;
55 }
56 this->publish_state();
57 }
58
59 protected:
60 void control(const climate::ClimateCall &call) override {
61 auto mode = call.get_mode();
62 if (mode.has_value())
63 this->mode = *mode;
65 if (target_temperature.has_value())
68 if (target_temperature_low.has_value())
71 if (target_temperature_high.has_value())
73 auto fan_mode = call.get_fan_mode();
74 if (fan_mode.has_value())
75 this->set_fan_mode_(*fan_mode);
76 auto swing_mode = call.get_swing_mode();
77 if (swing_mode.has_value())
78 this->swing_mode = *swing_mode;
79 if (call.has_custom_fan_mode())
81 auto preset = call.get_preset();
82 if (preset.has_value())
83 this->set_preset_(*preset);
84 if (call.has_custom_preset())
86 this->publish_state();
87 }
90 switch (type_) {
96 });
98 break;
107 });
120 });
121 // Custom fan modes and presets are set once in setup()
127 });
128 break;
137 });
138 // Custom fan modes are set once in setup()
142 });
152 });
153 break;
154 }
155 return traits;
156 }
157
159};
160
161} // namespace demo
162} // namespace esphome
This class is used to encode all control actions on a climate device.
Definition climate.h:34
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:314
bool has_custom_fan_mode() const
Definition climate.h:121
bool has_custom_preset() const
Definition climate.h:122
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:308
const optional< float > & get_target_temperature() const
Definition climate.cpp:307
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:309
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:313
StringRef get_custom_fan_mode() const
Definition climate.h:119
StringRef get_custom_preset() const
Definition climate.h:120
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:187
ClimateMode mode
The active mode of the climate device.
Definition climate.h:293
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:287
void set_supported_custom_fan_modes(std::initializer_list< const char * > modes)
Set the supported custom fan modes (stored on Climate, referenced by ClimateTraits).
Definition climate.h:239
float target_temperature
The target temperature of the climate device.
Definition climate.h:274
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:299
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:277
void set_supported_custom_presets(std::initializer_list< const char * > presets)
Set the supported custom presets (stored on Climate, referenced by ClimateTraits).
Definition climate.h:250
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition climate.cpp:695
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.h:325
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:684
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:267
ClimateAction action
The active state of the climate device.
Definition climate.h:296
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:436
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:290
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.h:315
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:279
void add_feature_flags(uint32_t feature_flags)
void set_visual_temperature_step(float temperature_step)
void set_supported_presets(ClimatePresetMask presets)
void set_supported_swing_modes(ClimateSwingModeMask modes)
void set_supported_modes(ClimateModeMask modes)
void set_supported_fan_modes(ClimateFanModeMask modes)
void set_type(DemoClimateType type)
climate::ClimateTraits traits() override
void control(const climate::ClimateCall &call) override
uint16_t type
@ CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_AWAY
Device is in away preset.
@ CLIMATE_PRESET_BOOST
Device is in boost preset.
@ CLIMATE_PRESET_ACTIVITY
Device is reacting to activity (e.g., movement sensors)
@ CLIMATE_PRESET_SLEEP
Device is prepared for sleep.
@ CLIMATE_PRESET_HOME
Device is in home preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
@ CLIMATE_ACTION_HEATING
The climate device is actively heating.
@ CLIMATE_ACTION_COOLING
The climate device is actively cooling.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7