From 9f954ed601ee6792c28c73d90313ce15c387d816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:15:52 +0300 Subject: [PATCH 01/26] Added error code monitoring feature and error_codes.py --- components/samsung_ac/__init__.py | 19 ++++++++++++++++++- components/samsung_ac/error_codes.py | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 components/samsung_ac/error_codes.py diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 74088120..779d5c0f 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -16,6 +16,7 @@ CORE, Lambda ) +from .error_codes import ERROR_CODES CODEOWNERS = ["matthias882", "lanwin"] DEPENDENCIES = ["uart"] @@ -72,6 +73,8 @@ CONF_DEVICE_CUSTOM = "custom_sensor" CONF_DEVICE_CUSTOM_MESSAGE = "message" CONF_DEVICE_CUSTOM_RAW_FILTERS = "raw_filters" +CONF_DEVICE_ERROR_CODE = "error_code" + CONF_CAPABILITIES = "capabilities" CONF_CAPABILITIES_HORIZONTAL_SWING = "horizontal_swing" @@ -166,7 +169,14 @@ def humidity_sensor_schema(message: int): state_class=STATE_CLASS_MEASUREMENT, ) - +def error_code_sensor_schema(message: int): + return custom_sensor_schema( + message=message, + unit_of_measurement="", + accuracy_decimals=0, + icon="mdi:alert", + ) + DEVICE_SCHEMA = ( cv.Schema( { @@ -212,6 +222,7 @@ def humidity_sensor_schema(message: int): # keep CUSTOM_SENSOR_KEYS in sync with these cv.Optional(CONF_DEVICE_WATER_TEMPERATURE): temperature_sensor_schema(0x4237), cv.Optional(CONF_DEVICE_ROOM_HUMIDITY): humidity_sensor_schema(0x4038), + cv.Optional(CONF_DEVICE_ERROR_CODE): error_code_sensor_schema(0x8235), } ) ) @@ -219,6 +230,7 @@ def humidity_sensor_schema(message: int): CUSTOM_SENSOR_KEYS = [ CONF_DEVICE_WATER_TEMPERATURE, CONF_DEVICE_ROOM_HUMIDITY, + CONF_DEVICE_ERROR_CODE, ] CONF_DEVICES = "devices" @@ -401,6 +413,11 @@ async def to_code(config): var_cli = cg.new_Pvariable(conf[CONF_ID]) await climate.register_climate(var_cli, conf) cg.add(var_dev.set_climate(var_cli)) + + if CONF_DEVICE_ERROR_CODE in device: + conf = device[CONF_DEVICE_ERROR_CODE] + sens = await sensor.new_sensor(conf) + cg.add(var_dev.set_error_code_sensor(sens)) if CONF_DEVICE_CUSTOM in device: for cust_sens in device[CONF_DEVICE_CUSTOM]: diff --git a/components/samsung_ac/error_codes.py b/components/samsung_ac/error_codes.py new file mode 100644 index 00000000..38a13e68 --- /dev/null +++ b/components/samsung_ac/error_codes.py @@ -0,0 +1,4 @@ +ERROR_CODES = { + 201: "Communication error between indoor and outdoor units (installation number setting error,repeated indoor unit address, indoor unit communication cable error)", + # ... +} \ No newline at end of file From 2f027eab269780ae3331fd729572a18d6f2f3280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:33:41 +0300 Subject: [PATCH 02/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 13 ++++++++++++- components/samsung_ac/protocol_nasa.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 7e43a53e..e8aefcde 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -712,6 +712,13 @@ namespace esphome target->set_indoor_eva_out_temperature(source, temp); break; } + case MessageNumber::VAR_out_error_code: + { + LOG_MESSAGE(VAR_out_error_code, (double)message.value, source, dest); + target->publish_error_code(source, message.value); + break; + } + default: { double value = 0; @@ -923,8 +930,12 @@ namespace esphome break; case 0x8235: // VAR_out_error_code - LOG_MESSAGE(VAR_out_error_code, message.value, source, dest); + { + int error_code = message.value; + LOG_MESSAGE(VAR_out_error_code, error_code, source, dest); + target->publish_error_code(source, error_code); break; + } case 0x8261: // VAR_OUT_SENSOR_PIPEIN3 unit = 'Celsius' { diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index ff1fd25e..069a7203 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -89,6 +89,7 @@ namespace esphome VAR_in_temp_water_heater_target_f = 0x4235, VAR_in_temp_eva_in_f = 0x4205, VAR_in_temp_eva_out_f = 0x4206, + VAR_out_error_code = 0x8235, }; struct Address @@ -177,6 +178,7 @@ namespace esphome NasaProtocol() = default; void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; + virtual void publish_error_code(const std::string &source, int error_code) = 0; void protocol_update(MessageTarget *target) override; }; From f4cd35e2d4b26e8f06bf331768e6ed0f4252bbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:34:58 +0300 Subject: [PATCH 03/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 069a7203..913ec927 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -178,7 +178,7 @@ namespace esphome NasaProtocol() = default; void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; - virtual void publish_error_code(const std::string &source, int error_code) = 0; + void publish_error_code(const std::string &source, int error_code) = 0; void protocol_update(MessageTarget *target) override; }; From 6a6b48b1fe3344d4a405a0f66e983d497ba8a572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:40:03 +0300 Subject: [PATCH 04/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 87760425..74e3c2e8 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -94,6 +94,7 @@ namespace esphome virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0; virtual optional> get_custom_sensors(const std::string address) = 0; virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0; + virtual void publish_error_code(const std::string &source, int error_code) = 0; }; struct ProtocolRequest From 932a0cfbbbdec25ebf1c5f22e5bea07e14aef80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:40:42 +0300 Subject: [PATCH 05/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 913ec927..069a7203 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -178,7 +178,7 @@ namespace esphome NasaProtocol() = default; void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; - void publish_error_code(const std::string &source, int error_code) = 0; + virtual void publish_error_code(const std::string &source, int error_code) = 0; void protocol_update(MessageTarget *target) override; }; From 5abb97ffc08d105b3842e589d27b9d5a5125c836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:47:11 +0300 Subject: [PATCH 06/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 5 +++++ components/samsung_ac/protocol_nasa.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index e8aefcde..daa0779b 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -1233,6 +1233,11 @@ namespace esphome } } + void NasaProtocol::publish_error_code(const std::string &source, int error_code) + { + ESP_LOGW(TAG, "Error code from %s: %d", source.c_str(), error_code); + } + void NasaProtocol::protocol_update(MessageTarget *target) { // Unused for NASA protocol diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 069a7203..acd422d0 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -178,8 +178,8 @@ namespace esphome NasaProtocol() = default; void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; - virtual void publish_error_code(const std::string &source, int error_code) = 0; void protocol_update(MessageTarget *target) override; + virtual void publish_error_code(const std::string &source, int error_code) override; }; } // namespace samsung_ac From d85412ae35d4cb1e696db6dee0e25ade1b7c2397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 14:54:00 +0300 Subject: [PATCH 07/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/samsung_ac.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 800ec621..4462f2de 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -143,7 +143,7 @@ namespace esphome if (dev != nullptr) dev->update_mode(mode); } - + void /*MessageTarget::*/ set_water_heater_mode(const std::string address, WaterHeaterMode waterheatermode) override { Samsung_AC_Device *dev = find_device(address); @@ -194,6 +194,11 @@ namespace esphome dev->update_custom_sensor(message_number, value); } + void publish_error_code(const std::string &source, int error_code) override + { + ESP_LOGW("Samsung_AC", "Error code from %s: %d", source.c_str(), error_code); + } + protected: Samsung_AC_Device *find_device(const std::string address) { From f3b32fb9726fc0c5dce380e6ea799da8bd57be01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:00:05 +0300 Subject: [PATCH 08/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol.h | 2 +- components/samsung_ac/protocol_nasa.cpp | 4 ++-- components/samsung_ac/protocol_nasa.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 74e3c2e8..54a65720 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -94,7 +94,7 @@ namespace esphome virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0; virtual optional> get_custom_sensors(const std::string address) = 0; virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0; - virtual void publish_error_code(const std::string &source, int error_code) = 0; + virtual void publish_error_code(const std::string &source, int error_code); }; struct ProtocolRequest diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index daa0779b..097fcaa8 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -1233,9 +1233,9 @@ namespace esphome } } - void NasaProtocol::publish_error_code(const std::string &source, int error_code) + void MessageTarget::publish_error_code(const std::string &source, int error_code) { - ESP_LOGW(TAG, "Error code from %s: %d", source.c_str(), error_code); + ESP_LOGW("ERROR", "Error code from %s: %d", source.c_str(), error_code); } void NasaProtocol::protocol_update(MessageTarget *target) diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index acd422d0..370afd9b 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -179,7 +179,7 @@ namespace esphome void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void protocol_update(MessageTarget *target) override; - virtual void publish_error_code(const std::string &source, int error_code) override; + virtual void publish_error_code(const std::string &source, int error_code); }; } // namespace samsung_ac From 82b5aad0cb6254253e039fae008ef16c0ca8d62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:04:46 +0300 Subject: [PATCH 09/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 5 ++++- components/samsung_ac/protocol_nasa.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 097fcaa8..9ebc558c 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -1237,7 +1237,10 @@ namespace esphome { ESP_LOGW("ERROR", "Error code from %s: %d", source.c_str(), error_code); } - + void NasaProtocol::publish_error_code(const std::string &source, int error_code) + { + ESP_LOGW("NasaProtocol", "Error Code from %s: %d", source.c_str(), error_code); + } void NasaProtocol::protocol_update(MessageTarget *target) { // Unused for NASA protocol diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 370afd9b..acd422d0 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -179,7 +179,7 @@ namespace esphome void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void protocol_update(MessageTarget *target) override; - virtual void publish_error_code(const std::string &source, int error_code); + virtual void publish_error_code(const std::string &source, int error_code) override; }; } // namespace samsung_ac From 489bf3142c194cb7dac8cfa403fdf4f97f569864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:10:20 +0300 Subject: [PATCH 10/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol.h | 4 ++-- components/samsung_ac/protocol_nasa.cpp | 2 +- components/samsung_ac/protocol_nasa.h | 2 +- components/samsung_ac/samsung_ac.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 54a65720..56c619ad 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -32,7 +32,7 @@ namespace esphome Fan = 3, Heat = 4, }; - + enum class WaterHeaterMode { Unknown = -1, @@ -94,7 +94,7 @@ namespace esphome virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0; virtual optional> get_custom_sensors(const std::string address) = 0; virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0; - virtual void publish_error_code(const std::string &source, int error_code); + virtual void publish_error_code(const std::string &source, int error_code) = 0; }; struct ProtocolRequest diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 9ebc558c..ea1bd490 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -1239,7 +1239,7 @@ namespace esphome } void NasaProtocol::publish_error_code(const std::string &source, int error_code) { - ESP_LOGW("NasaProtocol", "Error Code from %s: %d", source.c_str(), error_code); + ESP_LOGW("ERROR", "Error code from %s: %d", source.c_str(), error_code); } void NasaProtocol::protocol_update(MessageTarget *target) { diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index acd422d0..7d25f1b9 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -179,7 +179,7 @@ namespace esphome void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void protocol_update(MessageTarget *target) override; - virtual void publish_error_code(const std::string &source, int error_code) override; + void publish_error_code(const std::string &source, int error_code); }; } // namespace samsung_ac diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 4462f2de..2c4cd0dd 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -194,7 +194,7 @@ namespace esphome dev->update_custom_sensor(message_number, value); } - void publish_error_code(const std::string &source, int error_code) override + void publish_error_code(const std::string &source, int error_code) { ESP_LOGW("Samsung_AC", "Error code from %s: %d", source.c_str(), error_code); } From 51384d8cee66175b008da8076ace35d16c7e78ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:35:46 +0300 Subject: [PATCH 11/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/__init__.py | 12 ++++++------ components/samsung_ac/protocol.h | 2 +- components/samsung_ac/protocol_nasa.cpp | 12 ++---------- components/samsung_ac/protocol_nasa.h | 1 - components/samsung_ac/samsung_ac.h | 7 ++++--- components/samsung_ac/samsung_ac_device.h | 18 +++++++++++++++--- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 779d5c0f..bb8bde6c 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -365,7 +365,12 @@ async def to_code(config): conf = device[CONF_DEVICE_INDOOR_EVA_OUT_TEMPERATURE] sens = await sensor.new_sensor(conf) cg.add(var_dev.set_indoor_eva_out_temperature_sensor(sens)) - + + if CONF_DEVICE_ERROR_CODE in device: + conf = device[CONF_DEVICE_ERROR_CODE] + sens = await sensor.new_sensor(conf) + cg.add(var_dev.set_error_code_sensor(sens)) + if CONF_DEVICE_WATER_TARGET_TEMPERATURE in device: conf = device[CONF_DEVICE_WATER_TARGET_TEMPERATURE] conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS @@ -413,11 +418,6 @@ async def to_code(config): var_cli = cg.new_Pvariable(conf[CONF_ID]) await climate.register_climate(var_cli, conf) cg.add(var_dev.set_climate(var_cli)) - - if CONF_DEVICE_ERROR_CODE in device: - conf = device[CONF_DEVICE_ERROR_CODE] - sens = await sensor.new_sensor(conf) - cg.add(var_dev.set_error_code_sensor(sens)) if CONF_DEVICE_CUSTOM in device: for cust_sens in device[CONF_DEVICE_CUSTOM]: diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 56c619ad..b7e0bfc4 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -94,7 +94,7 @@ namespace esphome virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0; virtual optional> get_custom_sensors(const std::string address) = 0; virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0; - virtual void publish_error_code(const std::string &source, int error_code) = 0; + virtual void set_error_code(const std::string address, int error_code) = 0; }; struct ProtocolRequest diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index ea1bd490..026918de 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -714,8 +714,8 @@ namespace esphome } case MessageNumber::VAR_out_error_code: { - LOG_MESSAGE(VAR_out_error_code, (double)message.value, source, dest); - target->publish_error_code(source, message.value); + LOG_MESSAGE(VAR_out_error_code, (int)message.value, source, dest); + target->set_error_code(source, message.value); break; } @@ -1233,14 +1233,6 @@ namespace esphome } } - void MessageTarget::publish_error_code(const std::string &source, int error_code) - { - ESP_LOGW("ERROR", "Error code from %s: %d", source.c_str(), error_code); - } - void NasaProtocol::publish_error_code(const std::string &source, int error_code) - { - ESP_LOGW("ERROR", "Error code from %s: %d", source.c_str(), error_code); - } void NasaProtocol::protocol_update(MessageTarget *target) { // Unused for NASA protocol diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 7d25f1b9..b987e24b 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -179,7 +179,6 @@ namespace esphome void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) override; void protocol_update(MessageTarget *target) override; - void publish_error_code(const std::string &source, int error_code); }; } // namespace samsung_ac diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 2c4cd0dd..968e6908 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -193,10 +193,11 @@ namespace esphome if (dev != nullptr) dev->update_custom_sensor(message_number, value); } - - void publish_error_code(const std::string &source, int error_code) + void /*MessageTarget::*/ set_error_code(const std::string address, int value) override { - ESP_LOGW("Samsung_AC", "Error code from %s: %d", source.c_str(), error_code); + Samsung_AC_Device *dev = find_device(address); + if (dev != nullptr) + dev->update_error_code(value); } protected: diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index 376d3408..e80c8e93 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -56,7 +56,7 @@ namespace esphome std::function write_state_; }; - + class Samsung_AC_Water_Heater_Mode_Select : public select::Select { public: @@ -107,6 +107,7 @@ namespace esphome sensor::Sensor *outdoor_temperature{nullptr}; sensor::Sensor *indoor_eva_in_temperature{nullptr}; sensor::Sensor *indoor_eva_out_temperature{nullptr}; + sensor::Sensor *error_code{nullptr}; Samsung_AC_Number *target_temperature{nullptr}; Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; @@ -139,6 +140,11 @@ namespace esphome indoor_eva_out_temperature = sensor; } + void set_error_code_sensor(sensor::Sensor *sensor) + { + error_code = sensor; + } + void add_custom_sensor(int message_number, sensor::Sensor *sensor) { Samsung_AC_Sensor cust_sensor; @@ -198,7 +204,7 @@ namespace esphome publish_request(request); }; } - + void set_water_heater_mode_select(Samsung_AC_Water_Heater_Mode_Select *select) { waterheatermode = select; @@ -311,7 +317,7 @@ namespace esphome if (climate != nullptr) calc_and_publish_mode(); } - + void update_water_heater_mode(WaterHeaterMode value) { _cur_water_heater_mode = value; @@ -415,6 +421,12 @@ namespace esphome indoor_eva_out_temperature->publish_state(value); } + void update_error_code(int value) + { + if (error_code != nullptr) + error_code->publish_state(value); + } + void update_custom_sensor(uint16_t message_number, float value) { for (auto &sensor : custom_sensors) From 9c719e05804aa48f8dd08c1378a22468a57347c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:38:41 +0300 Subject: [PATCH 12/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 026918de..f098394f 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -929,14 +929,6 @@ namespace esphome LOG_MESSAGE(ENUM_out_load_4way, message.value, source, dest); break; - case 0x8235: // VAR_out_error_code - { - int error_code = message.value; - LOG_MESSAGE(VAR_out_error_code, error_code, source, dest); - target->publish_error_code(source, error_code); - break; - } - case 0x8261: // VAR_OUT_SENSOR_PIPEIN3 unit = 'Celsius' { double temp = (double)message.value / (double)10; From 3aecb1ef1b727b824699647d5fc9ab9d9c6307a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 15:47:00 +0300 Subject: [PATCH 13/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/__init__.py | 4 +--- components/samsung_ac/protocol_nasa.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index bb8bde6c..fde12c11 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -16,7 +16,6 @@ CORE, Lambda ) -from .error_codes import ERROR_CODES CODEOWNERS = ["matthias882", "lanwin"] DEPENDENCIES = ["uart"] @@ -208,6 +207,7 @@ def error_code_sensor_schema(message: int): device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, ), + cv.Optional(CONF_DEVICE_ERROR_CODE): error_code_sensor_schema(0x8235), cv.Optional(CONF_DEVICE_TARGET_TEMPERATURE): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_WATER_OUTLET_TARGET): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_WATER_TARGET_TEMPERATURE): NUMBER_SCHEMA, @@ -222,7 +222,6 @@ def error_code_sensor_schema(message: int): # keep CUSTOM_SENSOR_KEYS in sync with these cv.Optional(CONF_DEVICE_WATER_TEMPERATURE): temperature_sensor_schema(0x4237), cv.Optional(CONF_DEVICE_ROOM_HUMIDITY): humidity_sensor_schema(0x4038), - cv.Optional(CONF_DEVICE_ERROR_CODE): error_code_sensor_schema(0x8235), } ) ) @@ -230,7 +229,6 @@ def error_code_sensor_schema(message: int): CUSTOM_SENSOR_KEYS = [ CONF_DEVICE_WATER_TEMPERATURE, CONF_DEVICE_ROOM_HUMIDITY, - CONF_DEVICE_ERROR_CODE, ] CONF_DEVICES = "devices" diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index f098394f..b3b992ef 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -715,7 +715,7 @@ namespace esphome case MessageNumber::VAR_out_error_code: { LOG_MESSAGE(VAR_out_error_code, (int)message.value, source, dest); - target->set_error_code(source, message.value); + target->set_error_code(source, (int)message.value); break; } From f8edfe89d4b4f0921ba2bb221ce40f8ce231ff3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 16:12:10 +0300 Subject: [PATCH 14/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index b3b992ef..f6782608 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -714,8 +714,9 @@ namespace esphome } case MessageNumber::VAR_out_error_code: { - LOG_MESSAGE(VAR_out_error_code, (int)message.value, source, dest); - target->set_error_code(source, (int)message.value); + int code = ((int16_t)message.value); + LOG_MESSAGE(VAR_out_error_code, code, source, dest); + target->set_error_code(source, code); break; } From 1026ed0e2766837777e63f028881ca1a7ec379c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 16:36:26 +0300 Subject: [PATCH 15/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index f6782608..65379906 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -714,7 +714,7 @@ namespace esphome } case MessageNumber::VAR_out_error_code: { - int code = ((int16_t)message.value); + int code = ((int32_t)message.value); LOG_MESSAGE(VAR_out_error_code, code, source, dest); target->set_error_code(source, code); break; From 045b9c41409c1f7e0c7b1426b77e885745ac0c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 16:51:38 +0300 Subject: [PATCH 16/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 65379906..cdd9b74e 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -714,9 +714,9 @@ namespace esphome } case MessageNumber::VAR_out_error_code: { - int code = ((int32_t)message.value); + int code = static_cast(message.value); LOG_MESSAGE(VAR_out_error_code, code, source, dest); - target->set_error_code(source, code); + //target->set_error_code(source, code); break; } From 77c7e865b7491114cf936fa2e9559f897e787327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 17:00:17 +0300 Subject: [PATCH 17/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index cdd9b74e..eb58512e 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -715,8 +715,11 @@ namespace esphome case MessageNumber::VAR_out_error_code: { int code = static_cast(message.value); - LOG_MESSAGE(VAR_out_error_code, code, source, dest); - //target->set_error_code(source, code); + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %f", source.c_str(), dest.c_str(), code); + } + target->set_error_code(source, code); break; } From 5893c5064b8df12e3233caa9edb66d17b3ca49ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 17:05:05 +0300 Subject: [PATCH 18/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index eb58512e..deca4f66 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -717,7 +717,7 @@ namespace esphome int code = static_cast(message.value); if (debug_log_messages) { - ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %f", source.c_str(), dest.c_str(), code); + ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %f", source.c_str(), dest.c_str(), message.to_string().c_str()); } target->set_error_code(source, code); break; From b078b9469f83c2e9a377d54b4732012b4fce1d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 17:30:11 +0300 Subject: [PATCH 19/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index deca4f66..08ac3f5b 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -717,7 +717,7 @@ namespace esphome int code = static_cast(message.value); if (debug_log_messages) { - ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %f", source.c_str(), dest.c_str(), message.to_string().c_str()); + ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %d", source.c_str(), dest.c_str(), message.to_string().c_str()); } target->set_error_code(source, code); break; From d33c55ba69238b528f1184ffe18f9c1062bf75e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 17:37:19 +0300 Subject: [PATCH 20/26] Added error code handling and message integration in protocol_nasa components --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 08ac3f5b..583626bd 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -717,7 +717,7 @@ namespace esphome int code = static_cast(message.value); if (debug_log_messages) { - ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %d", source.c_str(), dest.c_str(), message.to_string().c_str()); + ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %d", source.c_str(), dest.c_str(), code); } target->set_error_code(source, code); break; From c700762c5a67c6a4c1dafdeb0b76382f8ff0d194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 21:26:00 +0300 Subject: [PATCH 21/26] Added error_code sensor to example.yaml with detailed description. --- example.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example.yaml b/example.yaml index 2d44a418..4eb4ddc5 100644 --- a/example.yaml +++ b/example.yaml @@ -124,6 +124,13 @@ samsung_ac: # Only supported on NASA devices room_humidity: name: "Kitchen humidity" + + # This sensor captures and monitors specific error codes returned by the HVAC system. + # When an error occurs, the sensor detects the error code and updates its value accordingly. + # Additionally, by using the blueprint available at https://github.com/omerfaruk-aran/esphome_samsung_ac_blueprint, + # you can automatically send detailed error messages to your mobile devices based on the captured error codes. + error_code: + name: "Error Code" # Only supported on NASA based heatpumps water_temperature: From 872bd71c6644765f1736db0dc5b2f8be4037eb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Sun, 25 Aug 2024 23:24:12 +0300 Subject: [PATCH 22/26] Deleted error_codes.py --- components/samsung_ac/error_codes.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 components/samsung_ac/error_codes.py diff --git a/components/samsung_ac/error_codes.py b/components/samsung_ac/error_codes.py deleted file mode 100644 index 38a13e68..00000000 --- a/components/samsung_ac/error_codes.py +++ /dev/null @@ -1,4 +0,0 @@ -ERROR_CODES = { - 201: "Communication error between indoor and outdoor units (installation number setting error,repeated indoor unit address, indoor unit communication cable error)", - # ... -} \ No newline at end of file From 01e2c1e9a757d17a1d559ed6232755d12e57ac8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 26 Aug 2024 10:19:20 +0300 Subject: [PATCH 23/26] Fix build on ESP-IDF: Change logging message type interpolation #166 --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 583626bd..f3e6d1d8 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -24,7 +24,7 @@ namespace esphome #define LOG_MESSAGE(message_name, temp, source, dest) \ if (debug_log_messages) \ { \ - ESP_LOGW(TAG, "s:%s d:%s " #message_name " %f", source.c_str(), dest.c_str(), temp); \ + ESP_LOGW(TAG, "s:%s d:%s " #message_name " %g", source.c_str(), dest.c_str(), temp); \ } uint16_t crc16(std::vector &data, int startIndex, int length) From 5cdf9860959825431666756e2089e92ac801a715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 26 Aug 2024 10:20:59 +0300 Subject: [PATCH 24/26] Fix build on ESP-IDF: Change logging message type interpolation #166 --- components/samsung_ac/protocol_nasa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index f3e6d1d8..25aa82de 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -24,7 +24,7 @@ namespace esphome #define LOG_MESSAGE(message_name, temp, source, dest) \ if (debug_log_messages) \ { \ - ESP_LOGW(TAG, "s:%s d:%s " #message_name " %g", source.c_str(), dest.c_str(), temp); \ + ESP_LOGW(TAG, "s:%s d:%s " #message_name " %g", source.c_str(), dest.c_str(), static_cast(temp)); \ } uint16_t crc16(std::vector &data, int startIndex, int length) From c616fcd2cd28028904e8b8f14dec4b11bac4245a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 26 Aug 2024 18:34:03 +0300 Subject: [PATCH 25/26] Fix --- components/samsung_ac/protocol_nasa.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 25aa82de..be6c9b3e 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -21,9 +21,9 @@ namespace esphome return value - (int)65535 /*uint16 max*/ - 1.0; } -#define LOG_MESSAGE(message_name, temp, source, dest) \ - if (debug_log_messages) \ - { \ +#define LOG_MESSAGE(message_name, temp, source, dest) \ + if (debug_log_messages) \ + { \ ESP_LOGW(TAG, "s:%s d:%s " #message_name " %g", source.c_str(), dest.c_str(), static_cast(temp)); \ } From d35cb575201e10a325e4a179011ead3071b73e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 26 Aug 2024 18:37:10 +0300 Subject: [PATCH 26/26] Fix --- components/samsung_ac/protocol_nasa.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index be6c9b3e..25aa82de 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -21,9 +21,9 @@ namespace esphome return value - (int)65535 /*uint16 max*/ - 1.0; } -#define LOG_MESSAGE(message_name, temp, source, dest) \ - if (debug_log_messages) \ - { \ +#define LOG_MESSAGE(message_name, temp, source, dest) \ + if (debug_log_messages) \ + { \ ESP_LOGW(TAG, "s:%s d:%s " #message_name " %g", source.c_str(), dest.c_str(), static_cast(temp)); \ }