Skip to content

Commit abd29e5

Browse files
committed
Add hvac_action support
1 parent 96d86a4 commit abd29e5

6 files changed

Lines changed: 75 additions & 9 deletions

File tree

README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ Configuration variables:
116116
- **alternative_swing_control** (*Optional*, boolean): (supported by smartAir2 only) If ``true`` - use alternative values to control swing mode. Use only if the original control method is not working for your AC.
117117
- **status_message_header_size** (*Optional*, int): (supported only by hOn) Define the header size of the status message. Can be used to handle some protocol variations. Use only if you are sure what you are doing. The default value: ``0``.
118118
- **control_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the control packet. Can help with some newer models of ACs that use bigger packets. The default value: ``10``.
119-
- **sensors_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the sensor packet of the status message. Can help with some models of ACs that have bigger sensor packet. The default value: ``22``, minimum value: ``18``.
120-
- **control_method** (*Optional*, list): (supported only by hOn) Defines control method (should be supported by AC). Supported values: ``MONITOR_ONLY`` - no control, just monitor status, ``SET_GROUP_PARAMETERS`` - set all AC parameters with one command (default method), ``SET_SINGLE_PARAMETER`` - set each parameter individually (this method is supported by some new ceiling ACs like AD71S2SM3FA)
121-
- **display** (*Optional*, boolean): Can be used to set the AC display off.
119+
- **sensors_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the sensor packet of the status message. Can help with some models of ACs that have bigger sensor packet. The default value: ``22``, minimum value: ``18``.
120+
- **control_method** (*Optional*, list): (supported only by hOn) Defines control method (should be supported by AC). Supported values: ``MONITOR_ONLY`` - no control, just monitor status, ``SET_GROUP_PARAMETERS`` - set all AC parameters with one command (default method), ``SET_SINGLE_PARAMETER`` - set each parameter individually (this method is supported by some new ceiling ACs like AD71S2SM3FA)
121+
- **hvac_action** (*Optional*, boolean): (supported only by hOn) If ``true`` - expose the current HVAC action.
122+
- **display** (*Optional*, boolean): Can be used to set the AC display off.
122123
- **beeper** (*Optional*, boolean): Can be used to disable beeping on commands from AC. Supported only by hOn protocol.
123124
- **supported_modes** (*Optional*, list): Can be used to disable some of AC modes. Possible values: ``'OFF'``, ``HEAT_COOL``, ``COOL``, ``HEAT``, ``DRY``, ``FAN_ONLY``.
124125
- **supported_swing_modes** (*Optional*, list): Can be used to disable some swing modes if your AC does not support it. Possible values: ``'OFF'``, ``VERTICAL``, ``HORIZONTAL``, ``BOTH``.

components/haier/climate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
CONF_CONTROL_METHOD = "control_method"
4747
CONF_CONTROL_PACKET_SIZE = "control_packet_size"
4848
CONF_HORIZONTAL_AIRFLOW = "horizontal_airflow"
49+
CONF_HVAC_ACTION = "hvac_action"
4950
CONF_ON_ALARM_START = "on_alarm_start"
5051
CONF_ON_ALARM_END = "on_alarm_end"
5152
CONF_ON_STATUS_MESSAGE = "on_status_message"
@@ -231,6 +232,7 @@ def _base_config_schema(class_: MockObjClass) -> cv.Schema:
231232
CONF_STATUS_MESSAGE_HEADER_SIZE,
232233
default=PROTOCOL_STATUS_MESSAGE_HEADER_SIZE,
233234
): cv.int_range(min=PROTOCOL_STATUS_MESSAGE_HEADER_SIZE),
235+
cv.Optional(CONF_HVAC_ACTION, default=False): cv.boolean,
234236
cv.Optional(
235237
CONF_SUPPORTED_PRESETS,
236238
default=["BOOST", "SLEEP"], # No AWAY by default
@@ -483,6 +485,8 @@ async def to_code(config):
483485
cg.add(var.set_send_wifi(config[CONF_WIFI_SIGNAL]))
484486
if CONF_CONTROL_METHOD in config:
485487
cg.add(var.set_control_method(config[CONF_CONTROL_METHOD]))
488+
if CONF_HVAC_ACTION in config:
489+
cg.add(var.set_hvac_action(config[CONF_HVAC_ACTION]))
486490
if CONF_BEEPER in config:
487491
cg.add(var.set_beeper_state(config[CONF_BEEPER]))
488492
if CONF_DISPLAY in config:

components/haier/hon_climate.cpp

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ HonClimate::HonClimate()
5858

5959
HonClimate::~HonClimate() {}
6060

61+
void HonClimate::set_hvac_action(bool state) {
62+
this->hvac_action_enabled_ = state;
63+
if (state) {
64+
this->traits_.add_feature_flags(climate::CLIMATE_SUPPORTS_ACTION);
65+
}
66+
}
67+
6168
void HonClimate::set_beeper_state(bool state) {
6269
if (state != this->settings_.beeper_state) {
6370
this->settings_.beeper_state = state;
@@ -970,6 +977,52 @@ void HonClimate::update_horizontal_airflow_select_state_() {
970977
}
971978
#endif // USE_SELECT
972979

980+
bool HonClimate::update_hvac_action_(const hon_protocol::HaierPacketBigData *bd_packet) {
981+
if ((this->mode != CLIMATE_MODE_OFF) && (bd_packet == nullptr)) {
982+
return false;
983+
}
984+
985+
ClimateAction new_action = CLIMATE_ACTION_OFF;
986+
if ((this->mode != CLIMATE_MODE_OFF) && (bd_packet->compressor_status < 2)) {
987+
const bool compressor_on = bd_packet->compressor_status == 1;
988+
989+
switch (this->mode) {
990+
case CLIMATE_MODE_COOL:
991+
new_action = compressor_on ? CLIMATE_ACTION_COOLING : CLIMATE_ACTION_IDLE;
992+
break;
993+
case CLIMATE_MODE_DRY:
994+
new_action = compressor_on ? CLIMATE_ACTION_DRYING : CLIMATE_ACTION_IDLE;
995+
break;
996+
case CLIMATE_MODE_HEAT:
997+
new_action = (bd_packet->defrost_status == 1) ? CLIMATE_ACTION_DEFROSTING
998+
: (compressor_on ? CLIMATE_ACTION_HEATING : CLIMATE_ACTION_IDLE);
999+
break;
1000+
case CLIMATE_MODE_FAN_ONLY:
1001+
new_action = CLIMATE_ACTION_FAN;
1002+
break;
1003+
case CLIMATE_MODE_HEAT_COOL:
1004+
if (bd_packet->defrost_status == 1) {
1005+
new_action = CLIMATE_ACTION_DEFROSTING;
1006+
} else if (!compressor_on) {
1007+
new_action = CLIMATE_ACTION_IDLE;
1008+
} else if (bd_packet->indoor_coil_temperature == 0xFF) {
1009+
new_action = CLIMATE_ACTION_OFF;
1010+
} else {
1011+
float indoor_coil_temperature = bd_packet->indoor_coil_temperature / 2.0f - 20.0f;
1012+
new_action =
1013+
(this->current_temperature > indoor_coil_temperature) ? CLIMATE_ACTION_COOLING : CLIMATE_ACTION_HEATING;
1014+
}
1015+
break;
1016+
default:
1017+
break;
1018+
}
1019+
}
1020+
1021+
bool changed = this->action != new_action;
1022+
this->action = new_action;
1023+
return changed;
1024+
}
1025+
9731026
haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *packet_buffer, uint8_t size) {
9741027
size_t expected_size =
9751028
2 + this->status_message_header_size_ + this->real_control_packet_size_ + this->real_sensors_packet_size_;
@@ -978,10 +1031,10 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
9781031
return haier_protocol::HandlerError::WRONG_MESSAGE_STRUCTURE;
9791032
}
9801033
uint16_t subtype = (((uint16_t) packet_buffer[0]) << 8) + packet_buffer[1];
1034+
const hon_protocol::HaierPacketBigData *bd_packet = nullptr;
9811035
if ((subtype == 0x7D01) && (size >= expected_size + sizeof(hon_protocol::HaierPacketBigData))) {
9821036
// Got BigData packet
983-
const hon_protocol::HaierPacketBigData *bd_packet =
984-
(const hon_protocol::HaierPacketBigData *) (&packet_buffer[expected_size]);
1037+
bd_packet = (const hon_protocol::HaierPacketBigData *) (&packet_buffer[expected_size]);
9851038
#ifdef USE_SENSOR
9861039
this->update_sub_sensor_(SubSensorType::INDOOR_COIL_TEMPERATURE, bd_packet->indoor_coil_temperature / 2.0 - 20);
9871040
this->update_sub_sensor_(SubSensorType::OUTDOOR_COIL_TEMPERATURE, bd_packet->outdoor_coil_temperature - 64);
@@ -1161,6 +1214,9 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
11611214
}
11621215
should_publish = should_publish || (old_mode != this->mode);
11631216
}
1217+
if (this->hvac_action_enabled_) {
1218+
should_publish = this->update_hvac_action_(bd_packet) || should_publish;
1219+
}
11641220
{
11651221
// Quiet mode, should be after climate mode
11661222
if ((this->mode != CLIMATE_MODE_FAN_ONLY) && (this->mode != CLIMATE_MODE_OFF) &&
@@ -1561,7 +1617,7 @@ void HonClimate::process_protocol_reset() {
15611617
}
15621618

15631619
bool HonClimate::should_get_big_data_() {
1564-
if (this->big_data_sensors_ > 0) {
1620+
if ((this->big_data_sensors_ > 0) || this->hvac_action_enabled_) {
15651621
this->big_data_counter_ = (this->big_data_counter_ + 1) % 3;
15661622
return this->big_data_counter_ == 1;
15671623
}

components/haier/hon_climate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class HonClimate : public HaierClimateBase {
142142
void set_extra_sensors_packet_bytes_size(size_t size) { this->extra_sensors_packet_bytes_ = size; };
143143
void set_status_message_header_size(size_t size) { this->status_message_header_size_ = size; };
144144
void set_control_method(HonControlMethod method) { this->control_method_ = method; };
145+
void set_hvac_action(bool state);
145146
template<typename F> void add_alarm_start_callback(F &&callback) {
146147
this->alarm_start_callback_.add(std::forward<F>(callback));
147148
}
@@ -181,6 +182,7 @@ class HonClimate : public HaierClimateBase {
181182
// Helper functions
182183
haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
183184
void process_alarm_message_(const uint8_t *packet, uint8_t size, bool check_new);
185+
bool update_hvac_action_(const hon_protocol::HaierPacketBigData *bd_packet);
184186
void fill_control_messages_queue_();
185187
void clear_control_messages_queue_();
186188

@@ -212,6 +214,7 @@ class HonClimate : public HaierClimateBase {
212214
std::chrono::steady_clock::time_point last_alarm_request_;
213215
int big_data_sensors_{0};
214216
uint8_t big_data_counter_{0};
217+
bool hvac_action_enabled_{false};
215218
esphome::optional<hon_protocol::VerticalSwingMode> current_vertical_swing_{};
216219
esphome::optional<hon_protocol::HorizontalSwingMode> current_horizontal_swing_{};
217220
esphome::optional<std::chrono::steady_clock::time_point> vertical_direction_set_time_{};

docs/esphome-docs/climate/haier.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ Configuration variables:
116116
- **alternative_swing_control** (*Optional*, boolean): (supported by smartAir2 only) If ``true`` - use alternative values to control swing mode. Use only if the original control method is not working for your AC.
117117
- **status_message_header_size** (*Optional*, int): (supported only by hOn) Define the header size of the status message. Can be used to handle some protocol variations. Use only if you are sure what you are doing. The default value: ``0``.
118118
- **control_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the control packet. Can help with some newer models of ACs that use bigger packets. The default value: ``10``.
119-
- **sensors_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the sensor packet of the status message. Can help with some models of ACs that have bigger sensor packet. The default value: ``22``, minimum value: ``18``.
120-
- **control_method** (*Optional*, list): (supported only by hOn) Defines control method (should be supported by AC). Supported values: ``MONITOR_ONLY`` - no control, just monitor status, ``SET_GROUP_PARAMETERS`` - set all AC parameters with one command (default method), ``SET_SINGLE_PARAMETER`` - set each parameter individually (this method is supported by some new ceiling ACs like AD71S2SM3FA)
121-
- **display** (*Optional*, boolean): Can be used to set the AC display off.
119+
- **sensors_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the sensor packet of the status message. Can help with some models of ACs that have bigger sensor packet. The default value: ``22``, minimum value: ``18``.
120+
- **control_method** (*Optional*, list): (supported only by hOn) Defines control method (should be supported by AC). Supported values: ``MONITOR_ONLY`` - no control, just monitor status, ``SET_GROUP_PARAMETERS`` - set all AC parameters with one command (default method), ``SET_SINGLE_PARAMETER`` - set each parameter individually (this method is supported by some new ceiling ACs like AD71S2SM3FA)
121+
- **hvac_action** (*Optional*, boolean): (supported only by hOn) If ``true`` - expose the current HVAC action.
122+
- **display** (*Optional*, boolean): Can be used to set the AC display off.
122123
- **beeper** (*Optional*, boolean): Can be used to disable beeping on commands from AC. Supported only by hOn protocol.
123124
- **supported_modes** (*Optional*, list): Can be used to disable some of AC modes. Possible values: ``'OFF'``, ``HEAT_COOL``, ``COOL``, ``HEAT``, ``DRY``, ``FAN_ONLY``.
124125
- **supported_swing_modes** (*Optional*, list): Can be used to disable some swing modes if your AC does not support it. Possible values: ``'OFF'``, ``VERTICAL``, ``HORIZONTAL``, ``BOTH``.

docs/examples/climate_haier.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Configuration variables:
6969
- **control_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the control packet. Can help with some newer models of ACs that use bigger packets. The default value: ``10``.
7070
- **sensors_packet_size** (*Optional*, int): (supported only by hOn) Define the size of the sensor packet of the status message. Can help with some models of ACs that have bigger sensor packet. The default value: ``22``, minimum value: ``18``.
7171
- **control_method** (*Optional*, list): (supported only by hOn) Defines control method (should be supported by AC). Supported values: ``MONITOR_ONLY`` - no control, just monitor status, ``SET_GROUP_PARAMETERS`` - set all AC parameters with one command (default method), ``SET_SINGLE_PARAMETER`` - set each parameter individually (this method is supported by some new ceiling ACs like AD71S2SM3FA)
72+
- **hvac_action** (*Optional*, boolean): (supported only by hOn) If ``true`` - expose the current HVAC action.
7273
- **display** (*Optional*, boolean): Can be used to set the AC display off.
7374
- **beeper** (*Optional*, boolean): Can be used to disable beeping on commands from AC. Supported only by hOn protocol.
7475
- **supported_modes** (*Optional*, list): Can be used to disable some of AC modes. Possible values: ``'OFF'``, ``HEAT_COOL``, ``COOL``, ``HEAT``, ``DRY``, ``FAN_ONLY``.

0 commit comments

Comments
 (0)