From 4b3675168b699f6e52bd54ecde94c5b3aefdcaf9 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 08:11:19 -0400 Subject: [PATCH 1/6] Get running state from hp instead of computing --- espmhp.cpp | 59 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/espmhp.cpp b/espmhp.cpp index 5d256d1..b8ef552 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -142,7 +142,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { ESP_LOGV( "control", "Sending target temp: %.1f", *call.get_target_temperature() - ) + ); hp->setTemperature(*call.get_target_temperature()); this->target_temperature = *call.get_target_temperature(); updated = true; @@ -302,33 +302,6 @@ void MitsubishiHeatPump::hpSettingsChanged() { this->target_temperature = currentSettings.temperature; ESP_LOGI(TAG, "Target temp is: %f", this->target_temperature); - - /* - * Compute running state from mode & temperatures - */ - switch (this->mode) { - case climate::CLIMATE_MODE_HEAT: - 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: - 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; - } - /* * ******** Publish state back to ESPHome. ******** */ @@ -340,6 +313,36 @@ void MitsubishiHeatPump::hpSettingsChanged() { */ void MitsubishiHeatPump::hpStatusChanged(heatpumpStatus currentStatus) { this->current_temperature = currentStatus.roomTemperature; + switch (this->mode) { + case climate::CLIMATE_MODE_HEAT: + if (currentStatus.operating) { + this->action = climate::CLIMATE_ACTION_HEATING; + } + else { + this->action = climate::CLIMATE_ACTION_IDLE; + } + break; + case climate::CLIMATE_MODE_COOL: + if (currentStatus.operating) { + this->action = climate::CLIMATE_ACTION_COOLING; + } + else { + this->action = climate::CLIMATE_ACTION_IDLE; + } + break; + case climate::CLIMATE_MODE_DRY: + if (currentStatus.operating) { + this->action = climate::CLIMATE_ACTION_DRYING; + } + else { + this->action = climate::CLIMATE_ACTION_IDLE; + } + case climate::CLIMATE_MODE_FAN_ONLY: + this->action = climate::CLIMATE_ACTION_FAN; + default: + this->action = climate::CLIMATE_ACTION_OFF; + } + this->publish_state(); } From a36cb30a89dc41ca663e73bedfa799415984a16a Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 08:48:10 -0400 Subject: [PATCH 2/6] assume fan running when switching to fan mode --- espmhp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/espmhp.cpp b/espmhp.cpp index b8ef552..0f61188 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -128,6 +128,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { case climate::CLIMATE_MODE_FAN_ONLY: hp->setModeSetting("FAN"); hp->setPowerSetting("ON"); + this->action = climate::CLIMATE_ACTION_FAN; updated = true; break; case climate::CLIMATE_MODE_OFF: @@ -247,6 +248,7 @@ void MitsubishiHeatPump::hpSettingsChanged() { this->mode = climate::CLIMATE_MODE_FAN_ONLY; } else if (strcmp(currentSettings.mode, "AUTO") == 0) { this->mode = climate::CLIMATE_MODE_AUTO; + this->action = climate::CLIMATE_ACTION_FAN; } else { ESP_LOGW( TAG, From bf9259ce0a002d23384f524f4725bc18599d9f0c Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 08:54:39 -0400 Subject: [PATCH 3/6] off by one branch --- espmhp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espmhp.cpp b/espmhp.cpp index 0f61188..e4117cf 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -246,9 +246,9 @@ void MitsubishiHeatPump::hpSettingsChanged() { this->mode = climate::CLIMATE_MODE_COOL; } else if (strcmp(currentSettings.mode, "FAN") == 0) { this->mode = climate::CLIMATE_MODE_FAN_ONLY; + this->action = climate::CLIMATE_ACTION_FAN; } else if (strcmp(currentSettings.mode, "AUTO") == 0) { this->mode = climate::CLIMATE_MODE_AUTO; - this->action = climate::CLIMATE_ACTION_FAN; } else { ESP_LOGW( TAG, From 7e91b6bdae1038bf96faea36420df16c01679a87 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 09:17:40 -0400 Subject: [PATCH 4/6] Fix missing breaks and have slightly more optimism on mode changes --- espmhp.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/espmhp.cpp b/espmhp.cpp index e4117cf..23637f5 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -118,6 +118,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { case climate::CLIMATE_MODE_DRY: hp->setModeSetting("DRY"); hp->setPowerSetting("ON"); + this->action = climate::CLIMATE_ACTION_DRYING; updated = true; break; case climate::CLIMATE_MODE_AUTO: @@ -242,6 +243,7 @@ void MitsubishiHeatPump::hpSettingsChanged() { this->mode = climate::CLIMATE_MODE_HEAT; } else if (strcmp(currentSettings.mode, "DRY") == 0) { this->mode = climate::CLIMATE_MODE_DRY; + this->action = climate::CLIMATE_ACTION_DRYING; } else if (strcmp(currentSettings.mode, "COOL") == 0) { this->mode = climate::CLIMATE_MODE_COOL; } else if (strcmp(currentSettings.mode, "FAN") == 0) { @@ -334,13 +336,15 @@ void MitsubishiHeatPump::hpStatusChanged(heatpumpStatus currentStatus) { break; case climate::CLIMATE_MODE_DRY: if (currentStatus.operating) { - this->action = climate::CLIMATE_ACTION_DRYING; + this->action = climate::CLIMATE_ACTION_DRYING; } else { this->action = climate::CLIMATE_ACTION_IDLE; } + break; case climate::CLIMATE_MODE_FAN_ONLY: this->action = climate::CLIMATE_ACTION_FAN; + break; default: this->action = climate::CLIMATE_ACTION_OFF; } From 7a9ad8541421743dc3ed2816b37b142e0c9eb1c1 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 09:40:54 -0400 Subject: [PATCH 5/6] Naive auto mode action support --- espmhp.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/espmhp.cpp b/espmhp.cpp index 23637f5..f5fbc37 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -108,11 +108,13 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { case climate::CLIMATE_MODE_COOL: hp->setModeSetting("COOL"); hp->setPowerSetting("ON"); + this->action = climate::CLIMATE_ACTION_IDLE; updated = true; break; case climate::CLIMATE_MODE_HEAT: hp->setModeSetting("HEAT"); hp->setPowerSetting("ON"); + this->action = climate::CLIMATE_ACTION_IDLE; updated = true; break; case climate::CLIMATE_MODE_DRY: @@ -124,6 +126,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { case climate::CLIMATE_MODE_AUTO: hp->setModeSetting("AUTO"); hp->setPowerSetting("ON"); + this->action = climate::CLIMATE_ACTION_IDLE; updated = true; break; case climate::CLIMATE_MODE_FAN_ONLY: @@ -241,16 +244,19 @@ void MitsubishiHeatPump::hpSettingsChanged() { if (strcmp(currentSettings.power, "ON") == 0) { if (strcmp(currentSettings.mode, "HEAT") == 0) { this->mode = climate::CLIMATE_MODE_HEAT; + this->action = climate::CLIMATE_ACTION_IDLE; } else if (strcmp(currentSettings.mode, "DRY") == 0) { this->mode = climate::CLIMATE_MODE_DRY; this->action = climate::CLIMATE_ACTION_DRYING; } else if (strcmp(currentSettings.mode, "COOL") == 0) { this->mode = climate::CLIMATE_MODE_COOL; + this->action = climate::CLIMATE_ACTION_IDLE; } else if (strcmp(currentSettings.mode, "FAN") == 0) { this->mode = climate::CLIMATE_MODE_FAN_ONLY; this->action = climate::CLIMATE_ACTION_FAN; } else if (strcmp(currentSettings.mode, "AUTO") == 0) { this->mode = climate::CLIMATE_MODE_AUTO; + this->action = climate::CLIMATE_ACTION_IDLE; } else { ESP_LOGW( TAG, @@ -334,6 +340,16 @@ void MitsubishiHeatPump::hpStatusChanged(heatpumpStatus currentStatus) { this->action = climate::CLIMATE_ACTION_IDLE; } break; + case climate::CLIMATE_MODE_AUTO: + this->action = climate::CLIMATE_ACTION_IDLE; + if (currentStatus.operating) { + if (this->current_temperature > this->target_temperature) { + this->action = climate::CLIMATE_ACTION_COOLING; + } else if (this->current_temperature < this->target_temperature) { + this->action = climate::CLIMATE_ACTION_HEATING; + } + } + break; case climate::CLIMATE_MODE_DRY: if (currentStatus.operating) { this->action = climate::CLIMATE_ACTION_DRYING; From 41579d226cf5a93f2b66bb93ab52cd84d0f4e136 Mon Sep 17 00:00:00 2001 From: Phil Genera Date: Sat, 6 Jun 2020 11:41:28 -0400 Subject: [PATCH 6/6] Also be optimistic when turning off --- espmhp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/espmhp.cpp b/espmhp.cpp index f5fbc37..b46f9ea 100644 --- a/espmhp.cpp +++ b/espmhp.cpp @@ -138,6 +138,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) { case climate::CLIMATE_MODE_OFF: default: hp->setPowerSetting("OFF"); + this->action = climate::CLIMATE_ACTION_OFF; updated = true; break; } @@ -266,6 +267,7 @@ void MitsubishiHeatPump::hpSettingsChanged() { } } else { this->mode = climate::CLIMATE_MODE_OFF; + this->action = climate::CLIMATE_ACTION_OFF; } ESP_LOGI(TAG, "Climate mode is: %i", this->mode);