ESPHome 2026.10.2
Loading...
Searching...
No Matches
climate_ir.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4
9
10namespace esphome::climate_ir {
11
12/* A base for climate which works by sending (and receiving) IR codes
13
14 To send IR codes implement
15 void ClimateIR::transmit_state_()
16
17 Likewise to decode a IR into the AC state, implement
18 bool RemoteReceiverListener::on_receive(remote_base::RemoteReceiveData data) and return true
19*/
20class ClimateIR : public Component,
21 public climate::Climate,
24 public:
25 ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step = 1.0f,
26 bool supports_dry = false, bool supports_fan_only = false,
30 this->minimum_temperature_ = minimum_temperature;
31 this->maximum_temperature_ = maximum_temperature;
32 this->temperature_step_ = temperature_step;
33 if (supports_dry)
35 if (supports_fan_only)
37 this->fan_modes_ = fan_modes;
38 this->swing_modes_ = swing_modes;
39 this->presets_ = presets;
40 }
41
42 void setup() override;
43 void dump_config() override;
44 void set_supports_cool(bool supports_cool) { this->set_mode_supported_(climate::CLIMATE_MODE_COOL, supports_cool); }
45 void set_supports_heat(bool supports_heat) { this->set_mode_supported_(climate::CLIMATE_MODE_HEAT, supports_heat); }
46 void set_supports_heat_cool(bool supports_heat_cool) {
48 }
49 void set_sensor(sensor::Sensor *sensor) { this->sensor_ = sensor; }
50 void set_humidity_sensor(sensor::Sensor *sensor) { this->humidity_sensor_ = sensor; }
51
52 protected:
54
56 void control(const climate::ClimateCall &call) override;
59
61 virtual void transmit_state() = 0;
62
63 // Dummy implement on_receive so implementation is optional for inheritors
64 bool on_receive(remote_base::RemoteReceiveData data) override { return false; };
65
66 ESPHOME_ALWAYS_INLINE void set_mode_supported_(climate::ClimateMode mode, bool supported) {
67 if (supported) {
68 this->modes_.insert(mode);
69 } else {
70 this->modes_.erase(mode);
71 }
72 }
73
74 // The HEAT_COOL default (supports_cool && supports_heat) is resolved during code generation.
81
84};
85
86} // namespace esphome::climate_ir
constexpr void insert(ValueType value)
Add a single value to the set (std::set compatibility)
constexpr void erase(ValueType value)
Remove a value from the set (std::set compatibility)
This class is used to encode all control actions on a climate device.
Definition climate.h:34
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:195
ClimateMode mode
The active mode of the climate device.
Definition climate.h:312
climate::ClimatePresetMask presets_
Definition climate_ir.h:80
climate::ClimateFanModeMask fan_modes_
Definition climate_ir.h:78
climate::ClimateSwingModeMask swing_modes_
Definition climate_ir.h:79
static constexpr climate::ClimateModeMask DEFAULT_MODES
Definition climate_ir.h:75
void control(const climate::ClimateCall &call) override
Override control to change settings of the climate device.
sensor::Sensor * humidity_sensor_
Definition climate_ir.h:83
ESPHOME_ALWAYS_INLINE void set_mode_supported_(climate::ClimateMode mode, bool supported)
Definition climate_ir.h:66
climate::ClimateTraits traits() override
Return the traits of this controller.
Definition climate_ir.cpp:8
void set_sensor(sensor::Sensor *sensor)
Definition climate_ir.h:49
void set_supports_heat(bool supports_heat)
Definition climate_ir.h:45
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
void set_humidity_sensor(sensor::Sensor *sensor)
Definition climate_ir.h:50
bool on_receive(remote_base::RemoteReceiveData data) override
Definition climate_ir.h:64
climate::ClimateModeMask modes_
Definition climate_ir.h:77
ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step=1.0f, bool supports_dry=false, bool supports_fan_only=false, climate::ClimateFanModeMask fan_modes=climate::ClimateFanModeMask(), climate::ClimateSwingModeMask swing_modes=climate::ClimateSwingModeMask(), climate::ClimatePresetMask presets=climate::ClimatePresetMask())
Definition climate_ir.h:25
void set_supports_heat_cool(bool supports_heat_cool)
Definition climate_ir.h:46
void set_supports_cool(bool supports_cool)
Definition climate_ir.h:44
Base-class for all sensors.
Definition sensor.h:47
ClimateMode
Enum for all modes a climate device can be in.
@ 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.