From 4c6312bda5803d42f19753b1f38c8d051647f98d Mon Sep 17 00:00:00 2001 From: north3221 Date: Mon, 22 Jul 2024 21:51:57 +0100 Subject: [PATCH 1/2] first commit to try and add water outlet target --- components/samsung_ac/__init__.py | 13 ++++++++++++- components/samsung_ac/protocol.h | 2 ++ components/samsung_ac/protocol_nasa.cpp | 14 ++++++++++++++ components/samsung_ac/protocol_nasa.h | 1 + components/samsung_ac/protocol_non_nasa.cpp | 2 ++ components/samsung_ac/samsung_ac.h | 7 +++++++ components/samsung_ac/samsung_ac_device.h | 18 ++++++++++++++++++ 7 files changed, 56 insertions(+), 1 deletion(-) diff --git a/components/samsung_ac/__init__.py b/components/samsung_ac/__init__.py index fbdfddb8..1adea78d 100644 --- a/components/samsung_ac/__init__.py +++ b/components/samsung_ac/__init__.py @@ -53,6 +53,7 @@ CONF_DEVICE_ROOM_TEMPERATURE = "room_temperature" CONF_DEVICE_ROOM_TEMPERATURE_OFFSET = "room_temperature_offset" CONF_DEVICE_TARGET_TEMPERATURE = "target_temperature" +CONF_DEVICE_WATER_OUTLET_TARGET = "water_outlet_target" CONF_DEVICE_OUTDOOR_TEMPERATURE = "outdoor_temperature" CONF_DEVICE_WATER_TEMPERATURE = "water_temperature" CONF_DEVICE_WATER_TARGET_TEMPERATURE = "water_target_temperature" @@ -61,7 +62,6 @@ CONF_DEVICE_MODE = "mode" CONF_DEVICE_CLIMATE = "climate" CONF_DEVICE_ROOM_HUMIDITY = "room_humidity" -CONF_DEVICE_WATER_TEMPERATURE = "water_temperature" CONF_DEVICE_CUSTOM = "custom_sensor" CONF_DEVICE_CUSTOM_MESSAGE = "message" CONF_DEVICE_CUSTOM_RAW_FILTERS = "raw_filters" @@ -180,6 +180,7 @@ def humidity_sensor_schema(message: int): state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_DEVICE_TARGET_TEMPERATURE): NUMBER_SCHEMA, + cv.Optional(CONF_DEVICE_WATER_OUTLET_TARGET): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_WATER_TARGET_TEMPERATURE): NUMBER_SCHEMA, cv.Optional(CONF_DEVICE_POWER): switch.switch_schema(Samsung_AC_Switch), cv.Optional(CONF_DEVICE_DHW_POWER): switch.switch_schema(Samsung_AC_Switch), @@ -332,6 +333,16 @@ async def to_code(config): max_value=30.0, step=1.0) cg.add(var_dev.set_target_temperature_number(num)) + + if CONF_DEVICE_WATER_OUTLET_TARGET in device: + conf = device[CONF_DEVICE_WATER_OUTLET_TARGET] + conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS + conf[CONF_DEVICE_CLASS] = DEVICE_CLASS_TEMPERATURE + num = await number.new_number(conf, + min_value=15.0, + max_value=55.0, + step=0.1) + cg.add(var_dev.set_water_outlet_target_number(num)) if CONF_DEVICE_MODE in device: conf = device[CONF_DEVICE_MODE] diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index b4bf6778..8733e1b9 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -70,6 +70,7 @@ namespace esphome virtual void set_dhw_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; + 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_target_water_temperature(const std::string address, float value) = 0; virtual void set_mode(const std::string address, Mode mode) = 0; @@ -88,6 +89,7 @@ namespace esphome optional dhw_power; optional mode; optional target_temp; + optional water_outlet_target; optional target_water_temp; optional fan_mode; optional swing_mode; diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index 13ead487..cf6661ab 100644 --- a/components/samsung_ac/protocol_nasa.cpp +++ b/components/samsung_ac/protocol_nasa.cpp @@ -401,6 +401,13 @@ namespace esphome 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); @@ -534,6 +541,13 @@ namespace esphome 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 { diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index b7ad320f..3ce7cf05 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -81,6 +81,7 @@ namespace esphome ENUM_in_state_humidity_percent = 0x4038, VAR_in_temp_room_f = 0x4203, VAR_in_temp_target_f = 0x4201, + VAR_in_temp_water_outlet_target_f = 0x4247, VAR_in_temp_water_tank_f = 0x4237, VAR_out_sensor_airout = 0x8204, VAR_in_temp_water_heater_target_f = 0x4235, diff --git a/components/samsung_ac/protocol_non_nasa.cpp b/components/samsung_ac/protocol_non_nasa.cpp index 54cc94f7..e07800ba 100644 --- a/components/samsung_ac/protocol_non_nasa.cpp +++ b/components/samsung_ac/protocol_non_nasa.cpp @@ -572,6 +572,8 @@ namespace esphome { 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); diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index ce701b34..05d12174 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -86,6 +86,13 @@ namespace esphome 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); + if (dev != nullptr) + dev->update_water_outlet_target(value); + } void /*MessageTarget::*/ set_target_water_temperature(const std::string address, float value) override { diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index fbf508fa..9e5831c3 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -90,6 +90,7 @@ namespace esphome sensor::Sensor *room_temperature{nullptr}; sensor::Sensor *outdoor_temperature{nullptr}; Samsung_AC_Number *target_temperature{nullptr}; + Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; Samsung_AC_Switch *power{nullptr}; Samsung_AC_Switch *dhw_power{nullptr}; @@ -167,6 +168,17 @@ namespace esphome publish_request(request); }; }; + + void set_water_outlet_target_number(Samsung_AC_Number *number) + { + water_outlet_target = number; + water_outlet_target->write_state_ = [this](float value) + { + ProtocolRequest request; + request.water_outlet_target = value; + publish_request(request); + }; + }; void set_target_water_temperature_number(Samsung_AC_Number *number) { @@ -195,6 +207,12 @@ namespace esphome climate->publish_state(); } } + + void update_water_outlet_target(float value) + { + if (water_outlet_target != nullptr) + water_outlet_target->publish_state(value); + } void update_target_water_temperature(float value) { From 2b11c06531c5b9437e0697fc18f1ab14754142d1 Mon Sep 17 00:00:00 2001 From: north3221 Date: Wed, 24 Jul 2024 10:17:29 +0100 Subject: [PATCH 2/2] replace all tabs with space --- components/samsung_ac/protocol.h | 10 +++++----- components/samsung_ac/protocol_nasa.cpp | 18 ++++++++--------- components/samsung_ac/protocol_nasa.h | 4 ++-- components/samsung_ac/protocol_non_nasa.cpp | 8 ++++---- components/samsung_ac/samsung_ac.h | 8 ++++---- components/samsung_ac/samsung_ac_device.h | 22 ++++++++++----------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/components/samsung_ac/protocol.h b/components/samsung_ac/protocol.h index 8733e1b9..2b61ca4d 100644 --- a/components/samsung_ac/protocol.h +++ b/components/samsung_ac/protocol.h @@ -67,13 +67,13 @@ 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_dhw_power(const std::string address, bool value) = 0; + virtual void set_dhw_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; - virtual void set_water_outlet_target(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_target_water_temperature(const std::string address, float value) = 0; - virtual void set_mode(const std::string address, Mode mode) = 0; + virtual void set_mode(const std::string address, Mode mode) = 0; virtual void set_fanmode(const std::string address, FanMode fanmode) = 0; virtual void set_altmode(const std::string address, AltMode altmode) = 0; virtual void set_swing_vertical(const std::string address, bool vertical) = 0; @@ -86,10 +86,10 @@ namespace esphome { public: optional power; - optional dhw_power; + optional dhw_power; optional mode; optional target_temp; - optional water_outlet_target; + optional water_outlet_target; optional target_water_temp; optional fan_mode; optional swing_mode; diff --git a/components/samsung_ac/protocol_nasa.cpp b/components/samsung_ac/protocol_nasa.cpp index cf6661ab..a9be5f9b 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.dhw_power) + + if (request.dhw_power) { MessageSet dhwpower(MessageNumber::ENUM_in_water_heater_power); dhwpower.value = request.dhw_power.value() ? 1 : 0; @@ -400,15 +400,15 @@ namespace esphome targettemp.value = request.target_temp.value() * 10.0; packet.messages.push_back(targettemp); } - - if (request.water_outlet_target) + + 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) + + if (request.target_water_temp) { MessageSet targetwatertemp(MessageNumber::VAR_in_temp_water_heater_target_f); targetwatertemp.value = request.target_water_temp.value() * 10.0; @@ -542,14 +542,14 @@ namespace esphome target->set_target_temperature(source, temp); return; } - case MessageNumber::VAR_in_temp_water_outlet_target_f: // unit = 'Celsius' from XML + 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 + 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); @@ -568,7 +568,7 @@ namespace esphome target->set_power(source, message.value != 0); return; } - case MessageNumber::ENUM_in_water_heater_power: + 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_dhw_power(source, message.value != 0); diff --git a/components/samsung_ac/protocol_nasa.h b/components/samsung_ac/protocol_nasa.h index 3ce7cf05..edae3003 100644 --- a/components/samsung_ac/protocol_nasa.h +++ b/components/samsung_ac/protocol_nasa.h @@ -71,7 +71,7 @@ namespace esphome { Undefiend = 0, ENUM_in_operation_power = 0x4000, - ENUM_in_water_heater_power = 0x4065, + 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 ENUM_in_fan_mode_real = 0x4007, @@ -81,7 +81,7 @@ namespace esphome ENUM_in_state_humidity_percent = 0x4038, VAR_in_temp_room_f = 0x4203, VAR_in_temp_target_f = 0x4201, - VAR_in_temp_water_outlet_target_f = 0x4247, + VAR_in_temp_water_outlet_target_f = 0x4247, VAR_in_temp_water_tank_f = 0x4237, VAR_out_sensor_airout = 0x8204, VAR_in_temp_water_heater_target_f = 0x4235, diff --git a/components/samsung_ac/protocol_non_nasa.cpp b/components/samsung_ac/protocol_non_nasa.cpp index e07800ba..3c41d6ad 100644 --- a/components/samsung_ac/protocol_non_nasa.cpp +++ b/components/samsung_ac/protocol_non_nasa.cpp @@ -572,10 +572,10 @@ namespace esphome { 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); + // 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); target->set_mode(nonpacket_.src, nonnasa_mode_to_mode(nonpacket_.command20.mode)); diff --git a/components/samsung_ac/samsung_ac.h b/components/samsung_ac/samsung_ac.h index 05d12174..8536159e 100644 --- a/components/samsung_ac/samsung_ac.h +++ b/components/samsung_ac/samsung_ac.h @@ -86,8 +86,8 @@ namespace esphome if (dev != nullptr) dev->update_target_temperature(value); } - - void /*MessageTarget::*/ set_water_outlet_target(const std::string address, float value) override + + void /*MessageTarget::*/ set_water_outlet_target(const std::string address, float value) override { Samsung_AC_Device *dev = find_device(address); if (dev != nullptr) @@ -107,8 +107,8 @@ namespace esphome if (dev != nullptr) dev->update_power(value); } - - void /*MessageTarget::*/ set_dhw_power(const std::string address, bool value) override + + void /*MessageTarget::*/ set_dhw_power(const std::string address, bool value) override { Samsung_AC_Device *dev = find_device(address); if (dev != nullptr) diff --git a/components/samsung_ac/samsung_ac_device.h b/components/samsung_ac/samsung_ac_device.h index 9e5831c3..c16e89da 100644 --- a/components/samsung_ac/samsung_ac_device.h +++ b/components/samsung_ac/samsung_ac_device.h @@ -90,10 +90,10 @@ namespace esphome sensor::Sensor *room_temperature{nullptr}; sensor::Sensor *outdoor_temperature{nullptr}; Samsung_AC_Number *target_temperature{nullptr}; - Samsung_AC_Number *water_outlet_target{nullptr}; + Samsung_AC_Number *water_outlet_target{nullptr}; Samsung_AC_Number *target_water_temperature{nullptr}; Samsung_AC_Switch *power{nullptr}; - Samsung_AC_Switch *dhw_power{nullptr}; + Samsung_AC_Switch *dhw_power{nullptr}; Samsung_AC_Mode_Select *mode{nullptr}; Samsung_AC_Climate *climate{nullptr}; std::vector custom_sensors; @@ -135,8 +135,8 @@ namespace esphome publish_request(request); }; } - - void set_dhw_power_switch(Samsung_AC_Switch *switch_) + + void set_dhw_power_switch(Samsung_AC_Switch *switch_) { dhw_power = switch_; dhw_power->write_state_ = [this](bool value) @@ -168,8 +168,8 @@ namespace esphome publish_request(request); }; }; - - void set_water_outlet_target_number(Samsung_AC_Number *number) + + void set_water_outlet_target_number(Samsung_AC_Number *number) { water_outlet_target = number; water_outlet_target->write_state_ = [this](float value) @@ -207,8 +207,8 @@ namespace esphome climate->publish_state(); } } - - void update_water_outlet_target(float value) + + void update_water_outlet_target(float value) { if (water_outlet_target != nullptr) water_outlet_target->publish_state(value); @@ -221,7 +221,7 @@ namespace esphome } optional _cur_power; - optional _cur_dhw_power; + optional _cur_dhw_power; optional _cur_mode; void update_power(bool value) @@ -232,8 +232,8 @@ namespace esphome if (climate != nullptr) calc_and_publish_mode(); } - - void update_dhw_power(bool value) + + void update_dhw_power(bool value) { _cur_dhw_power = value; if (dhw_power != nullptr)