From 87e05a1bfe67802a9fec8640511ea824d1e4156e Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Wed, 27 Dec 2023 19:00:44 +0100 Subject: [PATCH] Added indoor humidity sensor support --- .haier-hon-base.yaml | 6 +++++- components/haier/hon_climate.cpp | 3 +++ components/haier/hon_climate.h | 1 + components/haier/sensor/__init__.py | 10 ++++++++++ configs/sensor/humidity.yaml | 5 +++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 configs/sensor/humidity.yaml diff --git a/.haier-hon-base.yaml b/.haier-hon-base.yaml index 208d7f5..388af72 100644 --- a/.haier-hon-base.yaml +++ b/.haier-hon-base.yaml @@ -19,8 +19,12 @@ packages: # Horizontal airflow direction setting. Works only if the horizontal swing # is off. You can remove this control if you don't need it airflow_horizontal_select: !include configs/select/airflow_horizontal.yaml - # Diagnostic sensors + # Additional sensors outdoor_temperature_sensor: !include configs/sensor/outdoor_temperature.yaml + # Make sure that your AC supports humidity before uncommenting it + # (in the opposite case value will always be 0) + #indoor_humidity_sensor: !include configs/sensor/humidity.yaml + # Diagnostic sensors indoor_coil_temperature_sensor: !include configs/sensor/indoor_coil_temperature.yaml outdoor_coil_temperature_sensor: !include configs/sensor/outdoor_coil_temperature.yaml outdoor_defrost_temperature_sensor: !include configs/sensor/outdoor_defrost_temperature.yaml diff --git a/components/haier/hon_climate.cpp b/components/haier/hon_climate.cpp index d34e89a..ddd9a2a 100644 --- a/components/haier/hon_climate.cpp +++ b/components/haier/hon_climate.cpp @@ -776,6 +776,9 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t * this->got_valid_outdoor_temp_ = true; this->update_sub_sensor(SubSensorType::OUTDOOR_TEMPERATURE, (float) (packet.sensors.outdoor_temperature + PROTOCOL_OUTDOOR_TEMPERATURE_OFFSET)); } + if ((this->sub_sensors_[(size_t)SubSensorType::HUMIDITY] != nullptr) && (packet.sensors.room_humidity <= 100)) { + this->update_sub_sensor(SubSensorType::HUMIDITY, (float) packet.sensors.room_humidity); + } #endif // USE_SENSOR bool should_publish = false; { diff --git a/components/haier/hon_climate.h b/components/haier/hon_climate.h index 74fc3be..a373e9b 100644 --- a/components/haier/hon_climate.h +++ b/components/haier/hon_climate.h @@ -44,6 +44,7 @@ class HonClimate : public HaierClimateBase { enum class SubSensorType { // Used data based sensors OUTDOOR_TEMPERATURE = 0, + HUMIDITY, // Big data based sensors INDOOR_COIL_TEMPERATURE, OUTDOOR_COIL_TEMPERATURE, diff --git a/components/haier/sensor/__init__.py b/components/haier/sensor/__init__.py index d31f31d..c78a209 100644 --- a/components/haier/sensor/__init__.py +++ b/components/haier/sensor/__init__.py @@ -3,8 +3,10 @@ from esphome.components import sensor from esphome.const import ( CONF_POWER, + CONF_HUMIDITY, DEVICE_CLASS_CURRENT, DEVICE_CLASS_FREQUENCY, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, @@ -14,6 +16,7 @@ ICON_HEATING_COIL, ICON_PULSE, ICON_THERMOMETER, + ICON_WATER_PERCENT, ICON_WEATHER_WINDY, STATE_CLASS_MEASUREMENT, UNIT_AMPERE, @@ -69,6 +72,13 @@ state_class=STATE_CLASS_MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, ), + CONF_HUMIDITY: sensor.sensor_schema( + unit_of_measurement=UNIT_PERCENT, + icon=ICON_WATER_PERCENT, + accuracy_decimals=0, + device_class=DEVICE_CLASS_HUMIDITY, + state_class=STATE_CLASS_MEASUREMENT, + ), CONF_INDOOR_COIL_TEMPERATURE: sensor.sensor_schema( unit_of_measurement=UNIT_CELSIUS, icon=ICON_HEATING_COIL, diff --git a/configs/sensor/humidity.yaml b/configs/sensor/humidity.yaml new file mode 100644 index 0000000..4c22593 --- /dev/null +++ b/configs/sensor/humidity.yaml @@ -0,0 +1,5 @@ +sensor: + - platform: haier + haier_id: ${device_id} + humidity: + name: ${device_name} Indoor Humidity