ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
siemens_ira211.cpp
Go to the documentation of this file.
1#include "siemens_ira211.h"
2#include "esphome/core/hal.h"
4
6
7using namespace remote_base;
8
9// Presets map to IRA211Mode and fan modes to IRA211Fan. Values the other side does not know fall back to comfort
10// and auto.
11static constexpr climate_ir::IRCode PRESETS[] PROGMEM = {
12 {climate::CLIMATE_PRESET_COMFORT, static_cast<uint8_t>(IRA211Mode::IRA211_MODE_COMFORT)},
13 {climate::CLIMATE_PRESET_ECO, static_cast<uint8_t>(IRA211Mode::IRA211_MODE_TIMER)},
14};
15static constexpr climate_ir::IRCode FANS[] PROGMEM = {
16 {climate::CLIMATE_FAN_AUTO, static_cast<uint8_t>(IRA211Fan::IRA211_FAN_AUTO)},
17 {climate::CLIMATE_FAN_LOW, static_cast<uint8_t>(IRA211Fan::IRA211_FAN_LOW)},
18 {climate::CLIMATE_FAN_MEDIUM, static_cast<uint8_t>(IRA211Fan::IRA211_FAN_MEDIUM)},
19 {climate::CLIMATE_FAN_HIGH, static_cast<uint8_t>(IRA211Fan::IRA211_FAN_HIGH)},
20};
21
22static IRA211Mode to_ira211_mode(climate::ClimatePreset preset) {
23 return static_cast<IRA211Mode>(
24 climate_ir::to_ir_code(PRESETS, preset, static_cast<uint8_t>(IRA211Mode::IRA211_MODE_COMFORT)));
25}
26static climate::ClimatePreset to_climate_preset(IRA211Mode mode) {
27 return climate_ir::from_ir_code(PRESETS, static_cast<uint8_t>(mode), climate::CLIMATE_PRESET_COMFORT);
28}
29static IRA211Fan to_ira211_fan(climate::ClimateFanMode fan_mode) {
30 return static_cast<IRA211Fan>(
31 climate_ir::to_ir_code(FANS, fan_mode, static_cast<uint8_t>(IRA211Fan::IRA211_FAN_AUTO)));
32}
33static climate::ClimateFanMode to_climate_fan_mode(IRA211Fan fan) {
34 return climate_ir::from_ir_code(FANS, static_cast<uint8_t>(fan), climate::CLIMATE_FAN_AUTO);
35}
36
38 // The thermostat decides between heating and cooling itself, so one mode stands for both
42 }
43 climate_ir::ClimateIR::setup();
44 // Match the restored state, so the first command after a reboot does not send a needless POWER frame
45 this->is_on_ = this->mode != climate::CLIMATE_MODE_OFF;
46}
47
55
57 IRA211Data data{};
58 data.command = command;
59 data.set_temperature(this->target_temperature);
60 data.mode = mode;
61 data.fan = fan;
62 this->transmit_<IRA211Protocol>(data);
63}
64
66 const IRA211Mode mode = to_ira211_mode(this->preset.value_or(climate::CLIMATE_PRESET_COMFORT));
67 const IRA211Fan fan = to_ira211_fan(this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO));
68 // Show the preset that is actually sent, so a fresh entity does not stay on "none"
69 this->preset = to_climate_preset(mode);
70
71 if (this->mode == climate::CLIMATE_MODE_OFF) {
72 this->transmit_frame_(IRA211Command::IRA211_COMMAND_POWER, IRA211Mode::IRA211_MODE_PROTECTION, fan);
73 this->is_on_ = false;
74 return;
75 }
76 if (!this->is_on_) {
77 // Turning on takes a POWER frame before the state is sent
78 this->transmit_frame_(IRA211Command::IRA211_COMMAND_POWER, mode, fan);
79 this->is_on_ = true;
80 }
81 this->transmit_frame_(IRA211Command::IRA211_COMMAND_SYNC, mode, fan);
82}
83
85 // The thermostat reports "off" as the PROTECTION mode
86 if (mode == IRA211Mode::IRA211_MODE_PROTECTION) {
87 this->mode = climate::CLIMATE_MODE_OFF;
88 this->is_on_ = false;
89 return;
90 }
91 if (!this->is_on_) {
92 this->mode = this->active_mode_();
93 this->is_on_ = true;
94 }
95 this->preset = to_climate_preset(mode);
96}
97
99 auto decoded = IRA211Protocol().decode(data);
100 if (!decoded.has_value())
101 return false;
102
103 const IRA211Data &frame = *decoded;
104 switch (frame.command) {
105 case IRA211Command::IRA211_COMMAND_SYNC:
106 case IRA211Command::IRA211_COMMAND_POWER:
107 this->apply_mode_(frame.mode);
108 this->target_temperature = frame.get_temperature();
109 this->fan_mode = to_climate_fan_mode(frame.fan);
110 break;
111 case IRA211Command::IRA211_COMMAND_TEMP_UP:
112 case IRA211Command::IRA211_COMMAND_TEMP_DOWN:
113 this->target_temperature = frame.get_temperature();
114 break;
115 case IRA211Command::IRA211_COMMAND_MODE:
116 this->apply_mode_(frame.mode);
117 break;
118 case IRA211Command::IRA211_COMMAND_FAN:
119 this->fan_mode = to_climate_fan_mode(frame.fan);
120 break;
121 default:
122 return false;
123 }
124
125 this->publish_state();
126 return true;
127}
128
129} // namespace esphome::siemens_ira211
BedjetMode mode
BedJet operating mode.
constexpr size_t count(ValueType value) const
Check if the set contains a specific value (std::set compatibility) Returns 1 if present,...
constexpr void erase(ValueType value)
Remove a value from the set (std::set compatibility)
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
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
climate::ClimateModeMask modes_
Definition climate_ir.h:115
optional< IRA211Data > decode(RemoteReceiveData src)
void transmit_(const typename Protocol::ProtocolData &data, uint32_t send_times=1, uint32_t send_wait=0)
bool on_receive(remote_base::RemoteReceiveData data) override
void transmit_frame_(remote_base::IRA211Command command, remote_base::IRA211Mode mode, remote_base::IRA211Fan fan)
void apply_mode_(remote_base::IRA211Mode mode)
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
T from_ir_code(const IRCode(&table)[N], uint8_t code, T fallback)
The value for code, or fallback when the table has no such code; pass the current state to keep it.
Definition climate_ir.h:40
uint8_t to_ir_code(const IRCode(&table)[N], uint8_t value, uint8_t fallback)
The code for value, or fallback when the table has no such value.
Definition climate_ir.h:36
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
ClimateMode
Enum for all modes a climate device can be in.
@ 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.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
One entry of a PROGMEM table that maps a climate enum value to the unit's code.
Definition climate_ir.h:15