ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
remko_ar715.cpp
Go to the documentation of this file.
1#include "remko_ar715.h"
3#include "esphome/core/log.h"
4#include <cmath>
5
7
8ESPHOME_LOG_TAG(TAG, "remko_ar715.climate");
9
10// Timings from ir_ClimaButler.cpp (IRremoteESP8266), in microseconds
11static constexpr uint16_t BIT_MARK = 511;
12static constexpr uint16_t HDR_SPACE = 3492;
13static constexpr uint16_t ONE_SPACE = 1540;
14static constexpr uint16_t ZERO_SPACE = 548;
15static constexpr uint32_t CARRIER_FREQUENCY = 38000;
16static constexpr uint8_t BITS = 52;
17
18static constexpr uint8_t POWER_ON = 0x3;
19static constexpr uint8_t POWER_OFF = 0x0;
20static constexpr uint8_t SWING_ON = 0x5;
21static constexpr uint8_t SWING_OFF = 0x7;
22
23// Mode/fan byte: high nibble N3, low nibble N2
24static constexpr uint8_t MODE_FAN_AUTO = 0x80;
25static constexpr uint8_t MODE_FAN_LOW = 0xA2;
26static constexpr uint8_t MODE_FAN_MEDIUM = 0x91;
27static constexpr uint8_t MODE_FAN_HIGH = 0x88;
28static constexpr uint8_t MODE_DRY = 0xA4;
29static constexpr uint8_t MODE_FAN_ONLY = 0xA3;
30
31static uint8_t fan_mode_byte(climate::ClimateFanMode fan_mode) {
32 switch (fan_mode) {
34 return MODE_FAN_HIGH;
36 return MODE_FAN_MEDIUM;
38 return MODE_FAN_LOW;
39 default:
40 return MODE_FAN_AUTO;
41 }
42}
43
44// 52-bit word, 13 nibbles MSB first:
45// N12=0x8 (fixed), N11=power, N10..N5=0 (timer, unused), N4=swing,
46// N3,N2=mode/fan, N1=temp-16, N0=checksum (0xF - sum(N12..N1)) & 0xF
47static uint64_t build_frame(uint8_t power, uint8_t swing, uint8_t mode_fan, uint8_t temp) {
48 const uint8_t temp_nibble = (temp - 16) & 0xF;
49 const uint8_t sum = 0x8 + power + swing + (mode_fan >> 4) + (mode_fan & 0xF) + temp_nibble;
50 const uint8_t checksum = (0xF - sum) & 0xF;
51 return (uint64_t{0x8} << 48) | (uint64_t{power} << 44) | (uint32_t{swing} << 16) | (uint32_t{mode_fan} << 8) |
52 (temp_nibble << 4) | checksum;
53}
54
55static void send_frame(remote_base::RemoteTransmitData *data, uint64_t code) {
56 data->set_carrier_frequency(CARRIER_FREQUENCY);
57 data->reserve(2 + BITS * 2 + 2);
58 data->item(BIT_MARK, HDR_SPACE);
59 for (int i = BITS - 1; i >= 0; i--)
60 data->item(BIT_MARK, (code >> i) & 1 ? ONE_SPACE : ZERO_SPACE);
61 // Stop bit and inter-frame gap
62 data->item(BIT_MARK, HDR_SPACE);
63}
64
66 const uint8_t temp = lroundf(clamp(this->target_temperature, TEMP_MIN, TEMP_MAX));
67 const bool power = this->mode != climate::CLIMATE_MODE_OFF;
68 const bool swing = this->swing_mode == climate::CLIMATE_SWING_VERTICAL;
69
70 // DRY and FAN_ONLY carry no fan speed: mode and fan share the same nibbles
71 uint8_t mode_fan;
72 switch (this->mode) {
74 mode_fan = MODE_DRY;
75 break;
77 mode_fan = MODE_FAN_ONLY;
78 break;
79 default:
80 mode_fan = fan_mode_byte(this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO));
81 break;
82 }
83
84 const uint64_t code = build_frame(power ? POWER_ON : POWER_OFF, swing ? SWING_ON : SWING_OFF, mode_fan, temp);
85 ESP_LOGV(TAG, "Sending power=%s temp=%u swing=%s mode_fan=0x%02X code=0x%05" PRIX32 "%08" PRIX32, ONOFF(power), temp,
86 ONOFF(swing), mode_fan, static_cast<uint32_t>(code >> 32), static_cast<uint32_t>(code));
87
88 auto transmit = this->transmitter_->transmit();
89 send_frame(transmit.get_data(), code);
90 transmit.perform();
91}
92
93} // namespace esphome::remko_ar715
uint8_t checksum
Definition bl0906.h:3
ClimateMode mode
The active mode of the climate device.
Definition climate.h:304
float target_temperature
The target temperature of the climate device.
Definition climate.h:285
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:310
ClimateFanMode fan_mode
Definition climate.h:3
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ 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_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.
std::span< const uint8_t > data
ESPHOME_LOG_TAG(TAG, "remko_ar715.climate")
static void uint32_t