ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
template_climate.h
Go to the documentation of this file.
1#pragma once
2
7#ifdef USE_SENSOR
9#endif
10
11namespace esphome::template_ {
12
17
18class TemplateClimate final : public climate::Climate, public Component {
19#ifdef USE_SENSOR
20 // Codegen adds the matching feature flags, so the configuration alone decides them.
21 SUB_SENSOR(temperature)
22 SUB_SENSOR(humidity)
23#endif
24
25 public:
26 void setup() override;
27 void dump_config() override;
28
29 climate::ClimateTraits traits() override { return this->traits_; }
30
31 void add_feature_flags(uint32_t flags) { this->traits_.add_feature_flags(flags); }
32 void set_temperature_unit(TemperatureUnit unit) {
33 this->traits_.set_temperature_unit(unit);
34 // Visual overrides still apply on top of the converted default range
37 }
38
39 void add_supported_mode(climate::ClimateMode mode) { this->traits_.add_supported_mode(mode); }
40 void add_supported_fan_mode(climate::ClimateFanMode mode) { this->traits_.add_supported_fan_mode(mode); }
41 void add_supported_swing_mode(climate::ClimateSwingMode mode) { this->traits_.add_supported_swing_mode(mode); }
42 void add_supported_preset(climate::ClimatePreset preset) { this->traits_.add_supported_preset(preset); }
43
44 void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
45 void set_restore_mode(TemplateClimateRestoreMode restore_mode) { this->restore_mode_ = restore_mode; }
46
47 // Fired from control() for each field the call carries, so a device-backed config can forward
48 // it on. Which of these are configured also decides the two-point/target-humidity traits.
49 Trigger<climate::ClimateMode> *get_set_mode_trigger() { return &this->set_mode_trigger_; }
50 Trigger<float> *get_set_target_temperature_trigger() { return &this->set_target_temperature_trigger_; }
51 Trigger<float> *get_set_target_temperature_low_trigger() { return &this->set_target_temperature_low_trigger_; }
52 Trigger<float> *get_set_target_temperature_high_trigger() { return &this->set_target_temperature_high_trigger_; }
53 Trigger<float> *get_set_target_humidity_trigger() { return &this->set_target_humidity_trigger_; }
54 Trigger<climate::ClimateFanMode> *get_set_fan_mode_trigger() { return &this->set_fan_mode_trigger_; }
55 Trigger<StringRef> *get_set_custom_fan_mode_trigger() { return &this->set_custom_fan_mode_trigger_; }
56 Trigger<climate::ClimateSwingMode> *get_set_swing_mode_trigger() { return &this->set_swing_mode_trigger_; }
57 Trigger<climate::ClimatePreset> *get_set_preset_trigger() { return &this->set_preset_trigger_; }
58 Trigger<StringRef> *get_set_custom_preset_trigger() { return &this->set_custom_preset_trigger_; }
59
60 // Public so the climate.template.publish action and the initial_state codegen can set them.
61 void set_target_temperature(float value) { this->target_temperature = value; }
62 void set_target_temperature_low(float value) { this->target_temperature_low = value; }
63 void set_target_temperature_high(float value) { this->target_temperature_high = value; }
64 void set_target_humidity(float value) { this->target_humidity = value; }
65 void set_mode(climate::ClimateMode mode);
66 void set_swing_mode(climate::ClimateSwingMode mode);
67 void set_fan_mode(climate::ClimateFanMode mode);
68 void set_custom_fan_mode(const char *mode) { this->set_custom_fan_mode(StringRef(mode)); }
69 void set_custom_fan_mode(StringRef mode);
70 void set_preset(climate::ClimatePreset preset);
71 void set_custom_preset(const char *preset) { this->set_custom_preset(StringRef(preset)); }
72 void set_custom_preset(StringRef preset);
73
74 protected:
75 void control(const climate::ClimateCall &call) override;
76
78 bool optimistic_{false};
80
91};
92
93} // namespace esphome::template_
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
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
float target_temperature
The target temperature of the climate device.
Definition climate.h:298
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:301
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:314
float target_humidity
The target humidity of the climate device.
Definition climate.h:308
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:303
void set_visual_max_temperature(float visual_max_temperature)
static constexpr float DEFAULT_VISUAL_MAX_TEMPERATURE
void add_feature_flags(uint32_t feature_flags)
void add_supported_fan_mode(ClimateFanMode mode)
void add_supported_preset(ClimatePreset preset)
void set_visual_min_temperature(float visual_min_temperature)
void set_temperature_unit(TemperatureUnit unit)
void add_supported_mode(ClimateMode mode)
static constexpr float DEFAULT_VISUAL_MIN_TEMPERATURE
void add_supported_swing_mode(ClimateSwingMode mode)
Trigger< climate::ClimateMode > set_mode_trigger_
Trigger< climate::ClimatePreset > set_preset_trigger_
Trigger< climate::ClimateSwingMode > set_swing_mode_trigger_
Trigger< StringRef > set_custom_fan_mode_trigger_
void control(const climate::ClimateCall &call) override
Trigger< float > set_target_temperature_low_trigger_
TemplateClimateRestoreMode restore_mode_
Trigger< StringRef > set_custom_preset_trigger_
Trigger< climate::ClimateFanMode > set_fan_mode_trigger_
Trigger< float > set_target_temperature_high_trigger_
uint16_t flags
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...
ClimateMode
Enum for all modes a climate device can be in.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
constexpr float celsius_to(float value, TemperatureUnit unit)
Convert degrees Celsius into the given unit.
Definition helpers.h:1874
uint32_t value
Definition hal.cpp:41
TemperatureUnit
Definition helpers.h:1867
static void uint32_t
uint16_t temperature
Definition sun_gtil2.cpp:12