From 50739005ea70e12421c0815a5ee781d56d44e6c1 Mon Sep 17 00:00:00 2001 From: OlympusMonds Date: Sat, 2 Mar 2024 16:33:50 +1100 Subject: [PATCH 1/3] Add support to mitsubishi climate for sleep mode (tested for SG17B 309E remote) --- esphome/components/mitsubishi/mitsubishi.cpp | 21 ++++++++++++++++++-- esphome/components/mitsubishi/mitsubishi.h | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/esphome/components/mitsubishi/mitsubishi.cpp b/esphome/components/mitsubishi/mitsubishi.cpp index 5609a27532d8..06a7e744e092 100644 --- a/esphome/components/mitsubishi/mitsubishi.cpp +++ b/esphome/components/mitsubishi/mitsubishi.cpp @@ -31,6 +31,8 @@ const uint8_t MITSUBISHI_POWERFUL = 0x08; // Optional presets used to enable some model features const uint8_t MITSUBISHI_ECONOCOOL = 0x20; +const uint8_t MITSUBISHI_NIGHTMODE = 0xC1; +const uint8_t MITSUBISHI_DEFAULTMODE = 0x81; // Pulse parameters in usec const uint16_t MITSUBISHI_BIT_MARK = 430; @@ -82,7 +84,7 @@ climate::ClimateTraits MitsubishiClimate::traits() { climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL}); traits.set_supported_presets( - {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST}); + {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP}); return traits; } @@ -108,7 +110,6 @@ void MitsubishiClimate::transmit_state() { // Byte 15: HVAC specfic, i.e. POWERFUL, SMART SET, PLASMA, always 0x00 // Byte 16: Constant 0x00 // Byte 17: Checksum: SUM[Byte0...Byte16] - uint32_t remote_state[18] = {0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -221,6 +222,10 @@ void MitsubishiClimate::transmit_state() { remote_state[8] = (remote_state[8] & ~7) | MITSUBISHI_MODE_A_COOL; remote_state[14] = MITSUBISHI_ECONOCOOL; break; + case climate::CLIMATE_PRESET_SLEEP: + remote_state[9] = MITSUBISHI_FAN_AUTO; + remote_state[14] = MITSUBISHI_NIGHTMODE; + break; case climate::CLIMATE_PRESET_BOOST: remote_state[6] |= MITSUBISHI_OTHERWISE; remote_state[15] = MITSUBISHI_POWERFUL; @@ -367,6 +372,18 @@ bool MitsubishiClimate::on_receive(remote_base::RemoteReceiveData data) { break; } + switch (state_frame[14]) { + case MITSUBISHI_ECONOCOOL: + this->preset = climate::CLIMATE_PRESET_ECO; + break; + case MITSUBISHI_NIGHTMODE: + this->preset = climate::CLIMATE_PRESET_SLEEP; + break; + case MITSUBISHI_DEFAULTMODE: + this->preset = climate::CLIMATE_PRESET_NONE; + break; + } + ESP_LOGV(TAG, "Receiving: %s", format_hex_pretty(state_frame, 18).c_str()); this->publish_state(); diff --git a/esphome/components/mitsubishi/mitsubishi.h b/esphome/components/mitsubishi/mitsubishi.h index d228d74b1d9f..0bf14360aa47 100644 --- a/esphome/components/mitsubishi/mitsubishi.h +++ b/esphome/components/mitsubishi/mitsubishi.h @@ -48,7 +48,7 @@ class MitsubishiClimate : public climate_ir::ClimateIR { climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH, climate::CLIMATE_FAN_QUIET}, {climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH, climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL}, - {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST}) {} + {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP}) {} void set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; } void set_supports_dry(bool supports_dry) { this->supports_dry_ = supports_dry; } From e9ea1b39f1c11d02a8ec90601c22aa6c9a5d22dd Mon Sep 17 00:00:00 2001 From: OlympusMonds Date: Thu, 7 Mar 2024 19:26:25 +1100 Subject: [PATCH 2/3] Fix clang-format issues --- esphome/components/mitsubishi/mitsubishi.cpp | 4 ++-- esphome/components/mitsubishi/mitsubishi.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/mitsubishi/mitsubishi.cpp b/esphome/components/mitsubishi/mitsubishi.cpp index 06a7e744e092..6e683e1119f1 100644 --- a/esphome/components/mitsubishi/mitsubishi.cpp +++ b/esphome/components/mitsubishi/mitsubishi.cpp @@ -83,8 +83,8 @@ climate::ClimateTraits MitsubishiClimate::traits() { traits.set_supported_swing_modes({climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH, climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL}); - traits.set_supported_presets( - {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP}); + traits.set_supported_presets({climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, + climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP}); return traits; } diff --git a/esphome/components/mitsubishi/mitsubishi.h b/esphome/components/mitsubishi/mitsubishi.h index 0bf14360aa47..e8fcbcf979e1 100644 --- a/esphome/components/mitsubishi/mitsubishi.h +++ b/esphome/components/mitsubishi/mitsubishi.h @@ -48,7 +48,8 @@ class MitsubishiClimate : public climate_ir::ClimateIR { climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH, climate::CLIMATE_FAN_QUIET}, {climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH, climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL}, - {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST, climate::CLIMATE_PRESET_SLEEP}) {} + {climate::CLIMATE_PRESET_NONE, climate::CLIMATE_PRESET_ECO, climate::CLIMATE_PRESET_BOOST, + climate::CLIMATE_PRESET_SLEEP}) {} void set_supports_cool(bool supports_cool) { this->supports_cool_ = supports_cool; } void set_supports_dry(bool supports_dry) { this->supports_dry_ = supports_dry; } From 743a75fffb8330733585549a4046883bcefc575e Mon Sep 17 00:00:00 2001 From: OlympusMonds Date: Thu, 7 Mar 2024 19:26:40 +1100 Subject: [PATCH 3/3] Avoid defining a default mode --- esphome/components/mitsubishi/mitsubishi.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/esphome/components/mitsubishi/mitsubishi.cpp b/esphome/components/mitsubishi/mitsubishi.cpp index 6e683e1119f1..081c24a050cb 100644 --- a/esphome/components/mitsubishi/mitsubishi.cpp +++ b/esphome/components/mitsubishi/mitsubishi.cpp @@ -32,7 +32,6 @@ const uint8_t MITSUBISHI_POWERFUL = 0x08; // Optional presets used to enable some model features const uint8_t MITSUBISHI_ECONOCOOL = 0x20; const uint8_t MITSUBISHI_NIGHTMODE = 0xC1; -const uint8_t MITSUBISHI_DEFAULTMODE = 0x81; // Pulse parameters in usec const uint16_t MITSUBISHI_BIT_MARK = 430; @@ -379,9 +378,6 @@ bool MitsubishiClimate::on_receive(remote_base::RemoteReceiveData data) { case MITSUBISHI_NIGHTMODE: this->preset = climate::CLIMATE_PRESET_SLEEP; break; - case MITSUBISHI_DEFAULTMODE: - this->preset = climate::CLIMATE_PRESET_NONE; - break; } ESP_LOGV(TAG, "Receiving: %s", format_hex_pretty(state_frame, 18).c_str());