From 40c1331b8a7a876173571041b0099e6bffed592f Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 09:06:59 +0200 Subject: [PATCH 1/9] Added support for LG wall hvac --- sonoff/my_user_config.h | 5 +- sonoff/xdrv_05_irremote.ino | 133 ++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 3e0efdef4..154c5bd7f 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -36,7 +36,8 @@ * Users are advised to use the user_config_override.h file for most changes. \*********************************************************************************************/ -//#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md +#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md +#warning Override settings are used :-) /*********************************************************************************************\ * SECTION 1 @@ -366,7 +367,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index dd8178c12..56ad491d9 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -44,6 +44,9 @@ const char kIrRemoteProtocols[] PROGMEM = #define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit #define HVAC_TOSHIBA_DATALEN 9 +// HVAC LG +#define HVAC_LG_DATALEN 7 + IRMitsubishiAC *mitsubir = NULL; const char kFanSpeedOptions[] = "A12345S"; @@ -137,6 +140,10 @@ void IrReceiveCheck(void) * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library \*********************************************************************************************/ +/******************* + TOSCHIBA +********************/ + boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; @@ -226,6 +233,11 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H return false; } + +/******************* + MITSUBISHI +********************/ + boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { char *p; @@ -269,6 +281,124 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea return false; } + + +/******************* + LG +********************/ + +boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) +{ + uint32_t LG_Code; + byte data[HVAC_LG_DATALEN]; + static boolean hvacOn = false; + char *p; + uint8_t mode; + byte Temp; + + // Constant data + data[0] = 0x08; + data[1] = 0x08; + data[2] = 0x00; + + if (!HVAC_Power) { + data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051 + data[3] = (byte)0x00; + data[4] = (byte)0x00; + data[5] = (byte)0x05; + data[6] = (byte)0x01; + hvacOn = false; + } + + else { + + // Set code for HVAC Mode - data[3] + if (HVAC_Mode == NULL) { + p = (char *)kHvacModeOptions; // default HVAC_HOT + } + else { + p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0])); + } + if (!p) { + return true; + } + mode = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00 + switch (mode) { + case 0: // AUTO + data[3] = 11; + break; + case 1: // COOL + data[3] = 8; + break; + case 2: // DRY + data[3] = 9; + break; + case 3: // HOT + data[3] = 12; + break; + } + if (!hvacOn) { + data[3] = data[3] & 7; // reset bit3 + hvacOn = true; + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); + AddLog(LOG_LEVEL_DEBUG); + + // Set code for HVAC temperature - data[4] + if (HVAC_Temp > 30) { + Temp = 30; + } + else if (HVAC_Temp < 18) { + Temp = 18; + } + else { + Temp = HVAC_Temp; + } + data[4] = (byte)(Temp - 15); + + // Set code for HVAC fan mode - data[5] + if (HVAC_FanMode == NULL) { + p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO + } + else { + p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0])); + } + if (!p) { + return true; + } + mode = p - kFanSpeedOptions; + if ((mode == 0) || (mode > 3)) { + data[5] = 5; // Auto = 0x05 + } + else { + data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); + AddLog(LOG_LEVEL_DEBUG); + + // Set CRC code - data[6] + data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC + + } + // Build LG IR code + LG_Code = data[0] << 4; + for (int i = 1; i < 6; i++) { + LG_Code = (LG_Code + data[i]) << 4; + } + LG_Code = LG_Code + data[6]; + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); + AddLog(LOG_LEVEL_DEBUG); + + // Send LG IR Code + noInterrupts(); + irsend->sendLG(LG_Code, 28); + interrupts(); + + return false; +} #endif // USE_IR_HVAC /*********************************************************************************************\ @@ -381,6 +511,9 @@ boolean IrSendCommand(void) else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) { error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); } + else if (!strcasecmp_P(HVAC_Vendor, PSTR("LG"))) { + error = IrHvacLG(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); + } else { error = true; } From 3be1b7a1e0ee2f40b93a8ccdf7ebf964bd7e3eef Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:03:02 +0200 Subject: [PATCH 2/9] Revert "Added support for LG wall hvac" This reverts commit 40c1331b8a7a876173571041b0099e6bffed592f. --- sonoff/my_user_config.h | 5 +- sonoff/xdrv_05_irremote.ino | 133 ------------------------------------ 2 files changed, 2 insertions(+), 136 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 154c5bd7f..3e0efdef4 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -36,8 +36,7 @@ * Users are advised to use the user_config_override.h file for most changes. \*********************************************************************************************/ -#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md -#warning Override settings are used :-) +//#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md /*********************************************************************************************\ * SECTION 1 @@ -367,7 +366,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 56ad491d9..dd8178c12 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -44,9 +44,6 @@ const char kIrRemoteProtocols[] PROGMEM = #define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit #define HVAC_TOSHIBA_DATALEN 9 -// HVAC LG -#define HVAC_LG_DATALEN 7 - IRMitsubishiAC *mitsubir = NULL; const char kFanSpeedOptions[] = "A12345S"; @@ -140,10 +137,6 @@ void IrReceiveCheck(void) * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library \*********************************************************************************************/ -/******************* - TOSCHIBA -********************/ - boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; @@ -233,11 +226,6 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H return false; } - -/******************* - MITSUBISHI -********************/ - boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { char *p; @@ -281,124 +269,6 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea return false; } - - -/******************* - LG -********************/ - -boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) -{ - uint32_t LG_Code; - byte data[HVAC_LG_DATALEN]; - static boolean hvacOn = false; - char *p; - uint8_t mode; - byte Temp; - - // Constant data - data[0] = 0x08; - data[1] = 0x08; - data[2] = 0x00; - - if (!HVAC_Power) { - data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051 - data[3] = (byte)0x00; - data[4] = (byte)0x00; - data[5] = (byte)0x05; - data[6] = (byte)0x01; - hvacOn = false; - } - - else { - - // Set code for HVAC Mode - data[3] - if (HVAC_Mode == NULL) { - p = (char *)kHvacModeOptions; // default HVAC_HOT - } - else { - p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0])); - } - if (!p) { - return true; - } - mode = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00 - switch (mode) { - case 0: // AUTO - data[3] = 11; - break; - case 1: // COOL - data[3] = 8; - break; - case 2: // DRY - data[3] = 9; - break; - case 3: // HOT - data[3] = 12; - break; - } - if (!hvacOn) { - data[3] = data[3] & 7; // reset bit3 - hvacOn = true; - } - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); - AddLog(LOG_LEVEL_DEBUG); - - // Set code for HVAC temperature - data[4] - if (HVAC_Temp > 30) { - Temp = 30; - } - else if (HVAC_Temp < 18) { - Temp = 18; - } - else { - Temp = HVAC_Temp; - } - data[4] = (byte)(Temp - 15); - - // Set code for HVAC fan mode - data[5] - if (HVAC_FanMode == NULL) { - p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO - } - else { - p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0])); - } - if (!p) { - return true; - } - mode = p - kFanSpeedOptions; - if ((mode == 0) || (mode > 3)) { - data[5] = 5; // Auto = 0x05 - } - else { - data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 - } - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); - AddLog(LOG_LEVEL_DEBUG); - - // Set CRC code - data[6] - data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC - - } - // Build LG IR code - LG_Code = data[0] << 4; - for (int i = 1; i < 6; i++) { - LG_Code = (LG_Code + data[i]) << 4; - } - LG_Code = LG_Code + data[6]; - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); - AddLog(LOG_LEVEL_DEBUG); - - // Send LG IR Code - noInterrupts(); - irsend->sendLG(LG_Code, 28); - interrupts(); - - return false; -} #endif // USE_IR_HVAC /*********************************************************************************************\ @@ -511,9 +381,6 @@ boolean IrSendCommand(void) else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) { error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); } - else if (!strcasecmp_P(HVAC_Vendor, PSTR("LG"))) { - error = IrHvacLG(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); - } else { error = true; } From 7e576a58f93086397afb504e9fd3922ad8f0688e Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:05:50 +0200 Subject: [PATCH 3/9] commented user override to pass travis ci test --- sonoff/my_user_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 3e0efdef4..8634b5be7 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -38,6 +38,7 @@ //#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md + /*********************************************************************************************\ * SECTION 1 * - After initial load any change here only take effect if CFG_HOLDER is changed too @@ -366,7 +367,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // From 1900aec31889631aa92d367e6b52c3894ed4a927 Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:08:48 +0200 Subject: [PATCH 4/9] Revert "commented user override to pass travis ci test" This reverts commit 7e576a58f93086397afb504e9fd3922ad8f0688e. --- sonoff/my_user_config.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 8634b5be7..3e0efdef4 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -38,7 +38,6 @@ //#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md - /*********************************************************************************************\ * SECTION 1 * - After initial load any change here only take effect if CFG_HOLDER is changed too @@ -367,7 +366,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // From 68e78036512d352dd46b40151f358beb9ae1d55c Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:15:54 +0200 Subject: [PATCH 5/9] add support to LG wall HVAC systems --- sonoff/my_user_config.h | 3 +- sonoff/xdrv_05_irremote.ino | 138 ++++++++++++++++++++++++++++++++++-- 2 files changed, 135 insertions(+), 6 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 3e0efdef4..8634b5be7 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -38,6 +38,7 @@ //#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md + /*********************************************************************************************\ * SECTION 1 * - After initial load any change here only take effect if CFG_HOLDER is changed too @@ -366,7 +367,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index dd8178c12..8bd267759 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -1,18 +1,14 @@ /* xdrv_05_irremote.ino - infra red support for Sonoff-Tasmota - Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -44,6 +40,9 @@ const char kIrRemoteProtocols[] PROGMEM = #define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit #define HVAC_TOSHIBA_DATALEN 9 +// HVAC LG +#define HVAC_LG_DATALEN 7 + IRMitsubishiAC *mitsubir = NULL; const char kFanSpeedOptions[] = "A12345S"; @@ -137,6 +136,10 @@ void IrReceiveCheck(void) * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library \*********************************************************************************************/ +/******************* + TOSHIBA +********************/ + boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; @@ -226,6 +229,11 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H return false; } + +/******************* + MITSUBISHI +********************/ + boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { char *p; @@ -269,6 +277,124 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea return false; } + + +/******************* + LG +********************/ + +boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) +{ + uint32_t LG_Code; + byte data[HVAC_LG_DATALEN]; + static boolean hvacOn = false; + char *p; + uint8_t mode; + byte Temp; + + // Constant data + data[0] = 0x08; + data[1] = 0x08; + data[2] = 0x00; + + if (!HVAC_Power) { + data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051 + data[3] = (byte)0x00; + data[4] = (byte)0x00; + data[5] = (byte)0x05; + data[6] = (byte)0x01; + hvacOn = false; + } + + else { + + // Set code for HVAC Mode - data[3] + if (HVAC_Mode == NULL) { + p = (char *)kHvacModeOptions; // default HVAC_HOT + } + else { + p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0])); + } + if (!p) { + return true; + } + mode = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00 + switch (mode) { + case 0: // AUTO + data[3] = 11; + break; + case 1: // COOL + data[3] = 8; + break; + case 2: // DRY + data[3] = 9; + break; + case 3: // HOT + data[3] = 12; + break; + } + if (!hvacOn) { + data[3] = data[3] & 7; // reset bit3 + hvacOn = true; + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); + AddLog(LOG_LEVEL_DEBUG); + + // Set code for HVAC temperature - data[4] + if (HVAC_Temp > 30) { + Temp = 30; + } + else if (HVAC_Temp < 18) { + Temp = 18; + } + else { + Temp = HVAC_Temp; + } + data[4] = (byte)(Temp - 15); + + // Set code for HVAC fan mode - data[5] + if (HVAC_FanMode == NULL) { + p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO + } + else { + p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0])); + } + if (!p) { + return true; + } + mode = p - kFanSpeedOptions; + if ((mode == 0) || (mode > 3)) { + data[5] = 5; // Auto = 0x05 + } + else { + data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); + AddLog(LOG_LEVEL_DEBUG); + + // Set CRC code - data[6] + data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC + + } + // Build LG IR code + LG_Code = data[0] << 4; + for (int i = 1; i < 6; i++) { + LG_Code = (LG_Code + data[i]) << 4; + } + LG_Code = LG_Code + data[6]; + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); + AddLog(LOG_LEVEL_DEBUG); + + // Send LG IR Code + noInterrupts(); + irsend->sendLG(LG_Code, 28); + interrupts(); + + return false; +} #endif // USE_IR_HVAC /*********************************************************************************************\ @@ -279,7 +405,6 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea * ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96 IRsend: { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } - IRhvac: { "Vendor": "", "Power": <0|1>, "Mode": "", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> } */ @@ -381,6 +506,9 @@ boolean IrSendCommand(void) else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) { error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); } + else if (!strcasecmp_P(HVAC_Vendor, PSTR("LG"))) { + error = IrHvacLG(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); + } else { error = true; } From 13c7958c9924c0467d919033afe34aad869ec960 Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:28:23 +0200 Subject: [PATCH 6/9] Revert "add support to LG wall HVAC systems" This reverts commit 68e78036512d352dd46b40151f358beb9ae1d55c. --- sonoff/my_user_config.h | 3 +- sonoff/xdrv_05_irremote.ino | 138 ++---------------------------------- 2 files changed, 6 insertions(+), 135 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 8634b5be7..3e0efdef4 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -38,7 +38,6 @@ //#define USE_CONFIG_OVERRIDE // Uncomment to use user_config_override.h file. See README.md - /*********************************************************************************************\ * SECTION 1 * - After initial load any change here only take effect if CFG_HOLDER is changed too @@ -367,7 +366,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -#define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 8bd267759..dd8178c12 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -1,14 +1,18 @@ /* xdrv_05_irremote.ino - infra red support for Sonoff-Tasmota + Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -40,9 +44,6 @@ const char kIrRemoteProtocols[] PROGMEM = #define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit #define HVAC_TOSHIBA_DATALEN 9 -// HVAC LG -#define HVAC_LG_DATALEN 7 - IRMitsubishiAC *mitsubir = NULL; const char kFanSpeedOptions[] = "A12345S"; @@ -136,10 +137,6 @@ void IrReceiveCheck(void) * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library \*********************************************************************************************/ -/******************* - TOSHIBA -********************/ - boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; @@ -229,11 +226,6 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H return false; } - -/******************* - MITSUBISHI -********************/ - boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { char *p; @@ -277,124 +269,6 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea return false; } - - -/******************* - LG -********************/ - -boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) -{ - uint32_t LG_Code; - byte data[HVAC_LG_DATALEN]; - static boolean hvacOn = false; - char *p; - uint8_t mode; - byte Temp; - - // Constant data - data[0] = 0x08; - data[1] = 0x08; - data[2] = 0x00; - - if (!HVAC_Power) { - data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051 - data[3] = (byte)0x00; - data[4] = (byte)0x00; - data[5] = (byte)0x05; - data[6] = (byte)0x01; - hvacOn = false; - } - - else { - - // Set code for HVAC Mode - data[3] - if (HVAC_Mode == NULL) { - p = (char *)kHvacModeOptions; // default HVAC_HOT - } - else { - p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0])); - } - if (!p) { - return true; - } - mode = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00 - switch (mode) { - case 0: // AUTO - data[3] = 11; - break; - case 1: // COOL - data[3] = 8; - break; - case 2: // DRY - data[3] = 9; - break; - case 3: // HOT - data[3] = 12; - break; - } - if (!hvacOn) { - data[3] = data[3] & 7; // reset bit3 - hvacOn = true; - } - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); - AddLog(LOG_LEVEL_DEBUG); - - // Set code for HVAC temperature - data[4] - if (HVAC_Temp > 30) { - Temp = 30; - } - else if (HVAC_Temp < 18) { - Temp = 18; - } - else { - Temp = HVAC_Temp; - } - data[4] = (byte)(Temp - 15); - - // Set code for HVAC fan mode - data[5] - if (HVAC_FanMode == NULL) { - p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO - } - else { - p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0])); - } - if (!p) { - return true; - } - mode = p - kFanSpeedOptions; - if ((mode == 0) || (mode > 3)) { - data[5] = 5; // Auto = 0x05 - } - else { - data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 - } - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); - AddLog(LOG_LEVEL_DEBUG); - - // Set CRC code - data[6] - data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC - - } - // Build LG IR code - LG_Code = data[0] << 4; - for (int i = 1; i < 6; i++) { - LG_Code = (LG_Code + data[i]) << 4; - } - LG_Code = LG_Code + data[6]; - - snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); - AddLog(LOG_LEVEL_DEBUG); - - // Send LG IR Code - noInterrupts(); - irsend->sendLG(LG_Code, 28); - interrupts(); - - return false; -} #endif // USE_IR_HVAC /*********************************************************************************************\ @@ -405,6 +279,7 @@ boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_P * ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96 IRsend: { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } + IRhvac: { "Vendor": "", "Power": <0|1>, "Mode": "", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> } */ @@ -506,9 +381,6 @@ boolean IrSendCommand(void) else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) { error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); } - else if (!strcasecmp_P(HVAC_Vendor, PSTR("LG"))) { - error = IrHvacLG(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); - } else { error = true; } From beb9d0ff841e8c9b6b871f2d415bc075d6a2767b Mon Sep 17 00:00:00 2001 From: evzone Date: Sun, 18 Nov 2018 11:35:53 +0200 Subject: [PATCH 7/9] add IR support to LG wall HVAC systems --- .../src/IRremoteESP8266.h | 4 +- sonoff/my_user_config.h | 2 +- sonoff/xdrv_05_irremote.ino | 138 +++++++++++++++++- 3 files changed, 136 insertions(+), 8 deletions(-) diff --git a/lib/IRremoteESP8266-2.2.1.02/src/IRremoteESP8266.h b/lib/IRremoteESP8266-2.2.1.02/src/IRremoteESP8266.h index e2dc26904..f2c730dee 100644 --- a/lib/IRremoteESP8266-2.2.1.02/src/IRremoteESP8266.h +++ b/lib/IRremoteESP8266-2.2.1.02/src/IRremoteESP8266.h @@ -171,8 +171,8 @@ #define DECODE_AIWA_RC_T501 false #define SEND_AIWA_RC_T501 false -#define DECODE_LG false -#define SEND_LG false +#define DECODE_LG true +#define SEND_LG true #define DECODE_SANYO false #define SEND_SANYO false diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 3e0efdef4..9d5b871c4 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -366,7 +366,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) -// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) + #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index dd8178c12..8bd267759 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -1,18 +1,14 @@ /* xdrv_05_irremote.ino - infra red support for Sonoff-Tasmota - Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -44,6 +40,9 @@ const char kIrRemoteProtocols[] PROGMEM = #define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit #define HVAC_TOSHIBA_DATALEN 9 +// HVAC LG +#define HVAC_LG_DATALEN 7 + IRMitsubishiAC *mitsubir = NULL; const char kFanSpeedOptions[] = "A12345S"; @@ -137,6 +136,10 @@ void IrReceiveCheck(void) * IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library \*********************************************************************************************/ +/******************* + TOSHIBA +********************/ + boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2]; @@ -226,6 +229,11 @@ boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean H return false; } + +/******************* + MITSUBISHI +********************/ + boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) { char *p; @@ -269,6 +277,124 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea return false; } + + +/******************* + LG +********************/ + +boolean IrHvacLG(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp) +{ + uint32_t LG_Code; + byte data[HVAC_LG_DATALEN]; + static boolean hvacOn = false; + char *p; + uint8_t mode; + byte Temp; + + // Constant data + data[0] = 0x08; + data[1] = 0x08; + data[2] = 0x00; + + if (!HVAC_Power) { + data[2] = (byte)0x0C; // Turn OFF HVAC, code 0x88C0051 + data[3] = (byte)0x00; + data[4] = (byte)0x00; + data[5] = (byte)0x05; + data[6] = (byte)0x01; + hvacOn = false; + } + + else { + + // Set code for HVAC Mode - data[3] + if (HVAC_Mode == NULL) { + p = (char *)kHvacModeOptions; // default HVAC_HOT + } + else { + p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0])); + } + if (!p) { + return true; + } + mode = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00 + switch (mode) { + case 0: // AUTO + data[3] = 11; + break; + case 1: // COOL + data[3] = 8; + break; + case 2: // DRY + data[3] = 9; + break; + case 3: // HOT + data[3] = 12; + break; + } + if (!hvacOn) { + data[3] = data[3] & 7; // reset bit3 + hvacOn = true; + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: HvacMode %s, ModeVal %d, Code %d"), p, mode, data[3]); + AddLog(LOG_LEVEL_DEBUG); + + // Set code for HVAC temperature - data[4] + if (HVAC_Temp > 30) { + Temp = 30; + } + else if (HVAC_Temp < 18) { + Temp = 18; + } + else { + Temp = HVAC_Temp; + } + data[4] = (byte)(Temp - 15); + + // Set code for HVAC fan mode - data[5] + if (HVAC_FanMode == NULL) { + p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO + } + else { + p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0])); + } + if (!p) { + return true; + } + mode = p - kFanSpeedOptions; + if ((mode == 0) || (mode > 3)) { + data[5] = 5; // Auto = 0x05 + } + else { + data[5] = (mode * 2) - 2; // Low = 0x00, Mid = 0x02, High = 0x04 + } + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: FanMode %s, ModeVal %d, Code %d"), p, mode, data[5]); + AddLog(LOG_LEVEL_DEBUG); + + // Set CRC code - data[6] + data[6] = (data[3] + data[4] + data[5]) & 0x0f; // CRC + + } + // Build LG IR code + LG_Code = data[0] << 4; + for (int i = 1; i < 6; i++) { + LG_Code = (LG_Code + data[i]) << 4; + } + LG_Code = LG_Code + data[6]; + + snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: LG_Code %d"), LG_Code); + AddLog(LOG_LEVEL_DEBUG); + + // Send LG IR Code + noInterrupts(); + irsend->sendLG(LG_Code, 28); + interrupts(); + + return false; +} #endif // USE_IR_HVAC /*********************************************************************************************\ @@ -279,7 +405,6 @@ boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolea * ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96 IRsend: { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } - IRhvac: { "Vendor": "", "Power": <0|1>, "Mode": "", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> } */ @@ -381,6 +506,9 @@ boolean IrSendCommand(void) else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) { error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); } + else if (!strcasecmp_P(HVAC_Vendor, PSTR("LG"))) { + error = IrHvacLG(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp); + } else { error = true; } From fe7f154b257aa7cbc69f5644f908a0e5ea0d5029 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 19 Nov 2018 10:59:01 +0100 Subject: [PATCH 8/9] Update my_user_config.h --- sonoff/my_user_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 9d5b871c4..3e0efdef4 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -366,7 +366,7 @@ // -- Low level interface devices ----------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram) - #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) +// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code) #define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram) #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // From 288fefebb74f67cfa2c3fbdba359b409a0a098ae Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 19 Nov 2018 11:00:24 +0100 Subject: [PATCH 9/9] Update xdrv_05_irremote.ino --- sonoff/xdrv_05_irremote.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 8bd267759..03f3a739f 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -1,14 +1,18 @@ /* xdrv_05_irremote.ino - infra red support for Sonoff-Tasmota + Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . */