ESPHome  2022.8.0
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 
17  TEMPLATABLE_VALUE(bool, away)
21  TEMPLATABLE_VALUE(std::string, custom_preset)
23 
24  void play(Ts... x) override {
25  auto call = this->climate_->make_call();
26  call.set_mode(this->mode_.optional_value(x...));
27  call.set_target_temperature(this->target_temperature_.optional_value(x...));
28  call.set_target_temperature_low(this->target_temperature_low_.optional_value(x...));
29  call.set_target_temperature_high(this->target_temperature_high_.optional_value(x...));
30  if (away_.has_value()) {
31  call.set_preset(away_.value(x...) ? CLIMATE_PRESET_AWAY : CLIMATE_PRESET_HOME);
32  }
33  call.set_fan_mode(this->fan_mode_.optional_value(x...));
34  call.set_fan_mode(this->custom_fan_mode_.optional_value(x...));
35  call.set_preset(this->preset_.optional_value(x...));
36  call.set_preset(this->custom_preset_.optional_value(x...));
37  call.set_swing_mode(this->swing_mode_.optional_value(x...));
38  call.perform();
39  }
40 
41  protected:
43 };
44 
45 class StateTrigger : public Trigger<> {
46  public:
47  StateTrigger(Climate *climate) {
48  climate->add_on_state_callback([this]() { this->trigger(); });
49  }
50 };
51 
52 } // namespace climate
53 } // namespace esphome
float target_temperature_low
Definition: climate.h:552
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:80
Device is in home preset.
Definition: climate_mode.h:84
float target_temperature_high
Definition: climate.h:553
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition: climate.cpp:229
ClimateSwingMode swing_mode
Definition: climate.h:548
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:68
void add_on_state_callback(std::function< void()> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition: climate.cpp:314
Device is in away preset.
Definition: climate_mode.h:86
TEMPLATABLE_VALUE(ClimateMode, mode) TEMPLATABLE_VALUE(float
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:252
StateTrigger(Climate *climate)
Definition: automation.h:47
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition: climate.cpp:452
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:248
uint8_t custom_preset
Definition: climate.h:546
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition: climate.cpp:193
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition: climate.cpp:153
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
ClimateFanMode fan_mode
Definition: climate.h:540
ControlAction(Climate *climate)
Definition: automation.h:11
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition: climate.cpp:256
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition: climate.cpp:129
target_temperature target_temperature_high fan_mode preset swing_mode void play(Ts... x) override
Definition: automation.h:24
Definition: a4988.cpp:4
uint8_t custom_fan_mode
Definition: climate.h:541
float target_temperature
Definition: climate.h:550
ClimatePreset preset
Definition: climate.h:545
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167