Skip to content

Commit

Permalink
Merge pull request #145 from north3221/dhw-target-temp
Browse files Browse the repository at this point in the history
Dhw target temp
  • Loading branch information
lanwin authored Jul 24, 2024
2 parents 9fb897a + 31e9f97 commit 84e6803
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/samsung_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
CONF_DEVICE_ROOM_TEMPERATURE_OFFSET = "room_temperature_offset"
CONF_DEVICE_TARGET_TEMPERATURE = "target_temperature"
CONF_DEVICE_OUTDOOR_TEMPERATURE = "outdoor_temperature"
CONF_DEVICE_WATER_TEMPERATURE = "water_temperature"
CONF_DEVICE_WATER_TARGET_TEMPERATURE = "water_target_temperature"
CONF_DEVICE_POWER = "power"
CONF_DEVICE_MODE = "mode"
CONF_DEVICE_CLIMATE = "climate"
Expand Down Expand Up @@ -177,6 +179,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_TARGET_TEMPERATURE): NUMBER_SCHEMA,
cv.Optional(CONF_DEVICE_POWER): switch.switch_schema(Samsung_AC_Switch),
cv.Optional(CONF_DEVICE_MODE): SELECT_MODE_SCHEMA,
cv.Optional(CONF_DEVICE_CLIMATE): CLIMATE_SCHEMA,
Expand Down Expand Up @@ -303,6 +306,16 @@ async def to_code(config):
sens = await sensor.new_sensor(conf)
cg.add(var_dev.set_outdoor_temperature_sensor(sens))

if CONF_DEVICE_WATER_TARGET_TEMPERATURE in device:
conf = device[CONF_DEVICE_WATER_TARGET_TEMPERATURE]
conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS
conf[CONF_DEVICE_CLASS] = DEVICE_CLASS_TEMPERATURE
num = await number.new_number(conf,
min_value=30.0,
max_value=70.0,
step=0.5)
cg.add(var_dev.set_target_water_temperature_number(num))

if CONF_DEVICE_TARGET_TEMPERATURE in device:
conf = device[CONF_DEVICE_TARGET_TEMPERATURE]
conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS
Expand Down
2 changes: 2 additions & 0 deletions components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace esphome
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_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_fanmode(const std::string address, FanMode fanmode) = 0;
virtual void set_altmode(const std::string address, AltMode altmode) = 0;
Expand All @@ -85,6 +86,7 @@ namespace esphome
optional<bool> power;
optional<Mode> mode;
optional<float> target_temp;
optional<float> target_water_temp;
optional<FanMode> fan_mode;
optional<SwingMode> swing_mode;
optional<AltMode> alt_mode;
Expand Down
14 changes: 14 additions & 0 deletions components/samsung_ac/protocol_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ namespace esphome
targettemp.value = request.target_temp.value() * 10.0;
packet.messages.push_back(targettemp);
}

if (request.target_water_temp)
{
MessageSet targetwatertemp(MessageNumber::VAR_in_temp_water_heater_target_f);
targetwatertemp.value = request.target_water_temp.value() * 10.0;
packet.messages.push_back(targetwatertemp);
}

if (request.fan_mode)
{
Expand Down Expand Up @@ -521,6 +528,13 @@ namespace esphome
target->set_target_temperature(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
Expand Down
1 change: 1 addition & 0 deletions components/samsung_ac/protocol_nasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace esphome
VAR_in_temp_target_f = 0x4201,
VAR_in_temp_water_tank_f = 0x4237,
VAR_out_sensor_airout = 0x8204,
VAR_in_temp_water_heater_target_f = 0x4235,
};

struct Address
Expand Down
2 changes: 2 additions & 0 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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));
Expand Down
7 changes: 7 additions & 0 deletions components/samsung_ac/samsung_ac.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ namespace esphome
dev->update_target_temperature(value);
}

void /*MessageTarget::*/ set_target_water_temperature(const std::string address, float value) override
{
Samsung_AC_Device *dev = find_device(address);
if (dev != nullptr)
dev->update_target_water_temperature(value);
}

void /*MessageTarget::*/ set_power(const std::string address, bool value) override
{
Samsung_AC_Device *dev = find_device(address);
Expand Down
18 changes: 18 additions & 0 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *target_water_temperature{nullptr};
Samsung_AC_Switch *power{nullptr};
Samsung_AC_Mode_Select *mode{nullptr};
Samsung_AC_Climate *climate{nullptr};
Expand Down Expand Up @@ -155,6 +156,17 @@ namespace esphome
};
};

void set_target_water_temperature_number(Samsung_AC_Number *number)
{
target_water_temperature = number;
target_water_temperature->write_state_ = [this](float value)
{
ProtocolRequest request;
request.target_water_temp = value;
publish_request(request);
};
};

void set_climate(Samsung_AC_Climate *value)
{
climate = value;
Expand All @@ -172,6 +184,12 @@ namespace esphome
}
}

void update_target_water_temperature(float value)
{
if (target_water_temperature != nullptr)
target_water_temperature->publish_state(value);
}

optional<bool> _cur_power;
optional<Mode> _cur_mode;

Expand Down
2 changes: 2 additions & 0 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ samsung_ac:
# Only supported on NASA based heatpumps
water_temperature:
name: "Warm water"
water_target_temperature:
name: "Hot Water Target Temperature"
outdoor_temperature: # Should be used with outdoor device address
name: "Outdoor temperature"

8 changes: 8 additions & 0 deletions test/test_stuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class DebugTarget : public MessageTarget
cout << "> " << address << " set_outdoor_temperature=" << to_string(value) << endl;
last_set_outdoor_temperature_address = address;
last_set_outdoor_temperature_value = value;

std::string last_set_target_water_temperature_address;
float last_set_target_water_temperature_value;
void set_target_water_temperature(const std::string address, float value)
{
cout << "> " << address << " set_target_water_temperature=" << to_string(value) << endl;
last_set_target_water_temperature_address = address;
last_set_target_water_temperature_value = value;
}

std::string last_set_room_humidity_address;
Expand Down

0 comments on commit 84e6803

Please sign in to comment.