ESPHome  2024.12.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "climate.h"
5 
6 namespace esphome {
7 namespace climate {
8 
9 template<typename... Ts> class ControlAction : public Action<Ts...> {
10  public:
11  explicit ControlAction(Climate *climate) : climate_(climate) {}
12 
18  TEMPLATABLE_VALUE(bool, away)
22  TEMPLATABLE_VALUE(std::string, custom_preset)
24 
25  void play(Ts... x) override {
26  auto call = this->climate_->make_call();
27  call.set_mode(this->mode_.optional_value(x...));
28  call.set_target_temperature(this->target_temperature_.optional_value(x...));
29  call.set_target_temperature_low(this->target_temperature_low_.optional_value(x...));
30  call.set_target_temperature_high(this->target_temperature_high_.optional_value(x...));
31  call.set_target_humidity(this->target_humidity_.optional_value(x...));
32  if (away_.has_value()) {
33  call.set_preset(away_.value(x...) ? CLIMATE_PRESET_AWAY : CLIMATE_PRESET_HOME);
34  }
35  call.set_fan_mode(this->fan_mode_.optional_value(x...));
36  call.set_fan_mode(this->custom_fan_mode_.optional_value(x...));
37  call.set_preset(this->preset_.optional_value(x...));
38  call.set_preset(this->custom_preset_.optional_value(x...));
39  call.set_swing_mode(this->swing_mode_.optional_value(x...));
40  call.perform();
41  }
42 
43  protected:
44  Climate *climate_;
45 };
46 
47 class ControlTrigger : public Trigger<ClimateCall &> {
48  public:
49  ControlTrigger(Climate *climate) {
50  climate->add_on_control_callback([this](ClimateCall &x) { this->trigger(x); });
51  }
52 };
53 
54 class StateTrigger : public Trigger<Climate &> {
55  public:
56  StateTrigger(Climate *climate) {
57  climate->add_on_state_callback([this](Climate &x) { this->trigger(x); });
58  }
59 };
60 
61 } // namespace climate
62 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
float target_temperature_low
Definition: climate.h:140
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:82
Device is in home preset.
Definition: climate_mode.h:86
uint16_t x
Definition: tt21100.cpp:17
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 target_temperature_high
Definition: climate.h:141
float target_humidity
Definition: climate.h:589
ClimateSwingMode swing_mode
Definition: climate.h:581
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:70
Device is in away preset.
Definition: climate_mode.h:88
TEMPLATABLE_VALUE(ClimateMode, mode) TEMPLATABLE_VALUE(float
StateTrigger(Climate *climate)
Definition: automation.h:56
uint8_t custom_preset
Definition: climate.h:579
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
ControlTrigger(Climate *climate)
Definition: automation.h:49
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
ClimateFanMode fan_mode
Definition: climate.h:573
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
ControlAction(Climate *climate)
Definition: automation.h:11
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t custom_fan_mode
Definition: climate.h:574
float target_temperature
Definition: climate.h:138
virtual void play(Ts... x)=0
ClimatePreset preset
Definition: climate.h:578
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:168