From: David Woodhouse <dwmw@amazon.co.uk>
Date: Fri, 18 Oct 2024 20:41:58 +0000 (+0100)
Subject: Avoid rewriting flow temp
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a5c84b2bdb0b0c70b2be1f81e8ff263a879f875c;p=users%2Fdwmw2%2Fesp32-pool.git

Avoid rewriting flow temp
---

diff --git a/heishamon.yaml b/heishamon.yaml
index 78a10fd..306aca8 100644
--- a/heishamon.yaml
+++ b/heishamon.yaml
@@ -435,8 +435,11 @@ globals:
   - id: target_flow_temp
     type: float
     restore_value: no
+  - id: last_set_flow_temp
+    type: float
+    restore_value: no
 
-# Don't make the flow temp jump up too quickly. Only let it get 2°C higher than the
+# Don't make the flow temp jump up too quickly. Only let it get 3°C higher than the
 # actual flow temp, to avoid firing up both heat pumps if the heat demand from the
 # house isn't smooth enough.
 script:
@@ -448,10 +451,22 @@ script:
          if (!set_next || !id(auto_flow_temp).state)
            return;
          float cur_flow_temp = id(hp_feed_temp).state;
-         if (set_next > cur_flow_temp + 2.0)
-           set_next = cur_flow_temp + 2.0;
-         ESP_LOGI("Evohome", "Flow temp set to %f °C (want %f °C)", set_next, id(target_flow_temp));
-         id(ecodan_instance).set_flow_target_temperature(set_next, esphome::ecodan::SetZone::ZONE_1);
+         if (set_next > cur_flow_temp + 3.0) {
+           set_next = cur_flow_temp + 3.0;
+           // Always ratchet it up, don't let it go down if the actual flow temp does.
+           if (set_next < id(last_set_flow_temp))
+             set_next = id(last_set_flow_temp);
+           // But not above the target.
+           if (set_next > id(target_flow_temp))
+             set_next = id(target_flow_temp);
+         }
+         if (set_next == id(last_set_flow_temp)) {
+           ESP_LOGI("Evohome", "Flow temp already set to %f °C (cur %f °C, want %f °C)", set_next, cur_flow_temp, id(target_flow_temp));
+         } else {
+           ESP_LOGI("Evohome", "Flow temp set to %f °C (cur %f °C, want %f °C)", set_next, cur_flow_temp, id(target_flow_temp));
+           id(ecodan_instance).set_flow_target_temperature(set_next, esphome::ecodan::SetZone::ZONE_1);
+           id(last_set_flow_temp) = set_next;
+         }
 
 # relay
 switch:
@@ -500,5 +515,5 @@ interval:
   - interval: 30s
     then:
     - lambda: |-
-        if (id(target_flow_temp) && id(auto_flow_temp).state)
+        if (id(auto_flow_temp).state && id(target_flow_temp) && id(target_flow_temp) != id(last_set_flow_temp))
            id(adjust_flow_temp).execute();