Skip to content

Commit

Permalink
Merge pull request #167 from omerfaruk-aran/error_code_monitoring
Browse files Browse the repository at this point in the history
Error code monitoring
  • Loading branch information
lanwin authored Aug 27, 2024
2 parents 164b90a + d35cb57 commit cbd3669
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
19 changes: 17 additions & 2 deletions components/samsung_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
CONF_DEVICE_CUSTOM = "custom_sensor"
CONF_DEVICE_CUSTOM_MESSAGE = "message"
CONF_DEVICE_CUSTOM_RAW_FILTERS = "raw_filters"
CONF_DEVICE_ERROR_CODE = "error_code"


CONF_CAPABILITIES = "capabilities"
CONF_CAPABILITIES_HORIZONTAL_SWING = "horizontal_swing"
Expand Down Expand Up @@ -166,7 +168,14 @@ def humidity_sensor_schema(message: int):
state_class=STATE_CLASS_MEASUREMENT,
)


def error_code_sensor_schema(message: int):
return custom_sensor_schema(
message=message,
unit_of_measurement="",
accuracy_decimals=0,
icon="mdi:alert",
)

DEVICE_SCHEMA = (
cv.Schema(
{
Expand Down Expand Up @@ -198,6 +207,7 @@ def humidity_sensor_schema(message: int):
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_DEVICE_ERROR_CODE): error_code_sensor_schema(0x8235),
cv.Optional(CONF_DEVICE_TARGET_TEMPERATURE): NUMBER_SCHEMA,
cv.Optional(CONF_DEVICE_WATER_OUTLET_TARGET): NUMBER_SCHEMA,
cv.Optional(CONF_DEVICE_WATER_TARGET_TEMPERATURE): NUMBER_SCHEMA,
Expand Down Expand Up @@ -353,7 +363,12 @@ async def to_code(config):
conf = device[CONF_DEVICE_INDOOR_EVA_OUT_TEMPERATURE]
sens = await sensor.new_sensor(conf)
cg.add(var_dev.set_indoor_eva_out_temperature_sensor(sens))


if CONF_DEVICE_ERROR_CODE in device:
conf = device[CONF_DEVICE_ERROR_CODE]
sens = await sensor.new_sensor(conf)
cg.add(var_dev.set_error_code_sensor(sens))

if CONF_DEVICE_WATER_TARGET_TEMPERATURE in device:
conf = device[CONF_DEVICE_WATER_TARGET_TEMPERATURE]
conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS
Expand Down
3 changes: 2 additions & 1 deletion components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace esphome
Fan = 3,
Heat = 4,
};

enum class WaterHeaterMode
{
Unknown = -1,
Expand Down Expand Up @@ -94,6 +94,7 @@ namespace esphome
virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0;
virtual optional<std::set<uint16_t>> get_custom_sensors(const std::string address) = 0;
virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0;
virtual void set_error_code(const std::string address, int error_code) = 0;
};

struct ProtocolRequest
Expand Down
15 changes: 11 additions & 4 deletions components/samsung_ac/protocol_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,17 @@ namespace esphome
target->set_indoor_eva_out_temperature(source, temp);
break;
}
case MessageNumber::VAR_out_error_code:
{
int code = static_cast<int>(message.value);
if (debug_log_messages)
{
ESP_LOGW(TAG, "s:%s d:%s VAR_out_error_code %d", source.c_str(), dest.c_str(), code);
}
target->set_error_code(source, code);
break;
}

default:
{
double value = 0;
Expand Down Expand Up @@ -922,10 +933,6 @@ namespace esphome
LOG_MESSAGE(ENUM_out_load_4way, message.value, source, dest);
break;

case 0x8235: // VAR_out_error_code
LOG_MESSAGE(VAR_out_error_code, message.value, source, dest);
break;

case 0x8261: // VAR_OUT_SENSOR_PIPEIN3 unit = 'Celsius'
{
double temp = (double)message.value / (double)10;
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 @@ -89,6 +89,7 @@ namespace esphome
VAR_in_temp_water_heater_target_f = 0x4235,
VAR_in_temp_eva_in_f = 0x4205,
VAR_in_temp_eva_out_f = 0x4206,
VAR_out_error_code = 0x8235,
};

struct Address
Expand Down
8 changes: 7 additions & 1 deletion components/samsung_ac/samsung_ac.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace esphome
if (dev != nullptr)
dev->update_mode(mode);
}

void /*MessageTarget::*/ set_water_heater_mode(const std::string address, WaterHeaterMode waterheatermode) override
{
Samsung_AC_Device *dev = find_device(address);
Expand Down Expand Up @@ -193,6 +193,12 @@ namespace esphome
if (dev != nullptr)
dev->update_custom_sensor(message_number, value);
}
void /*MessageTarget::*/ set_error_code(const std::string address, int value) override
{
Samsung_AC_Device *dev = find_device(address);
if (dev != nullptr)
dev->update_error_code(value);
}

protected:
Samsung_AC_Device *find_device(const std::string address)
Expand Down
18 changes: 15 additions & 3 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace esphome

std::function<void(Mode)> write_state_;
};

class Samsung_AC_Water_Heater_Mode_Select : public select::Select
{
public:
Expand Down Expand Up @@ -107,6 +107,7 @@ namespace esphome
sensor::Sensor *outdoor_temperature{nullptr};
sensor::Sensor *indoor_eva_in_temperature{nullptr};
sensor::Sensor *indoor_eva_out_temperature{nullptr};
sensor::Sensor *error_code{nullptr};
Samsung_AC_Number *target_temperature{nullptr};
Samsung_AC_Number *water_outlet_target{nullptr};
Samsung_AC_Number *target_water_temperature{nullptr};
Expand Down Expand Up @@ -139,6 +140,11 @@ namespace esphome
indoor_eva_out_temperature = sensor;
}

void set_error_code_sensor(sensor::Sensor *sensor)
{
error_code = sensor;
}

void add_custom_sensor(int message_number, sensor::Sensor *sensor)
{
Samsung_AC_Sensor cust_sensor;
Expand Down Expand Up @@ -198,7 +204,7 @@ namespace esphome
publish_request(request);
};
}

void set_water_heater_mode_select(Samsung_AC_Water_Heater_Mode_Select *select)
{
waterheatermode = select;
Expand Down Expand Up @@ -311,7 +317,7 @@ namespace esphome
if (climate != nullptr)
calc_and_publish_mode();
}

void update_water_heater_mode(WaterHeaterMode value)
{
_cur_water_heater_mode = value;
Expand Down Expand Up @@ -415,6 +421,12 @@ namespace esphome
indoor_eva_out_temperature->publish_state(value);
}

void update_error_code(int value)
{
if (error_code != nullptr)
error_code->publish_state(value);
}

void update_custom_sensor(uint16_t message_number, float value)
{
for (auto &sensor : custom_sensors)
Expand Down
7 changes: 7 additions & 0 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ samsung_ac:
# Only supported on NASA devices
room_humidity:
name: "Kitchen humidity"

# This sensor captures and monitors specific error codes returned by the HVAC system.
# When an error occurs, the sensor detects the error code and updates its value accordingly.
# Additionally, by using the blueprint available at https://github.com/omerfaruk-aran/esphome_samsung_ac_blueprint,
# you can automatically send detailed error messages to your mobile devices based on the captured error codes.
error_code:
name: "Error Code"

# Only supported on NASA based heatpumps
water_temperature:
Expand Down

0 comments on commit cbd3669

Please sign in to comment.