From be6fc7ec099b5d5312f5045ed32404253f867c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 12 Aug 2024 14:07:37 +0300 Subject: [PATCH 01/21] Test version: process_messageset optimized --- components/samsung_ac/protocol_nasa.cpp | 297 ++++++++---------------- 1 file changed, 97 insertions(+), 200 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 06a12cf5..da2cdfbe 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -502,208 +502,105 @@ namespace esphome } } - void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) - { - if (debug_mqtt_connected()) - { - if (message.type == MessageSetType::Enum) - { - debug_mqtt_publish("samsung_ac/nasa/enum/" + long_to_hex((uint16_t)message.messageNumber), std::to_string(message.value)); - } - else if (message.type == MessageSetType::Variable) - { - debug_mqtt_publish("samsung_ac/nasa/var/" + long_to_hex((uint16_t)message.messageNumber), std::to_string(message.value)); - } - else if (message.type == MessageSetType::LongVariable) - { - debug_mqtt_publish("samsung_ac/nasa/var_long/" + long_to_hex((uint16_t)message.messageNumber), std::to_string(message.value)); - } - } - - if (custom && custom.value().find((uint16_t)message.messageNumber) != custom.value().end()) - { - target->set_custom_sensor(source, (uint16_t)message.messageNumber, (float)message.value); - } - - switch (message.messageNumber) - { - case MessageNumber::VAR_in_temp_room_f: // unit = 'Celsius' from XML - { - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp); - target->set_room_temperature(source, temp); - return; - } - case MessageNumber::VAR_in_temp_target_f: // unit = 'Celsius' from XML - { - double temp = (double)message.value / (double)10; - // if (value == 1) value = 'waterOutSetTemp'; //action in xml - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp); - target->set_target_temperature(source, temp); - return; - } - case MessageNumber::VAR_in_temp_water_outlet_target_f: // unit = 'Celsius' from XML - { - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp); - target->set_water_outlet_target(source, temp); - return; - } - case MessageNumber::VAR_in_temp_water_heater_target_f: // unit = 'Celsius' from XML - { - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); - target->set_target_water_temperature(source, temp); - return; - } - case MessageNumber::ENUM_in_state_humidity_percent: - { - // XML Enum no value but in Code it adds unit - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); - return; - } - case MessageNumber::ENUM_in_operation_power: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); - target->set_power(source, message.value != 0); - return; - } - case MessageNumber::ENUM_in_water_heater_power: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); - target->set_water_heater_power(source, message.value != 0); - return; - } - case MessageNumber::ENUM_in_operation_mode: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); - target->set_mode(source, operation_mode_to_mode(message.value)); - return; - } - case MessageNumber::ENUM_in_fan_mode: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); - FanMode mode = FanMode::Unknown; - if (message.value == 0) - mode = FanMode::Auto; - else if (message.value == 1) - mode = FanMode::Low; - else if (message.value == 2) - mode = FanMode::Mid; - else if (message.value == 3) - mode = FanMode::High; - else if (message.value == 4) - mode = FanMode::Turbo; - target->set_fanmode(source, mode); - return; - } - case MessageNumber::ENUM_in_fan_mode_real: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); - return; - } - case MessageNumber::ENUM_in_alt_mode: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); - target->set_altmode(source, message.value); - return; - } - case MessageNumber::ENUM_in_louver_hl_swing: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); - target->set_swing_vertical(source, message.value == 1); - return; - } - case MessageNumber::ENUM_in_louver_lr_swing: - { - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); - target->set_swing_horizontal(source, message.value == 1); - return; - } - case MessageNumber::VAR_in_temp_water_tank_f: - { - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); - return; - } - case MessageNumber::VAR_out_sensor_airout: - { - double temp = (double)((int16_t)message.value) / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); - target->set_outdoor_temperature(source, temp); - return; - } - +void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) { + if (debug_mqtt_connected()) { + std::string topic_prefix = "samsung_ac/nasa/"; + std::string topic_suffix = long_to_hex((uint16_t)message.messageNumber); + std::string payload = std::to_string(message.value); + + switch (message.type) { + case MessageSetType::Enum: + debug_mqtt_publish(topic_prefix + "enum/" + topic_suffix, payload); + break; + case MessageSetType::Variable: + debug_mqtt_publish(topic_prefix + "var/" + topic_suffix, payload); + break; + case MessageSetType::LongVariable: + debug_mqtt_publish(topic_prefix + "var_long/" + topic_suffix, payload); + break; default: - { - if ((uint16_t)message.messageNumber == 0x4260) - { - // VAR_IN_FSV_3021 - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_FSV_3021 %f", source.c_str(), dest.c_str(), temp); - return; - } - if ((uint16_t)message.messageNumber == 0x4261) - { - // VAR_IN_FSV_3022 - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_FSV_3022 %f", source.c_str(), dest.c_str(), temp); - return; - } - if ((uint16_t)message.messageNumber == 0x4262) - { - // VAR_IN_FSV_3023 - double temp = (double)message.value / (double)10; - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_FSV_3023 %f", source.c_str(), dest.c_str(), temp); - return; - } - - if ((uint16_t)message.messageNumber == 0x8414) - { - // LVAR_OUT_CONTROL_WATTMETER_ALL_UNIT_ACCUM - double kwh = (double)message.value / (double)1000; - ESP_LOGW(TAG, "s:%s d:%s LVAR_OUT_CONTROL_WATTMETER_ALL_UNIT_ACCUM %fkwh", source.c_str(), dest.c_str(), kwh); - return; - } - if ((uint16_t)message.messageNumber == 0x8413) - { - // LVAR_OUT_CONTROL_WATTMETER_1W_1MIN_SUM - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s LVAR_OUT_CONTROL_WATTMETER_1W_1MIN_SUM %f", source.c_str(), dest.c_str(), value); - return; - } - if ((uint16_t)message.messageNumber == 0x8411) - { - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s NASA_OUTDOOR_CONTROL_WATTMETER_1UNIT %f", source.c_str(), dest.c_str(), value); - return; - } - if ((uint16_t)message.messageNumber == 0x8427) - { - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s total produced energy %f", source.c_str(), dest.c_str(), value); - return; - } - if ((uint16_t)message.messageNumber == 0x8426) - { - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s actual produced energy %f", source.c_str(), dest.c_str(), value); - return; - } - if ((uint16_t)message.messageNumber == 0x8415) - { - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s NASA_OUTDOOR_CONTROL_WATTMETER_TOTAL_SUM %f", source.c_str(), dest.c_str(), value); - return; - } - if ((uint16_t)message.messageNumber == 0x8416) - { - double value = (double)message.value; - ESP_LOGW(TAG, "s:%s d:%s NASA_OUTDOOR_CONTROL_WATTMETER_TOTAL_SUM_ACCUM %f", source.c_str(), dest.c_str(), value); - return; - } - } - } + break; } + } + + if (custom && custom.value().find((uint16_t)message.messageNumber) != custom.value().end()) { + target->set_custom_sensor(source, (uint16_t)message.messageNumber, (float)message.value); + } + + switch (message.messageNumber) { + case MessageNumber::VAR_in_temp_room_f: { + double temp = message.value / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp); + target->set_room_temperature(source, temp); + break; + } + case MessageNumber::VAR_in_temp_target_f: { + double temp = message.value / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp); + target->set_target_temperature(source, temp); + break; + } + case MessageNumber::VAR_in_temp_water_outlet_target_f: { + double temp = message.value / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp); + target->set_water_outlet_target(source, temp); + break; + } + case MessageNumber::VAR_in_temp_water_heater_target_f: { + double temp = message.value / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); + target->set_target_water_temperature(source, temp); + break; + } + case MessageNumber::ENUM_in_state_humidity_percent: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); + break; + case MessageNumber::ENUM_in_operation_power: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + target->set_power(source, message.value != 0); + break; + case MessageNumber::ENUM_in_water_heater_power: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + target->set_water_heater_power(source, message.value != 0); + break; + case MessageNumber::ENUM_in_operation_mode: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); + target->set_mode(source, operation_mode_to_mode(message.value)); + break; + case MessageNumber::ENUM_in_fan_mode: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); + target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); + break; + case MessageNumber::ENUM_in_fan_mode_real: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); + break; + case MessageNumber::ENUM_in_alt_mode: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); + target->set_altmode(source, message.value); + break; + case MessageNumber::ENUM_in_louver_hl_swing: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); + target->set_swing_vertical(source, message.value == 1); + break; + case MessageNumber::ENUM_in_louver_lr_swing: + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); + target->set_swing_horizontal(source, message.value == 1); + break; + case MessageNumber::VAR_in_temp_water_tank_f: + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); + break; + case MessageNumber::VAR_out_sensor_airout: { + double temp = ((int16_t)message.value) / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); + target->set_outdoor_temperature(source, temp); + break; + } + default: + ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); + break; + } +} + DecodeResult try_decode_nasa_packet(std::vector data) { From cba5cdb85f972891f85c827843767b77fe7dd775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 12 Aug 2024 15:03:15 +0300 Subject: [PATCH 02/21] Test version: process_messageset optimized --- components/samsung_ac/protocol_nasa.cpp | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index da2cdfbe..3e2b0980 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -502,7 +502,7 @@ namespace esphome } } -void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) { +void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target, bool log_undefined_messages) { if (debug_mqtt_connected()) { std::string topic_prefix = "samsung_ac/nasa/"; std::string topic_suffix = long_to_hex((uint16_t)message.messageNumber); @@ -548,7 +548,7 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag } case MessageNumber::VAR_in_temp_water_heater_target_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c.str(), temp); target->set_target_water_temperature(source, temp); break; } @@ -556,52 +556,55 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); break; case MessageNumber::ENUM_in_operation_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c.str(), dest.c.str(), message.value == 0 ? "off" : "on"); target->set_power(source, message.value != 0); break; case MessageNumber::ENUM_in_water_heater_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c.str(), dest.c.str(), message.value == 0 ? "off" : "on"); target->set_water_heater_power(source, message.value != 0); break; case MessageNumber::ENUM_in_operation_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c.str(), dest.c.str(), message.value); target->set_mode(source, operation_mode_to_mode(message.value)); break; case MessageNumber::ENUM_in_fan_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c.str(), dest.c.str(), message.value); target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); break; case MessageNumber::ENUM_in_fan_mode_real: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c.str(), dest.c.str(), message.value); break; case MessageNumber::ENUM_in_alt_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c.str(), dest.c.str(), message.value); target->set_altmode(source, message.value); break; case MessageNumber::ENUM_in_louver_hl_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c.str(), dest.c.str(), message.value); target->set_swing_vertical(source, message.value == 1); break; case MessageNumber::ENUM_in_louver_lr_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c.str(), dest.c.str(), message.value); target->set_swing_horizontal(source, message.value == 1); break; case MessageNumber::VAR_in_temp_water_tank_f: - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c.str(), dest.c.str(), message.value); break; case MessageNumber::VAR_out_sensor_airout: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c.str(), dest.c.str(), message.value); target->set_outdoor_temperature(source, temp); break; } default: - ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); + if (log_undefined_messages) { + ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c.str(), dest.c.str(), message.to_string().c.str()); + } break; } } + DecodeResult try_decode_nasa_packet(std::vector data) { return packet_.decode(data); From 2e57d77263da3694caa2f098009e38de63c19dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 12 Aug 2024 15:09:28 +0300 Subject: [PATCH 03/21] Test version: log_undefined_messages parameter add. --- components/samsung_ac/samsung_ac.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 0a5bd303..f36a2769 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -52,6 +52,11 @@ namespace esphome non_nasa_keepalive = value; } + void log_undefined_messages(bool value) + { + log_undefined_messages = value; + } + void register_device(Samsung_AC_Device *device); void /*MessageTarget::*/ register_address(const std::string address) override From 4dc6a036425cf896fa675e1d51eea109cf2b3d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 12 Aug 2024 15:19:50 +0300 Subject: [PATCH 04/21] Test version: log_undefined_messages parameter add. --- components/samsung_ac/protocol_nasa.cpp | 2 +- components/samsung_ac/samsung_ac.cpp | 1 + components/samsung_ac/samsung_ac.h | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 3e2b0980..8defcf75 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -670,7 +670,7 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag optional> custom = target->get_custom_sensors(source); for (auto &message : packet_.messages) { - process_messageset(source, dest, message, custom, target); + process_messageset(source, dest, message, custom, target,this->log_undefined_messages_); } } diff --git a/components/samsung_ac/samsung_ac.cpp b/components/samsung_ac/samsung_ac.cpp index d445db81..b35cc07f 100644 --- a/components/samsung_ac/samsung_ac.cpp +++ b/components/samsung_ac/samsung_ac.cpp @@ -11,6 +11,7 @@ namespace esphome void Samsung_AC::setup() { ESP_LOGW(TAG, "setup"); + this->log_undefined_messages_ = this->get_or_create("log_undefined_messages", false); } void Samsung_AC::update() diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index f36a2769..6b9868d3 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -52,10 +52,10 @@ namespace esphome non_nasa_keepalive = value; } - void log_undefined_messages(bool value) - { - log_undefined_messages = value; - } + void set_log_undefined_messages(bool value) + { + log_undefined_messages_ = value; + } void register_device(Samsung_AC_Device *device); @@ -170,6 +170,7 @@ namespace esphome } protected: + bool log_undefined_messages_{false}; Samsung_AC_Device *find_device(const std::string address) { auto it = devices_.find(address); From 2d2b30de7f4a46316865bd1b5b1071d7754f8a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Mon, 12 Aug 2024 15:45:48 +0300 Subject: [PATCH 05/21] Test version: log_undefined_messages parameter add. --- components/samsung_ac/protocol.cpp | 1 + components/samsung_ac/protocol.h | 1 + components/samsung_ac/protocol_nasa.cpp | 35 +++++++++++++------------ components/samsung_ac/samsung_ac.cpp | 1 - components/samsung_ac/samsung_ac.h | 11 +++----- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/components/samsung_ac/protocol.cpp b/components/samsung_ac/protocol.cpp index dbd67ba8..1e2be6c8 100644 --- a/components/samsung_ac/protocol.cpp +++ b/components/samsung_ac/protocol.cpp @@ -11,6 +11,7 @@ namespace esphome bool debug_log_packets = false; bool debug_log_raw_bytes = false; bool non_nasa_keepalive = false; + bool log_undefined_messages = false; ProtocolProcessing protocol_processing = ProtocolProcessing::Auto; // This functions is designed to run after a new value was added diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 0ed552c6..db54377f 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -11,6 +11,7 @@ namespace esphome extern bool debug_log_packets; extern bool debug_log_raw_bytes; extern bool non_nasa_keepalive; + extern bool log_undefined_messages ; enum class DecodeResult { diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 8defcf75..bea7c104 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -502,7 +502,7 @@ namespace esphome } } -void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target, bool log_undefined_messages) { +void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) { if (debug_mqtt_connected()) { std::string topic_prefix = "samsung_ac/nasa/"; std::string topic_suffix = long_to_hex((uint16_t)message.messageNumber); @@ -548,7 +548,7 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag } case MessageNumber::VAR_in_temp_water_heater_target_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c.str(), temp); + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); target->set_target_water_temperature(source, temp); break; } @@ -556,55 +556,56 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); break; case MessageNumber::ENUM_in_operation_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c.str(), dest.c.str(), message.value == 0 ? "off" : "on"); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); target->set_power(source, message.value != 0); break; case MessageNumber::ENUM_in_water_heater_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c.str(), dest.c.str(), message.value == 0 ? "off" : "on"); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); target->set_water_heater_power(source, message.value != 0); break; case MessageNumber::ENUM_in_operation_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); target->set_mode(source, operation_mode_to_mode(message.value)); break; case MessageNumber::ENUM_in_fan_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); break; case MessageNumber::ENUM_in_fan_mode_real: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); break; case MessageNumber::ENUM_in_alt_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); target->set_altmode(source, message.value); break; case MessageNumber::ENUM_in_louver_hl_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); target->set_swing_vertical(source, message.value == 1); break; case MessageNumber::ENUM_in_louver_lr_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); target->set_swing_horizontal(source, message.value == 1); break; case MessageNumber::VAR_in_temp_water_tank_f: - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); break; case MessageNumber::VAR_out_sensor_airout: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c.str(), dest.c.str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); target->set_outdoor_temperature(source, temp); break; } default: - if (log_undefined_messages) { - ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c.str(), dest.c.str(), message.to_string().c.str()); - } + if (log_undefined_messages) + { + ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); + } + break; } } - DecodeResult try_decode_nasa_packet(std::vector data) { return packet_.decode(data); @@ -670,7 +671,7 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag optional> custom = target->get_custom_sensors(source); for (auto &message : packet_.messages) { - process_messageset(source, dest, message, custom, target,this->log_undefined_messages_); + process_messageset(source, dest, message, custom, target); } } diff --git a/components/samsung_ac/samsung_ac.cpp b/components/samsung_ac/samsung_ac.cpp index b35cc07f..d445db81 100644 --- a/components/samsung_ac/samsung_ac.cpp +++ b/components/samsung_ac/samsung_ac.cpp @@ -11,7 +11,6 @@ namespace esphome void Samsung_AC::setup() { ESP_LOGW(TAG, "setup"); - this->log_undefined_messages_ = this->get_or_create("log_undefined_messages", false); } void Samsung_AC::update() diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 6b9868d3..220dc7c6 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -51,12 +51,10 @@ namespace esphome { non_nasa_keepalive = value; } - - void set_log_undefined_messages(bool value) - { - log_undefined_messages_ = value; - } - +void set_log_undefined_messages (bool value) + { + log_undefined_messages = value; + } void register_device(Samsung_AC_Device *device); void /*MessageTarget::*/ register_address(const std::string address) override @@ -170,7 +168,6 @@ namespace esphome } protected: - bool log_undefined_messages_{false}; Samsung_AC_Device *find_device(const std::string address) { auto it = devices_.find(address); From d27421385aa807d6dd0822a3b26128707b44493b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 17:34:00 +0300 Subject: [PATCH 06/21] =?UTF-8?q?De=C4=9Fi=C5=9Fiklikler=20yap=C4=B1ld?= =?UTF-8?q?=C4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/samsung_ac/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index db54377f..647b0942 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -11,7 +11,7 @@ namespace esphome extern bool debug_log_packets; extern bool debug_log_raw_bytes; extern bool non_nasa_keepalive; - extern bool log_undefined_messages ; + extern bool log_undefined_messages; enum class DecodeResult { From 501838392f89777b6e74f6aee882d5346a863f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 17:52:05 +0300 Subject: [PATCH 07/21] =?UTF-8?q?De=C4=9Fi=C5=9Fiklikler=20yap=C4=B1ld?= =?UTF-8?q?=C4=B1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/samsung_ac/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 8894100f..7360d989 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -212,6 +212,8 @@ def humidity_sensor_schema(message: int): CONF_NON_NASA_KEEPALIVE = "non_nasa_keepalive" +CONF_LOG_UNDEFINED_MESSAGES = "log_undefined_messages" + CONFIG_SCHEMA = ( cv.Schema( { @@ -224,6 +226,7 @@ def humidity_sensor_schema(message: int): cv.Optional(CONF_DEBUG_LOG_MESSAGES, default=False): cv.boolean, cv.Optional(CONF_DEBUG_LOG_MESSAGES_RAW, default=False): cv.boolean, cv.Optional(CONF_NON_NASA_KEEPALIVE, default=False): cv.boolean, + cv.Optional(CONF_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean, cv.Optional(CONF_CAPABILITIES): CAPABILITIES_SCHEMA, cv.Required(CONF_DEVICES): cv.ensure_list(DEVICE_SCHEMA), } @@ -387,6 +390,9 @@ async def to_code(config): if (CONF_NON_NASA_KEEPALIVE in config): cg.add(var.set_non_nasa_keepalive(config[CONF_NON_NASA_KEEPALIVE])) + + if (CONF_LOG_UNDEFINED_MESSAGES in config): + cg.add(var.set_log_undefined_messages(config[CONF_LOG_UNDEFINED_MESSAGES])) await cg.register_component(var, config) await uart.register_uart_device(var, config) From bc57a3b4ceca4eec3b2f7e9891a0f3443b1ab0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 18:20:15 +0300 Subject: [PATCH 08/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/__init__.py | 10 ++++++++++ components/samsung_ac/protocol.h | 2 ++ components/samsung_ac/protocol_nasa.cpp | 12 ++++++++++++ components/samsung_ac/protocol_nasa.h | 2 ++ components/samsung_ac/samsung_ac_device.h | 24 +++++++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 7360d989..bc3cdaff 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -316,6 +316,16 @@ async def to_code(config): conf = device[CONF_DEVICE_OUTDOOR_TEMPERATURE] sens = await sensor.new_sensor(conf) cg.add(var_dev.set_outdoor_temperature_sensor(sens)) + + if CONF_DEVICE_INDOOR_EVA_IN_TEMPERATURE in device: + conf = device[CONF_DEVICE_INDOOR_EVA_IN_TEMPERATURE] + sens = await sensor.new_sensor(conf) + cg.add(var_dev.set_indoor_eva_in_temperature_sensor(sens)) + + if CONF_DEVICE_INDOOR_EVA_OUT_TEMPERATURE in device: + 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_WATER_TARGET_TEMPERATURE in device: conf = device[CONF_DEVICE_WATER_TARGET_TEMPERATURE] diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 647b0942..aac201ab 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -73,6 +73,8 @@ namespace esphome virtual void set_target_temperature(const std::string address, float value) = 0; virtual void set_water_outlet_target(const std::string address, float value) = 0; virtual void set_outdoor_temperature(const std::string address, float value) = 0; + virtual void set_indoor_eva_in_temperature(const std::string address, float value) = 0; + virtual void set_indoor_eva_out_temperature(const std::string address, float value) = 0; virtual void set_target_water_temperature(const std::string address, float value) = 0; virtual void set_mode(const std::string address, Mode mode) = 0; virtual void set_fanmode(const std::string address, FanMode fanmode) = 0; diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index bea7c104..7c45e66e 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -595,6 +595,18 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag target->set_outdoor_temperature(source, temp); break; } + case MessageNumber::VAR_IN_TEMP_EVA_IN_F: { + double temp = ((int16_t)message.value) / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value); + target->set_indoor_eva_in_temperature(source, temp); + break; + } + case MessageNumber::VAR_OUT_TEMP_EVA_IN_F: { + double temp = ((int16_t)message.value) / 10.0; + ESP_LOGW(TAG, "s:%s d:%s VAR_OUT_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value); + target->set_indoor_eva_out_temperature(source, temp); + break; + } default: if (log_undefined_messages) { diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index edae3003..7f146a94 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -85,6 +85,8 @@ namespace esphome VAR_in_temp_water_tank_f = 0x4237, VAR_out_sensor_airout = 0x8204, VAR_in_temp_water_heater_target_f = 0x4235, + VAR_IN_TEMP_EVA_IN_F= 0x4205, + VAR_IN_TEMP_EVA_OUT_F= 0x4206, }; struct Address diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index bc202da5..66f99016 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -89,6 +89,8 @@ namespace esphome std::string address; sensor::Sensor *room_temperature{nullptr}; sensor::Sensor *outdoor_temperature{nullptr}; + sensor::Sensor *indoor_eva_in_temperature{nullptr}; + sensor::Sensor *indoor_eva_out_temperature{nullptr}; Samsung_AC_Number *target_temperature{nullptr}; Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; @@ -105,6 +107,16 @@ namespace esphome } void set_outdoor_temperature_sensor(sensor::Sensor *sensor) + { + indoor_eva_in_temperature = sensor; + } + + void set_indoor_eva_in_temperature_sensor(sensor::Sensor *sensor) + { + indoor_eva_out_temperature = sensor; + } + + void set_indoor_eva_out_temperature_sensor(sensor::Sensor *sensor) { outdoor_temperature = sensor; } @@ -333,6 +345,18 @@ namespace esphome outdoor_temperature->publish_state(value); } + void update_indoor_eva_in_temperature(float value) + { + if (indoor_eva_in_temperature != nullptr) + indoor_eva_in_temperature->publish_state(value); + } + + void update_indoor_eva_out_temperature(float value) + { + if (indoor_eva_out_temperature != nullptr) + indoor_eva_out_temperature->publish_state(value); + } + void update_custom_sensor(uint16_t message_number, float value) { for (auto &sensor : custom_sensors) From 3aa4c2082d3b4485968d7905e14f4a5cd1f85b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 18:23:25 +0300 Subject: [PATCH 09/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/samsung_ac.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 220dc7c6..58a68e20 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -83,6 +83,20 @@ void set_log_undefined_messages (bool value) dev->update_outdoor_temperature(value); } + void /*MessageTarget::*/ set_indoor_eva_in_temperature(const std::string address, float value) override + { + Samsung_AC_Device *dev = find_device(address); + if (dev != nullptr) + dev->update_indoor_eva_in_temperature(value); + } + + void /*MessageTarget::*/ set_indoor_eva_out_temperature(const std::string address, float value) override + { + Samsung_AC_Device *dev = find_device(address); + if (dev != nullptr) + dev->update_indoor_eva_out_temperature(value); + } + void /*MessageTarget::*/ set_target_temperature(const std::string address, float value) override { Samsung_AC_Device *dev = find_device(address); From 349ddeb4546545ff003db4caaaa34f2b801f4870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 18:31:20 +0300 Subject: [PATCH 10/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index bc3cdaff..73be07ce 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -55,6 +55,8 @@ CONF_DEVICE_TARGET_TEMPERATURE = "target_temperature" CONF_DEVICE_WATER_OUTLET_TARGET = "water_outlet_target" CONF_DEVICE_OUTDOOR_TEMPERATURE = "outdoor_temperature" +CONF_DEVICE_INDOOR_EVA_IN_TEMPERATURE = "indoor_eva_in_temperature" +CONF_DEVICE_INDOOR_EVA_OUT_TEMPERATURE = "indoor_eva_out_temperature" CONF_DEVICE_WATER_TEMPERATURE = "water_temperature" CONF_DEVICE_WATER_TARGET_TEMPERATURE = "water_target_temperature" CONF_DEVICE_POWER = "power" @@ -178,6 +180,18 @@ def humidity_sensor_schema(message: int): accuracy_decimals=1, device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, + ), + cv.Optional(CONF_DEVICE_INDOOR_EVA_IN_TEMPERATURE): sensor.sensor_schema( + unit_of_measurement=UNIT_CELSIUS, + accuracy_decimals=1, + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ), + cv.Optional(CONF_DEVICE_INDOOR_EVA_OUT_TEMPERATURE): sensor.sensor_schema( + unit_of_measurement=UNIT_CELSIUS, + accuracy_decimals=1, + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_DEVICE_TARGET_TEMPERATURE): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_WATER_OUTLET_TARGET): NUMBER_SCHEMA, From 8629eb301c476139fd2679f614bb98161820c1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 18:38:27 +0300 Subject: [PATCH 11/21] INDOOR EVA IN/OUT TEMP ADD. --- 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 7c45e66e..31d4ecb3 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -601,9 +601,9 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag target->set_indoor_eva_in_temperature(source, temp); break; } - case MessageNumber::VAR_OUT_TEMP_EVA_IN_F: { + case MessageNumber::VAR_IN_TEMP_EVA_OUT_F: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_OUT_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value); + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_OUT_F %li", source.c_str(), dest.c_str(), message.value); target->set_indoor_eva_out_temperature(source, temp); break; } From 6d81e39e6af828f9cbd23708baa0d54a857f8748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Tue, 13 Aug 2024 18:50:06 +0300 Subject: [PATCH 12/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/protocol_nasa.cpp | 13 +++++++++++-- components/samsung_ac/protocol_nasa.h | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 31d4ecb3..ce2172a5 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -1063,12 +1063,21 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag case 0x602: // STR_ad_option_install_2 case 0x600: // STR_ad_option_basic case 0x202: // VAR_ad_error_code1 + case 0x42d1: // VAR_IN_DUST_SENSOR_PM10_0_VALUE + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM10_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important + } case 0x42d2: // VAR_IN_DUST_SENSOR_PM2_5_VALUE + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM2_5_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important + } case 0x42d3: // VAR_IN_DUST_SENSOR_PM1_0_VALUE { - // ESP_LOGW(TAG, "s:%s d:%s Ignore %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); - return; // Ingore cause not important + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM1_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important } case 0x23: diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 7f146a94..231d3942 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -85,8 +85,8 @@ namespace esphome VAR_in_temp_water_tank_f = 0x4237, VAR_out_sensor_airout = 0x8204, VAR_in_temp_water_heater_target_f = 0x4235, - VAR_IN_TEMP_EVA_IN_F= 0x4205, - VAR_IN_TEMP_EVA_OUT_F= 0x4206, + VAR_IN_TEMP_EVA_IN_F = 0x4205, + VAR_IN_TEMP_EVA_OUT_F = 0x4206, }; struct Address From c3d14b95d629451f97e61e16e6ab7fdfb0ed7446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 00:13:57 +0300 Subject: [PATCH 13/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/samsung_ac_device.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index 66f99016..094ae654 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -108,17 +108,17 @@ namespace esphome void set_outdoor_temperature_sensor(sensor::Sensor *sensor) { - indoor_eva_in_temperature = sensor; + outdoor_temperature = sensor; } void set_indoor_eva_in_temperature_sensor(sensor::Sensor *sensor) { - indoor_eva_out_temperature = sensor; + indoor_eva_in_temperature = sensor; } void set_indoor_eva_out_temperature_sensor(sensor::Sensor *sensor) { - outdoor_temperature = sensor; + indoor_eva_out_temperature = sensor; } void add_custom_sensor(int message_number, sensor::Sensor *sensor) From e434eaf839e2a4954b6a79ebd2a9459ea518d4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 00:26:08 +0300 Subject: [PATCH 14/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/__init__.py | 6 ++++++ components/samsung_ac/protocol.cpp | 1 + components/samsung_ac/protocol.h | 1 + components/samsung_ac/samsung_ac.h | 4 ++++ test/esphome/core/log.h | 20 ++++++++++++-------- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 73be07ce..741a245d 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -228,6 +228,8 @@ def humidity_sensor_schema(message: int): CONF_LOG_UNDEFINED_MESSAGES = "log_undefined_messages" +CONF_LOG_MESSAGES = "log_messages" + CONFIG_SCHEMA = ( cv.Schema( { @@ -241,6 +243,7 @@ def humidity_sensor_schema(message: int): cv.Optional(CONF_DEBUG_LOG_MESSAGES_RAW, default=False): cv.boolean, cv.Optional(CONF_NON_NASA_KEEPALIVE, default=False): cv.boolean, cv.Optional(CONF_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean, + cv.Optional(CONF_LOG_MESSAGES, default=False): cv.boolean, cv.Optional(CONF_CAPABILITIES): CAPABILITIES_SCHEMA, cv.Required(CONF_DEVICES): cv.ensure_list(DEVICE_SCHEMA), } @@ -418,5 +421,8 @@ async def to_code(config): if (CONF_LOG_UNDEFINED_MESSAGES in config): cg.add(var.set_log_undefined_messages(config[CONF_LOG_UNDEFINED_MESSAGES])) + if (CONF_LOG_MESSAGES in config): + cg.add(var.set_log_messages(config[CONF_LOG_MESSAGES])) + await cg.register_component(var, config) await uart.register_uart_device(var, config) diff --git a/components/samsung_ac/protocol.cpp b/components/samsung_ac/protocol.cpp index 1e2be6c8..da58630f 100644 --- a/components/samsung_ac/protocol.cpp +++ b/components/samsung_ac/protocol.cpp @@ -12,6 +12,7 @@ namespace esphome bool debug_log_raw_bytes = false; bool non_nasa_keepalive = false; bool log_undefined_messages = false; + bool log_messages = false; ProtocolProcessing protocol_processing = ProtocolProcessing::Auto; // This functions is designed to run after a new value was added diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index aac201ab..029f2997 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -12,6 +12,7 @@ namespace esphome extern bool debug_log_raw_bytes; extern bool non_nasa_keepalive; extern bool log_undefined_messages; + extern bool log_messages; enum class DecodeResult { diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 58a68e20..357f40c6 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -54,6 +54,10 @@ namespace esphome void set_log_undefined_messages (bool value) { log_undefined_messages = value; + } + void set_log_messages (bool value) + { + log_messages = value; } void register_device(Samsung_AC_Device *device); diff --git a/test/esphome/core/log.h b/test/esphome/core/log.h index a4a04cee..4eaf3fca 100644 --- a/test/esphome/core/log.h +++ b/test/esphome/core/log.h @@ -22,14 +22,18 @@ namespace esphome printf((str.c_str()), ##__VA_ARGS__); \ } while (0); -#define ESP_LOGW(tag, format, ...) \ - do \ - { \ - std::string str = ""; \ - str += format; \ - str += "\n"; \ - printf((str.c_str()), ##__VA_ARGS__); \ - } while (0); +#define ESP_LOGW(tag, format, ...) \ + do \ + { \ + if (log_messages) \ + { \ + std::string str = ""; \ + str += format; \ + str += "\n"; \ + printf((str.c_str()), ##__VA_ARGS__); \ + } \ + } while (0) + #define ESP_LOGV(tag, format, ...) \ do \ From db435e5e6d781cee51152b7808a4c20a513a1d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 00:36:16 +0300 Subject: [PATCH 15/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/protocol_nasa.cpp | 36 ++++++++++++------------- test/esphome/core/log.h | 20 ++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index ce2172a5..6c94609a 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -530,87 +530,87 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag switch (message.messageNumber) { case MessageNumber::VAR_in_temp_room_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp); + if(log_messages){ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp);} target->set_room_temperature(source, temp); break; } case MessageNumber::VAR_in_temp_target_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp);} target->set_target_temperature(source, temp); break; } case MessageNumber::VAR_in_temp_water_outlet_target_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp);} target->set_water_outlet_target(source, temp); break; } case MessageNumber::VAR_in_temp_water_heater_target_f: { double temp = message.value / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp);} target->set_target_water_temperature(source, temp); break; } case MessageNumber::ENUM_in_state_humidity_percent: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value);} break; case MessageNumber::ENUM_in_operation_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} target->set_power(source, message.value != 0); break; case MessageNumber::ENUM_in_water_heater_power: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} target->set_water_heater_power(source, message.value != 0); break; case MessageNumber::ENUM_in_operation_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value);} target->set_mode(source, operation_mode_to_mode(message.value)); break; case MessageNumber::ENUM_in_fan_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value);} target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); break; case MessageNumber::ENUM_in_fan_mode_real: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value);} break; case MessageNumber::ENUM_in_alt_mode: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value);} target->set_altmode(source, message.value); break; case MessageNumber::ENUM_in_louver_hl_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value);} target->set_swing_vertical(source, message.value == 1); break; case MessageNumber::ENUM_in_louver_lr_swing: - ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value);} target->set_swing_horizontal(source, message.value == 1); break; case MessageNumber::VAR_in_temp_water_tank_f: - ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value);} break; case MessageNumber::VAR_out_sensor_airout: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value);} target->set_outdoor_temperature(source, temp); break; } case MessageNumber::VAR_IN_TEMP_EVA_IN_F: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value);} target->set_indoor_eva_in_temperature(source, temp); break; } case MessageNumber::VAR_IN_TEMP_EVA_OUT_F: { double temp = ((int16_t)message.value) / 10.0; - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_OUT_F %li", source.c_str(), dest.c_str(), message.value); + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_OUT_F %li", source.c_str(), dest.c_str(), message.value);} target->set_indoor_eva_out_temperature(source, temp); break; } default: if (log_undefined_messages) { - ESP_LOGW(TAG, "Tanımsız mesaj s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); + ESP_LOGW(TAG, "Undefined s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); } break; diff --git a/test/esphome/core/log.h b/test/esphome/core/log.h index 4eaf3fca..a4a04cee 100644 --- a/test/esphome/core/log.h +++ b/test/esphome/core/log.h @@ -22,18 +22,14 @@ namespace esphome printf((str.c_str()), ##__VA_ARGS__); \ } while (0); -#define ESP_LOGW(tag, format, ...) \ - do \ - { \ - if (log_messages) \ - { \ - std::string str = ""; \ - str += format; \ - str += "\n"; \ - printf((str.c_str()), ##__VA_ARGS__); \ - } \ - } while (0) - +#define ESP_LOGW(tag, format, ...) \ + do \ + { \ + std::string str = ""; \ + str += format; \ + str += "\n"; \ + printf((str.c_str()), ##__VA_ARGS__); \ + } while (0); #define ESP_LOGV(tag, format, ...) \ do \ From 751ba92e408534580088065ec2569208b4aa75c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 00:48:42 +0300 Subject: [PATCH 16/21] INDOOR EVA IN/OUT TEMP ADD. --- components/samsung_ac/protocol_nasa.cpp | 7 +++++++ components/samsung_ac/protocol_nasa.h | 1 + 2 files changed, 8 insertions(+) diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 6c94609a..f3e5c8b0 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -386,6 +386,13 @@ namespace esphome power.value = request.power.value() ? 1 : 0; packet.messages.push_back(power); } + + if (request.automatic_cleaning) + { + MessageSet automatic_cleaning(MessageNumber::ENUM_in_operation_automatic_cleaning); + automatic_cleaning.value = request.automatic_cleaning.value() ? 1 : 0; + packet.messages.push_back(automatic_cleaning); + } if (request.water_heater_power) { diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 231d3942..77abae60 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -71,6 +71,7 @@ namespace esphome { Undefiend = 0, ENUM_in_operation_power = 0x4000, + ENUM_in_operation_automatic_cleaning = 0x4111, ENUM_in_water_heater_power = 0x4065, ENUM_in_operation_mode = 0x4001, ENUM_in_fan_mode = 0x4006, // Did not exists in xml...only in Remocon.dll code From 8b21db23a0cc444df08bfad023378313c22c6bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 01:01:39 +0300 Subject: [PATCH 17/21] ADD Automatic Cleaning Mode. After the cooling process is completed, it dries all moisture in the interior hygienically. --- components/samsung_ac/__init__.py | 7 +++++++ components/samsung_ac/protocol.h | 2 ++ components/samsung_ac/protocol_nasa.cpp | 4 ++++ components/samsung_ac/samsung_ac.h | 6 ++++++ components/samsung_ac/samsung_ac_device.h | 22 ++++++++++++++++++++++ 5 files changed, 41 insertions(+) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 741a245d..094a06b0 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -60,6 +60,7 @@ CONF_DEVICE_WATER_TEMPERATURE = "water_temperature" CONF_DEVICE_WATER_TARGET_TEMPERATURE = "water_target_temperature" CONF_DEVICE_POWER = "power" +CONF_DEVICE_AUTOMATIC_CLEANING = "automatic_cleaning" CONF_DEVICE_WATER_HEATER_POWER = "water_heater_power" CONF_DEVICE_MODE = "mode" CONF_DEVICE_CLIMATE = "climate" @@ -197,6 +198,7 @@ def humidity_sensor_schema(message: int): cv.Optional(CONF_DEVICE_WATER_OUTLET_TARGET): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_WATER_TARGET_TEMPERATURE): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_POWER): switch.switch_schema(Samsung_AC_Switch), + cv.Optional(CONF_DEVICE_AUTOMATIC_CLEANING): switch.switch_schema(Samsung_AC_Switch), cv.Optional(CONF_DEVICE_WATER_HEATER_POWER): switch.switch_schema(Samsung_AC_Switch), cv.Optional(CONF_DEVICE_MODE): SELECT_MODE_SCHEMA, cv.Optional(CONF_DEVICE_CLIMATE): CLIMATE_SCHEMA, @@ -315,6 +317,11 @@ async def to_code(config): sens = await switch.new_switch(conf) cg.add(var_dev.set_power_switch(sens)) + if CONF_DEVICE_AUTOMATIC_CLEANING in device: + conf = device[CONF_DEVICE_AUTOMATIC_CLEANING] + sens = await switch.new_switch(conf) + cg.add(var_dev.set_automatic_cleaning_switch(sens)) + if CONF_DEVICE_WATER_HEATER_POWER in device: conf = device[CONF_DEVICE_WATER_HEATER_POWER] sens = await switch.new_switch(conf) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 029f2997..fbd2e25b 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -69,6 +69,7 @@ namespace esphome virtual void publish_data(std::vector &data) = 0; virtual void register_address(const std::string address) = 0; virtual void set_power(const std::string address, bool value) = 0; + virtual void set_automatic_cleaning(const std::string address, bool value) = 0; virtual void set_water_heater_power(const std::string address, bool value) = 0; virtual void set_room_temperature(const std::string address, float value) = 0; virtual void set_target_temperature(const std::string address, float value) = 0; @@ -90,6 +91,7 @@ namespace esphome { public: optional power; + optional automatic_cleaning; optional water_heater_power; optional mode; optional target_temp; diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index f3e5c8b0..c962a22e 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -566,6 +566,10 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} target->set_power(source, message.value != 0); break; + case MessageNumber::ENUM_in_operation_automatic_cleaning: + if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_automatic_cleaning %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} + target->set_automatic_cleaning(source, message.value != 0); + break; case MessageNumber::ENUM_in_water_heater_power: if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} target->set_water_heater_power(source, message.value != 0); diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 357f40c6..867659ba 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -128,6 +128,12 @@ void set_log_undefined_messages (bool value) if (dev != nullptr) dev->update_power(value); } + void /*MessageTarget::*/ set_automatic_cleaning(const std::string address, bool value) override + { + Samsung_AC_Device *dev = find_device(address); + if (dev != nullptr) + dev->update_automatic_cleaning(value); + } void /*MessageTarget::*/ set_water_heater_power(const std::string address, bool value) override { Samsung_AC_Device *dev = find_device(address); diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index 094ae654..c1a892a1 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -95,6 +95,7 @@ namespace esphome Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; Samsung_AC_Switch *power{nullptr}; + Samsung_AC_Switch *automatic_cleaning{nullptr}; Samsung_AC_Switch *water_heater_power{nullptr}; Samsung_AC_Mode_Select *mode{nullptr}; Samsung_AC_Climate *climate{nullptr}; @@ -147,6 +148,17 @@ namespace esphome publish_request(request); }; } + +void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) + { + automatic_cleaning = switch_; + automatic_cleaning->write_state_ = [this](bool value) + { + ProtocolRequest request; + request.automatic_cleaning = value; + publish_request(request); + }; + } void set_water_heater_power_switch(Samsung_AC_Switch *switch_) { @@ -233,6 +245,7 @@ namespace esphome } optional _cur_power; + optional _cur_automatic_cleaning; optional _cur_water_heater_power; optional _cur_mode; @@ -244,6 +257,15 @@ namespace esphome if (climate != nullptr) calc_and_publish_mode(); } + +void update_automatic_cleaning(bool value) + { + _cur_automatic_cleaning = value; + if (automatic_cleaning != nullptr) + automatic_cleaning->publish_state(value); + if (climate != nullptr) + calc_and_publish_mode(); + } void update_water_heater_power(bool value) { From c86eb0d47fcf32e999c8fe4f162623f43df2cfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 01:37:06 +0300 Subject: [PATCH 18/21] Initial commit with all changes --- esphome_samsung_ac | 1 + example.yaml | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 160000 esphome_samsung_ac diff --git a/esphome_samsung_ac b/esphome_samsung_ac new file mode 160000 index 00000000..f8e00b52 --- /dev/null +++ b/esphome_samsung_ac @@ -0,0 +1 @@ +Subproject commit f8e00b5246f27885a328bbf120798b22da5bdcba diff --git a/example.yaml b/example.yaml index 4acba9d8..9371fde1 100644 --- a/example.yaml +++ b/example.yaml @@ -47,7 +47,7 @@ uart: # Import custom component from GitHub external_components: - - source: github://lanwin/esphome_samsung_ac@stable # use @main if you want the latest development (possibly unstable?) + - source: github://omerfaruk-aran/esphome_samsung_ac@new_test # use @main if you want the latest development (possibly unstable?) components: [samsung_ac] # Configuration of AC component @@ -56,6 +56,12 @@ samsung_ac: # For NonNASA devices the following option can be enabled to prevent the device from sleeping when idle. This allows # values like internal and external temperature to continue to be tracked when the device isn't in use. non_nasa_keepalive: true + + #When enabled (set to true), this option will log the messages associated with undefined codes on the device. This is useful for debugging and identifying any unexpected or unknown codes that the device may receive during operation. + log_undefined_messages: false + + #When enabled (set to true), this option logs messages associated with defined codes on the device. This helps in monitoring the behavior of the device by recording the activity related to known, expected codes. + log_messages: false # Capabilities configure the features alle devices of your AC system have (all parts of this section are optional). # All capabilities are off by default, you need to enable only those your devices have. @@ -104,6 +110,8 @@ samsung_ac: name: "Kitchen power" mode: name: "Kitchen mode" + automatic_cleaning: + name: "Kitchen automatic clean" # If your AC sits near or inside the ceiling, the reported room temperature is often a little bit heigher then whats # measured below. This property can be used to correct that value. From 988eeba8b37fe27c3da4c2398eaed0f788f1f3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 01:48:27 +0300 Subject: [PATCH 19/21] Add automatic_cleaning mode for Samsung AC - Added the 'automatic_cleaning' feature to the Samsung AC integration. - This mode ensures hygienic drying of all moisture in the indoor unit after the cooling process is completed. --- example.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example.yaml b/example.yaml index 9371fde1..206b2386 100644 --- a/example.yaml +++ b/example.yaml @@ -110,6 +110,10 @@ samsung_ac: name: "Kitchen power" mode: name: "Kitchen mode" + + #Add automatic_cleaning mode for Samsung AC NASA + #- Added the "automatic_cleaning" feature to the Samsung AC integration. + #- This mode ensures hygienic drying of all moisture in the indoor unit after the cooling process is completed. automatic_cleaning: name: "Kitchen automatic clean" From 74fb700ebcb07de348093b2ccb3b47abe568fded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 13:33:37 +0300 Subject: [PATCH 20/21] Resolved conflicts, fixed indentation, renamed log parameters, implemented debug_log_messages functionality, and corrected repository source address in the YAML file. --- components/samsung_ac/__init__.py | 13 +- components/samsung_ac/conversions.cpp | 2 +- components/samsung_ac/conversions.h | 2 +- components/samsung_ac/protocol.cpp | 3 +- components/samsung_ac/protocol.h | 3 +- components/samsung_ac/protocol_nasa.cpp | 311 ++++++++++++-------- components/samsung_ac/protocol_non_nasa.cpp | 48 +-- components/samsung_ac/samsung_ac.h | 10 +- components/samsung_ac/samsung_ac_device.h | 20 +- example.yaml | 6 +- 10 files changed, 236 insertions(+), 182 deletions(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index 094a06b0..29f70a9c 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -228,9 +228,8 @@ def humidity_sensor_schema(message: int): CONF_NON_NASA_KEEPALIVE = "non_nasa_keepalive" -CONF_LOG_UNDEFINED_MESSAGES = "log_undefined_messages" +CONF_DEBUG_LOG_UNDEFINED_MESSAGES = "debug_log_undefined_messages" -CONF_LOG_MESSAGES = "log_messages" CONFIG_SCHEMA = ( cv.Schema( @@ -244,8 +243,7 @@ def humidity_sensor_schema(message: int): cv.Optional(CONF_DEBUG_LOG_MESSAGES, default=False): cv.boolean, cv.Optional(CONF_DEBUG_LOG_MESSAGES_RAW, default=False): cv.boolean, cv.Optional(CONF_NON_NASA_KEEPALIVE, default=False): cv.boolean, - cv.Optional(CONF_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean, - cv.Optional(CONF_LOG_MESSAGES, default=False): cv.boolean, + cv.Optional(CONF_DEBUG_LOG_UNDEFINED_MESSAGES, default=False): cv.boolean, cv.Optional(CONF_CAPABILITIES): CAPABILITIES_SCHEMA, cv.Required(CONF_DEVICES): cv.ensure_list(DEVICE_SCHEMA), } @@ -425,11 +423,8 @@ async def to_code(config): if (CONF_NON_NASA_KEEPALIVE in config): cg.add(var.set_non_nasa_keepalive(config[CONF_NON_NASA_KEEPALIVE])) - if (CONF_LOG_UNDEFINED_MESSAGES in config): - cg.add(var.set_log_undefined_messages(config[CONF_LOG_UNDEFINED_MESSAGES])) - - if (CONF_LOG_MESSAGES in config): - cg.add(var.set_log_messages(config[CONF_LOG_MESSAGES])) + if (CONF_DEBUG_LOG_UNDEFINED_MESSAGES in config): + cg.add(var.set_debug_log_undefined_messages(config[CONF_DEBUG_LOG_UNDEFINED_MESSAGES])) await cg.register_component(var, config) await uart.register_uart_device(var, config) diff --git a/components/samsung_ac/conversions.cpp b/components/samsung_ac/conversions.cpp index ba6ee24f..518cfe84 100644 --- a/components/samsung_ac/conversions.cpp +++ b/components/samsung_ac/conversions.cpp @@ -152,7 +152,7 @@ namespace esphome } } - optional altmodename_to_preset(const AltModeName& name) + optional altmodename_to_preset(const AltModeName &name) { if (str_equals_case_insensitive(name, "ECO")) return optional(climate::CLIMATE_PRESET_ECO); diff --git a/components/samsung_ac/conversions.h b/components/samsung_ac/conversions.h index 8bfb621f..050cc881 100644 --- a/components/samsung_ac/conversions.h +++ b/components/samsung_ac/conversions.h @@ -20,7 +20,7 @@ namespace esphome FanMode customfanmode_to_fanmode(const std::string &value); AltModeName preset_to_altmodename(climate::ClimatePreset preset); - optional altmodename_to_preset(const AltModeName& name); + optional altmodename_to_preset(const AltModeName &name); climate::ClimateSwingMode swingmode_to_climateswingmode(SwingMode swingMode); SwingMode climateswingmode_to_swingmode(climate::ClimateSwingMode swingMode); diff --git a/components/samsung_ac/protocol.cpp b/components/samsung_ac/protocol.cpp index da58630f..4e53f41d 100644 --- a/components/samsung_ac/protocol.cpp +++ b/components/samsung_ac/protocol.cpp @@ -11,8 +11,7 @@ namespace esphome bool debug_log_packets = false; bool debug_log_raw_bytes = false; bool non_nasa_keepalive = false; - bool log_undefined_messages = false; - bool log_messages = false; + bool debug_log_undefined_messages = false; ProtocolProcessing protocol_processing = ProtocolProcessing::Auto; // This functions is designed to run after a new value was added diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index fbd2e25b..5157c401 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -11,8 +11,7 @@ namespace esphome extern bool debug_log_packets; extern bool debug_log_raw_bytes; extern bool non_nasa_keepalive; - extern bool log_undefined_messages; - extern bool log_messages; + extern bool debug_log_undefined_messages; enum class DecodeResult { diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index c962a22e..5da5e953 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -386,8 +386,8 @@ namespace esphome power.value = request.power.value() ? 1 : 0; packet.messages.push_back(power); } - - if (request.automatic_cleaning) + + if (request.automatic_cleaning) { MessageSet automatic_cleaning(MessageNumber::ENUM_in_operation_automatic_cleaning); automatic_cleaning.value = request.automatic_cleaning.value() ? 1 : 0; @@ -407,14 +407,14 @@ namespace esphome targettemp.value = request.target_temp.value() * 10.0; packet.messages.push_back(targettemp); } - + if (request.water_outlet_target) { MessageSet wateroutlettarget(MessageNumber::VAR_in_temp_water_outlet_target_f); wateroutlettarget.value = request.water_outlet_target.value() * 10.0; packet.messages.push_back(wateroutlettarget); } - + if (request.target_water_temp) { MessageSet targetwatertemp(MessageNumber::VAR_in_temp_water_heater_target_f); @@ -509,125 +509,190 @@ namespace esphome } } -void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) { - if (debug_mqtt_connected()) { - std::string topic_prefix = "samsung_ac/nasa/"; - std::string topic_suffix = long_to_hex((uint16_t)message.messageNumber); - std::string payload = std::to_string(message.value); + void process_messageset(std::string source, std::string dest, MessageSet &message, optional> &custom, MessageTarget *target) + { + if (debug_mqtt_connected()) + { + std::string topic_prefix = "samsung_ac/nasa/"; + std::string topic_suffix = long_to_hex((uint16_t)message.messageNumber); + std::string payload = std::to_string(message.value); + + switch (message.type) + { + case MessageSetType::Enum: + debug_mqtt_publish(topic_prefix + "enum/" + topic_suffix, payload); + break; + case MessageSetType::Variable: + debug_mqtt_publish(topic_prefix + "var/" + topic_suffix, payload); + break; + case MessageSetType::LongVariable: + debug_mqtt_publish(topic_prefix + "var_long/" + topic_suffix, payload); + break; + default: + break; + } + } + + if (custom && custom.value().find((uint16_t)message.messageNumber) != custom.value().end()) + { + target->set_custom_sensor(source, (uint16_t)message.messageNumber, (float)message.value); + } - switch (message.type) { - case MessageSetType::Enum: - debug_mqtt_publish(topic_prefix + "enum/" + topic_suffix, payload); + switch (message.messageNumber) + { + case MessageNumber::VAR_in_temp_room_f: + { + double temp = message.value / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp); + } + target->set_room_temperature(source, temp); break; - case MessageSetType::Variable: - debug_mqtt_publish(topic_prefix + "var/" + topic_suffix, payload); + } + case MessageNumber::VAR_in_temp_target_f: + { + double temp = message.value / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp); + } + target->set_target_temperature(source, temp); break; - case MessageSetType::LongVariable: - debug_mqtt_publish(topic_prefix + "var_long/" + topic_suffix, payload); + } + case MessageNumber::VAR_in_temp_water_outlet_target_f: + { + double temp = message.value / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp); + } + target->set_water_outlet_target(source, temp); break; - default: + } + case MessageNumber::VAR_in_temp_water_heater_target_f: + { + double temp = message.value / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp); + } + target->set_target_water_temperature(source, temp); break; - } - } - - if (custom && custom.value().find((uint16_t)message.messageNumber) != custom.value().end()) { - target->set_custom_sensor(source, (uint16_t)message.messageNumber, (float)message.value); - } - - switch (message.messageNumber) { - case MessageNumber::VAR_in_temp_room_f: { - double temp = message.value / 10.0; - if(log_messages){ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_room_f %f", source.c_str(), dest.c_str(), temp);} - target->set_room_temperature(source, temp); - break; - } - case MessageNumber::VAR_in_temp_target_f: { - double temp = message.value / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_target_f %f", source.c_str(), dest.c_str(), temp);} - target->set_target_temperature(source, temp); - break; - } - case MessageNumber::VAR_in_temp_water_outlet_target_f: { - double temp = message.value / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_outlet_target_f %f", source.c_str(), dest.c_str(), temp);} - target->set_water_outlet_target(source, temp); - break; - } - case MessageNumber::VAR_in_temp_water_heater_target_f: { - double temp = message.value / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_heater_target_f %f", source.c_str(), dest.c_str(), temp);} - target->set_target_water_temperature(source, temp); - break; - } - case MessageNumber::ENUM_in_state_humidity_percent: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value);} - break; - case MessageNumber::ENUM_in_operation_power: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} - target->set_power(source, message.value != 0); - break; - case MessageNumber::ENUM_in_operation_automatic_cleaning: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_automatic_cleaning %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} - target->set_automatic_cleaning(source, message.value != 0); - break; - case MessageNumber::ENUM_in_water_heater_power: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on");} - target->set_water_heater_power(source, message.value != 0); - break; - case MessageNumber::ENUM_in_operation_mode: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value);} - target->set_mode(source, operation_mode_to_mode(message.value)); - break; - case MessageNumber::ENUM_in_fan_mode: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value);} - target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); - break; - case MessageNumber::ENUM_in_fan_mode_real: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value);} - break; - case MessageNumber::ENUM_in_alt_mode: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value);} - target->set_altmode(source, message.value); - break; - case MessageNumber::ENUM_in_louver_hl_swing: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value);} - target->set_swing_vertical(source, message.value == 1); - break; - case MessageNumber::ENUM_in_louver_lr_swing: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value);} - target->set_swing_horizontal(source, message.value == 1); - break; - case MessageNumber::VAR_in_temp_water_tank_f: - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value);} - break; - case MessageNumber::VAR_out_sensor_airout: { - double temp = ((int16_t)message.value) / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value);} - target->set_outdoor_temperature(source, temp); - break; - } - case MessageNumber::VAR_IN_TEMP_EVA_IN_F: { - double temp = ((int16_t)message.value) / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value);} - target->set_indoor_eva_in_temperature(source, temp); - break; - } - case MessageNumber::VAR_IN_TEMP_EVA_OUT_F: { - double temp = ((int16_t)message.value) / 10.0; - if(log_messages){ ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_OUT_F %li", source.c_str(), dest.c_str(), message.value);} - target->set_indoor_eva_out_temperature(source, temp); - break; - } - default: - if (log_undefined_messages) + } + case MessageNumber::ENUM_in_state_humidity_percent: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_state_humidity_percent %li", source.c_str(), dest.c_str(), message.value); + } + break; + case MessageNumber::ENUM_in_operation_power: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + } + target->set_power(source, message.value != 0); + break; + case MessageNumber::ENUM_in_operation_automatic_cleaning: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_automatic_cleaning %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + } + target->set_automatic_cleaning(source, message.value != 0); + break; + case MessageNumber::ENUM_in_water_heater_power: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_water_heater_power %s", source.c_str(), dest.c_str(), message.value == 0 ? "off" : "on"); + } + target->set_water_heater_power(source, message.value != 0); + break; + case MessageNumber::ENUM_in_operation_mode: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_operation_mode %li", source.c_str(), dest.c_str(), message.value); + } + target->set_mode(source, operation_mode_to_mode(message.value)); + break; + case MessageNumber::ENUM_in_fan_mode: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode %li", source.c_str(), dest.c_str(), message.value); + } + target->set_fanmode(source, fan_mode_real_to_fanmode(message.value)); + break; + case MessageNumber::ENUM_in_fan_mode_real: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_fan_mode_real %li", source.c_str(), dest.c_str(), message.value); + } + break; + case MessageNumber::ENUM_in_alt_mode: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_alt_mode %li", source.c_str(), dest.c_str(), message.value); + } + target->set_altmode(source, message.value); + break; + case MessageNumber::ENUM_in_louver_hl_swing: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_hl_swing %li", source.c_str(), dest.c_str(), message.value); + } + target->set_swing_vertical(source, message.value == 1); + break; + case MessageNumber::ENUM_in_louver_lr_swing: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s ENUM_in_louver_lr_swing %li", source.c_str(), dest.c_str(), message.value); + } + target->set_swing_horizontal(source, message.value == 1); + break; + case MessageNumber::VAR_in_temp_water_tank_f: + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_in_temp_water_tank_f %li", source.c_str(), dest.c_str(), message.value); + } + break; + case MessageNumber::VAR_out_sensor_airout: + { + double temp = ((int16_t)message.value) / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_out_sensor_airout %li", source.c_str(), dest.c_str(), message.value); + } + target->set_outdoor_temperature(source, temp); + break; + } + case MessageNumber::VAR_IN_TEMP_EVA_IN_F: + { + double temp = ((int16_t)message.value) / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_IN_F %li", source.c_str(), dest.c_str(), message.value); + } + target->set_indoor_eva_in_temperature(source, temp); + break; + } + case MessageNumber::VAR_IN_TEMP_EVA_OUT_F: + { + double temp = ((int16_t)message.value) / 10.0; + if (debug_log_messages) + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_TEMP_EVA_OUT_F %li", source.c_str(), dest.c_str(), message.value); + } + target->set_indoor_eva_out_temperature(source, temp); + break; + } + default: + if (debug_undefined_messages) { ESP_LOGW(TAG, "Undefined s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); } - - break; - } -} + break; + } + } DecodeResult try_decode_nasa_packet(std::vector data) { @@ -1074,21 +1139,21 @@ void process_messageset(std::string source, std::string dest, MessageSet &messag case 0x602: // STR_ad_option_install_2 case 0x600: // STR_ad_option_basic case 0x202: // VAR_ad_error_code1 - + case 0x42d1: // VAR_IN_DUST_SENSOR_PM10_0_VALUE - { - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM10_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); - return; // Ingore cause not important + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM10_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important } case 0x42d2: // VAR_IN_DUST_SENSOR_PM2_5_VALUE - { - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM2_5_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); - return; // Ingore cause not important + { + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM2_5_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important } case 0x42d3: // VAR_IN_DUST_SENSOR_PM1_0_VALUE { - ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM1_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); - return; // Ingore cause not important + ESP_LOGW(TAG, "s:%s d:%s VAR_IN_DUST_SENSOR_PM1_0_VALUE %s %li", source.c_str(), dest.c_str(), long_to_hex((int)message.messageNumber).c_str(), message.value); + return; // Ingore cause not important } case 0x23: diff --git a/components/samsung_ac/protocol_non_nasa.cpp b/components/samsung_ac/protocol_non_nasa.cpp index 392edc8a..24965faf 100644 --- a/components/samsung_ac/protocol_non_nasa.cpp +++ b/components/samsung_ac/protocol_non_nasa.cpp @@ -554,39 +554,39 @@ namespace esphome item.request.fanspeed == nonpacket_.command20.fanspeed && item.request.mode == nonpacket_.command20.mode && item.request.power == nonpacket_.command20.power; }); - + // If a state update comes through after a control message has been sent, but before it // has been acknowledged, it should be ignored. This prevents the UI status bouncing // between states after a command has been issued. bool pending_control_message = false; - for (auto& item : nonnasa_requests) + for (auto &item : nonnasa_requests) { - if (item.time_sent > 0 && nonpacket_.src == item.request.dst) - { - pending_control_message = true; - break; - } + if (item.time_sent > 0 && nonpacket_.src == item.request.dst) + { + pending_control_message = true; + break; + } } if (!pending_control_message) { - last_command20s_[nonpacket_.src] = nonpacket_.command20; - target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp); - // TODO - target->set_water_outlet_target(nonpacket_.src, false); - // TODO - target->set_target_water_temperature(nonpacket_.src, false); - target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp); - target->set_power(nonpacket_.src, nonpacket_.command20.power); - // TODO - target->set_water_heater_power(nonpacket_.src, false); - target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode)); - target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed)); - // TODO - target->set_altmode(nonpacket_.src, 0); - // TODO - target->set_swing_horizontal(nonpacket_.src, false); - target->set_swing_vertical(nonpacket_.src, false); + last_command20s_[nonpacket_.src] = nonpacket_.command20; + target->set_target_temperature(nonpacket_.src, nonpacket_.command20.target_temp); + // TODO + target->set_water_outlet_target(nonpacket_.src, false); + // TODO + target->set_target_water_temperature(nonpacket_.src, false); + target->set_room_temperature(nonpacket_.src, nonpacket_.command20.room_temp); + target->set_power(nonpacket_.src, nonpacket_.command20.power); + // TODO + target->set_water_heater_power(nonpacket_.src, false); + target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode)); + target->set_fanmode(nonpacket_.src, nonnasa_fanspeed_to_fanmode(nonpacket_.command20.fanspeed)); + // TODO + target->set_altmode(nonpacket_.src, 0); + // TODO + target->set_swing_horizontal(nonpacket_.src, false); + target->set_swing_vertical(nonpacket_.src, false); } } else if (nonpacket_.cmd == NonNasaCommand::CmdC6) diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 867659ba..19a0650b 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -51,13 +51,9 @@ namespace esphome { non_nasa_keepalive = value; } -void set_log_undefined_messages (bool value) + void set_debug_log_undefined_messages(bool value) { - log_undefined_messages = value; - } - void set_log_messages (bool value) - { - log_messages = value; + debug_log_undefined_messages = value; } void register_device(Samsung_AC_Device *device); @@ -107,7 +103,7 @@ void set_log_undefined_messages (bool value) if (dev != nullptr) dev->update_target_temperature(value); } - + void /*MessageTarget::*/ set_water_outlet_target(const std::string address, float value) override { Samsung_AC_Device *dev = find_device(address); diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index c1a892a1..409d490d 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -89,8 +89,8 @@ namespace esphome std::string address; sensor::Sensor *room_temperature{nullptr}; sensor::Sensor *outdoor_temperature{nullptr}; - sensor::Sensor *indoor_eva_in_temperature{nullptr}; - sensor::Sensor *indoor_eva_out_temperature{nullptr}; + sensor::Sensor *indoor_eva_in_temperature{nullptr}; + sensor::Sensor *indoor_eva_out_temperature{nullptr}; Samsung_AC_Number *target_temperature{nullptr}; Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; @@ -109,12 +109,12 @@ namespace esphome void set_outdoor_temperature_sensor(sensor::Sensor *sensor) { - outdoor_temperature = sensor; + outdoor_temperature = sensor; } void set_indoor_eva_in_temperature_sensor(sensor::Sensor *sensor) { - indoor_eva_in_temperature = sensor; + indoor_eva_in_temperature = sensor; } void set_indoor_eva_out_temperature_sensor(sensor::Sensor *sensor) @@ -148,8 +148,8 @@ namespace esphome publish_request(request); }; } - -void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) + + void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) { automatic_cleaning = switch_; automatic_cleaning->write_state_ = [this](bool value) @@ -192,7 +192,7 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) publish_request(request); }; }; - + void set_water_outlet_target_number(Samsung_AC_Number *number) { water_outlet_target = number; @@ -231,7 +231,7 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) climate->publish_state(); } } - + void update_water_outlet_target(float value) { if (water_outlet_target != nullptr) @@ -257,8 +257,8 @@ void set_automatic_cleaning_switch(Samsung_AC_Switch *switch_) if (climate != nullptr) calc_and_publish_mode(); } - -void update_automatic_cleaning(bool value) + + void update_automatic_cleaning(bool value) { _cur_automatic_cleaning = value; if (automatic_cleaning != nullptr) diff --git a/example.yaml b/example.yaml index 206b2386..decfc305 100644 --- a/example.yaml +++ b/example.yaml @@ -47,7 +47,7 @@ uart: # Import custom component from GitHub external_components: - - source: github://omerfaruk-aran/esphome_samsung_ac@new_test # use @main if you want the latest development (possibly unstable?) + - source: github://omerfaruk-aran/esphome_samsung_ac@main # use @main if you want the latest development (possibly unstable?) components: [samsung_ac] # Configuration of AC component @@ -58,10 +58,10 @@ samsung_ac: non_nasa_keepalive: true #When enabled (set to true), this option will log the messages associated with undefined codes on the device. This is useful for debugging and identifying any unexpected or unknown codes that the device may receive during operation. - log_undefined_messages: false + debug_log_undefined_messages: false #When enabled (set to true), this option logs messages associated with defined codes on the device. This helps in monitoring the behavior of the device by recording the activity related to known, expected codes. - log_messages: false + debug_log_messages: false # Capabilities configure the features alle devices of your AC system have (all parts of this section are optional). # All capabilities are off by default, you need to enable only those your devices have. From 3733db426d453ff782a3c82c9fe1c766e9dc2ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20ARAN?= Date: Wed, 14 Aug 2024 13:55:03 +0300 Subject: [PATCH 21/21] The debug_log_packets variable has been optimized. --- components/samsung_ac/protocol.cpp | 3 ++- components/samsung_ac/protocol.h | 3 ++- components/samsung_ac/protocol_nasa.cpp | 4 ++-- components/samsung_ac/protocol_non_nasa.cpp | 2 +- components/samsung_ac/samsung_ac.h | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/samsung_ac/protocol.cpp b/components/samsung_ac/protocol.cpp index 4e53f41d..676a0524 100644 --- a/components/samsung_ac/protocol.cpp +++ b/components/samsung_ac/protocol.cpp @@ -8,10 +8,11 @@ namespace esphome { namespace samsung_ac { - bool debug_log_packets = false; + //bool debug_log_packets = false; bool debug_log_raw_bytes = false; bool non_nasa_keepalive = false; bool debug_log_undefined_messages = false; + bool debug_log_messages = false; ProtocolProcessing protocol_processing = ProtocolProcessing::Auto; // This functions is designed to run after a new value was added diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 5157c401..4f21ebd4 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -8,10 +8,11 @@ namespace esphome { namespace samsung_ac { - extern bool debug_log_packets; + //extern bool debug_log_packets; extern bool debug_log_raw_bytes; extern bool non_nasa_keepalive; extern bool debug_log_undefined_messages; + extern bool debug_log_messages; enum class DecodeResult { diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 5da5e953..11ce6efe 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -685,7 +685,7 @@ namespace esphome break; } default: - if (debug_undefined_messages) + if (debug_log_undefined_messages) { ESP_LOGW(TAG, "Undefined s:%s d:%s %s", source.c_str(), dest.c_str(), message.to_string().c_str()); } @@ -706,7 +706,7 @@ namespace esphome target->register_address(source); - if (debug_log_packets) + if (debug_log_messages) { ESP_LOGW(TAG, "MSG: %s", packet_.to_string().c_str()); } diff --git a/components/samsung_ac/protocol_non_nasa.cpp b/components/samsung_ac/protocol_non_nasa.cpp index 24965faf..5f97cab0 100644 --- a/components/samsung_ac/protocol_non_nasa.cpp +++ b/components/samsung_ac/protocol_non_nasa.cpp @@ -528,7 +528,7 @@ namespace esphome void process_non_nasa_packet(MessageTarget *target) { - if (debug_log_packets) + if (debug_log_messages) { ESP_LOGW(TAG, "MSG: %s", nonpacket_.to_string().c_str()); } diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 19a0650b..1fcab17a 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -39,7 +39,7 @@ namespace esphome void set_debug_log_messages(bool value) { - debug_log_packets = value; + debug_log_messages = value; } void set_debug_log_messages_raw(bool value)