Skip to content

Commit

Permalink
Re-read & publish states immediately after control commands
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbenner committed Jun 10, 2023
1 parent c5d5b3a commit 091c575
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/daikin_s21/climate/daikin_s21_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ float DaikinS21Climate::get_room_temp_offset() {
return s21_val - room_val;
}

float nearest_step(float temp) {
return std::round(temp / SETPOINT_STEP) * SETPOINT_STEP;
}

// What setpoint should be sent to s21, acconting for external room sensor.
float DaikinS21Climate::calc_s21_setpoint(float target) {
float offset_target = target + this->get_room_temp_offset();
return std::round(offset_target / SETPOINT_STEP) * SETPOINT_STEP;
return nearest_step(offset_target);
}

// How far from desired setpoint is the current S21 setpoint?
Expand Down Expand Up @@ -347,7 +351,8 @@ void DaikinS21Climate::control(const climate::ClimateCall &call) {
set_basic = true;
}
if (call.get_target_temperature().has_value()) {
this->target_temperature = call.get_target_temperature().value();
this->target_temperature =
nearest_step(call.get_target_temperature().value());
set_basic = true;
}
if (call.get_custom_fan_mode().has_value()) {
Expand All @@ -364,11 +369,18 @@ void DaikinS21Climate::control(const climate::ClimateCall &call) {
this->s21->set_swing_settings(this->e2d_swing_v(swing_mode),
this->e2d_swing_h(swing_mode));
}

this->update();
}

void DaikinS21Climate::set_s21_climate() {
this->expected_s21_setpoint =
this->calc_s21_setpoint(this->target_temperature);
ESP_LOGI(TAG, "Controlling S21 climate:");
ESP_LOGI(TAG, " Mode: %s", climate::climate_mode_to_string(this->mode));
ESP_LOGI(TAG, " Setpoint: %.1f (s21: %.1f)", this->target_temperature,
this->expected_s21_setpoint);
ESP_LOGI(TAG, " Fan: %s", this->custom_fan_mode.value().c_str());
this->s21->set_daikin_climate_settings(
this->mode != climate::CLIMATE_MODE_OFF,
this->e2d_climate_mode(this->mode), this->expected_s21_setpoint,
Expand Down
4 changes: 4 additions & 0 deletions components/daikin_s21/s21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ void DaikinS21::set_daikin_climate_settings(bool power_on,
ESP_LOGD(TAG, "Sending basic climate CMD (D1): %s", str_repr(cmd).c_str());
if (!this->send_cmd({'D', '1'}, cmd)) {
ESP_LOGW(TAG, "Failed basic climate CMD");
} else {
this->update();
}
}

Expand All @@ -426,6 +428,8 @@ void DaikinS21::set_swing_settings(bool swing_v, bool swing_h) {
ESP_LOGD(TAG, "Sending swing CMD (D5): %s", str_repr(cmd).c_str());
if (!this->send_cmd({'D', '5'}, cmd)) {
ESP_LOGW(TAG, "Failed swing CMD");
} else {
this->update();
}
}

Expand Down

0 comments on commit 091c575

Please sign in to comment.