From 198dc5c05299245ab09a399173ef7ccc501db0b6 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Fri, 29 May 2020 21:46:32 -0400 Subject: [PATCH 1/7] Optimistically report the newly set values when receiving an update, and support the simple kinda of ClimateActions. --- espmhp.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/espmhp.cpp b/espmhp.cpp index b33336f..ed90109 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -102,6 +102,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { bool updated = false; if (call.get_mode().has_value()){ + this->mode = *call.get_mode(); switch (*call.get_mode()) { case climate::CLIMATE_MODE_COOL: hp->setModeSetting("COOL"); @@ -142,13 +143,14 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { *call.get_target_temperature() ) hp->setTemperature(*call.get_target_temperature()); + this->target_temperature = *call.get_target_temperature(); updated = true; } //const char* FAN_MAP[6] = {"AUTO", "QUIET", "1", "2", "3", "4"}; if (call.get_fan_mode().has_value()) { ESP_LOGV("control", "Requested fan mode is %s", *call.get_fan_mode()); - + this->fan_mode = *call.get_fan_mode(); switch(*call.get_fan_mode()) { case climate::CLIMATE_FAN_OFF: hp->setPowerSetting("OFF"); @@ -188,6 +190,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { ESP_LOGV(TAG, "control - requested swing mode is %s", *call.get_swing_mode()); + this->swing_mode = *call.get_swing_mode(); switch(*call.get_swing_mode()) { case climate::CLIMATE_SWING_OFF: hp->setVaneSetting("AUTO"); @@ -203,6 +206,9 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { } } ESP_LOGD(TAG, "control - Was HeatPump updated? %s", YESNO(updated)); + // send the update back to esphome: + this->publish_state(); + // and the heat pump: hp->update(); } @@ -295,6 +301,20 @@ void MitsubishiHeatPump::hpSettingsChanged() { ESP_LOGI(TAG, "Target temp is: %f", this->target_temperature); + /* + * Compute running state from mode & temperatures + */ + this->action = climate::CLIMATE_ACTION_OFF; + if (this->mode == climate::CLIMATE_MODE_HEAT) { + if (this->current_temperature < this->target_temperature) { + this->action = climate::CLIMATE_ACTION_HEATING; + } + } else if(this->mode == climate::CLIMATE_MODE_COOL) { + if (this->current_temperature > this->target_temperature) { + this->action = climate::CLIMATE_ACTION_COOLING; + } + } + /* * ******** Publish state back to ESPHome. ******** */ From 3b66056d75c493f2119d60150a499c100f52e9b6 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 30 May 2020 20:26:07 -0400 Subject: [PATCH 2/7] Rewrite to something a bit more compact --- espmhp.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/espmhp.cpp b/espmhp.cpp index ed90109..100e06d 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -206,6 +206,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { } } ESP_LOGD(TAG, "control - Was HeatPump updated? %s", YESNO(updated)); + // send the update back to esphome: this->publish_state(); // and the heat pump: @@ -305,14 +306,18 @@ void MitsubishiHeatPump::hpSettingsChanged() { * Compute running state from mode & temperatures */ this->action = climate::CLIMATE_ACTION_OFF; - if (this->mode == climate::CLIMATE_MODE_HEAT) { - if (this->current_temperature < this->target_temperature) { - this->action = climate::CLIMATE_ACTION_HEATING; - } - } else if(this->mode == climate::CLIMATE_MODE_COOL) { - if (this->current_temperature > this->target_temperature) { - this->action = climate::CLIMATE_ACTION_COOLING; - } + switch (this->mode) { + case climate::CLIMATE_MODE_HEAT: + if (this->current_temperature < this->target_temperature) { + this->action = climate::CLIMATE_ACTION_HEATING; + } + break; + case climate::CLIMATE_MODE_COOL: + case climate::CLIMATE_MODE_DRY: + if (this->current_temperature > this->target_temperature) { + this->action = climate::CLIMATE_ACTION_COOLING; + } + break; } /* From 4102ff48cc116a57897f88a1c735e1b9cf8b329b Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sun, 31 May 2020 20:00:11 -0400 Subject: [PATCH 3/7] Correct compiler warning, try harder to match upstream formatting style --- espmhp.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/espmhp.cpp b/espmhp.cpp index 100e06d..ea84464 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -305,19 +305,20 @@ void MitsubishiHeatPump::hpSettingsChanged() { /* * Compute running state from mode & temperatures */ - this->action = climate::CLIMATE_ACTION_OFF; switch (this->mode) { - case climate::CLIMATE_MODE_HEAT: - if (this->current_temperature < this->target_temperature) { - this->action = climate::CLIMATE_ACTION_HEATING; - } - break; - case climate::CLIMATE_MODE_COOL: - case climate::CLIMATE_MODE_DRY: - if (this->current_temperature > this->target_temperature) { - this->action = climate::CLIMATE_ACTION_COOLING; - } - break; + case climate::CLIMATE_MODE_HEAT: + if (this->current_temperature < this->target_temperature) { + this->action = climate::CLIMATE_ACTION_HEATING; + } + break; + case climate::CLIMATE_MODE_COOL: + case climate::CLIMATE_MODE_DRY: + if (this->current_temperature > this->target_temperature) { + this->action = climate::CLIMATE_ACTION_COOLING; + } + break; + default: + this->action = climate::CLIMATE_ACTION_OFF; } /* From a4f96c069aa2a81f684bcfc44f7b33302ee6cbaf Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sun, 31 May 2020 20:55:06 -0400 Subject: [PATCH 4/7] slightly more whitespace --- espmhp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espmhp.cpp b/espmhp.cpp index ea84464..94de0c3 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -317,8 +317,8 @@ void MitsubishiHeatPump::hpSettingsChanged() { this->action = climate::CLIMATE_ACTION_COOLING; } break; - default: - this->action = climate::CLIMATE_ACTION_OFF; + default: + this->action = climate::CLIMATE_ACTION_OFF; } /* From e1106eda77c37b76cf5eaf24d2956fbb57e23e7a Mon Sep 17 00:00:00 2001 From: Geoff Davis Date: Tue, 2 Jun 2020 20:30:53 -0700 Subject: [PATCH 5/7] Add "idle" states during heating and cooling. Dev version of esphome supports an idle state, so we'll take a guess at what the state is at a given point by comparing the set point. Note that this commit does not take into account hysteresis around the set point, and just assumes that if the temperature is at or over the set point during heating that the unit is idle, or if the temperature is at or under the setpoint during cooling that it's idle. --- espmhp.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/espmhp.cpp b/espmhp.cpp index 94de0c3..d30d704 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -310,13 +310,20 @@ void MitsubishiHeatPump::hpSettingsChanged() { if (this->current_temperature < this->target_temperature) { this->action = climate::CLIMATE_ACTION_HEATING; } + else { + this->action = climate::CLIMATE_ACTION_IDLE; + } break; case climate::CLIMATE_MODE_COOL: - case climate::CLIMATE_MODE_DRY: if (this->current_temperature > this->target_temperature) { this->action = climate::CLIMATE_ACTION_COOLING; } + else { + this->action = climate::CLIMATE_ACTION_IDLE; + } break; + case climate::CLIMATE_MODE_DRY: + this->action = climate::CLIMATE_ACTION_DRYING; default: this->action = climate::CLIMATE_ACTION_OFF; } From e819d5d26117def36f964a93451cc8d146b7dc3a Mon Sep 17 00:00:00 2001 From: Geoff Davis Date: Tue, 2 Jun 2020 20:37:10 -0700 Subject: [PATCH 6/7] Fix temperature step data type. Should be a float, not a uint8_t. --- espmhp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espmhp.h b/espmhp.h index ece2aa2..4390f2b 100644 --- a/espmhp.h +++ b/espmhp.h @@ -33,7 +33,7 @@ static const uint8_t ESPMHP_MIN_TEMPERATURE = 16; // degrees C, // defined by hardware static const uint8_t ESPMHP_MAX_TEMPERATURE = 31; // degrees C, //defined by hardware -static const uint8_t ESPMHP_TEMPERATURE_STEP = 0.5; // temperature setting step, +static const float ESPMHP_TEMPERATURE_STEP = 0.5; // temperature setting step, // in degrees C From b5b9836edab1776fedeb24af9b6215438188fd0c Mon Sep 17 00:00:00 2001 From: Geoff Davis Date: Tue, 2 Jun 2020 21:13:34 -0700 Subject: [PATCH 7/7] Add pgenera to authors --- espmhp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/espmhp.cpp b/espmhp.cpp index d30d704..5d256d1 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -4,7 +4,8 @@ * Implementation of esphome-mitsubishiheatpump * * Author: Geoff Davis. - * Date: 2020-03-11 + * Author: Phil Genera @pgenera on Github. + * Last Updated: 2020-06-02 * License: BSD * * Requirements: