Turn on at estimated time instead of actually ramping up
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 8 Dec 2024 16:13:11 +0000 (16:13 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 8 Dec 2024 16:13:16 +0000 (16:13 +0000)
This should cause fewer switches on the relay.

bathroomfloor.yaml
ufh.yaml

index cc03b2a8e7297aa6322e28e20076f103c3788c29..f8cde1d58b55008e5fa16769cc002b90961971cc 100644 (file)
@@ -73,14 +73,14 @@ time:
     on_time:
         # Ramp up to 21°C by 06:30
       - seconds: 0
-        minutes: /5
+        minutes: /1
         hours: 4,5,6
         then:
           script.execute:
             id: ramp_up
             target_temp: 21.0
             heat_rate: 0.08
-            target_time: 385 # 06:30 - 5 minutes
+            target_time: 390 # 06:30
 
         # Off (15°C) at 09:30 on weekdays
       - seconds: 0
@@ -90,7 +90,6 @@ time:
         then:
           climate.control:
             id: ntc_climate
-            mode: HEAT
             target_temperature: 15°C
 
         # Off (15°C) at 11:00 on weekends
@@ -101,28 +100,26 @@ time:
         then:
           climate.control:
             id: ntc_climate
-            mode: HEAT
             target_temperature: 15°C
 
         # Ramp up to 21°C by 8pm
       - seconds: 0
-        minutes: /5
+        minutes: /1
         hours: 18,19
         then:
           script.execute:
             id: ramp_up
             target_temp: 21.0
             heat_rate: 0.08
-            target_time: 1195 # 20:00 - 5 minutes
+            target_time: 1200 # 20:00
 
-        # Off (15°C) at pm.
+        # Off (15°C) at 9pm.
       - seconds: 0
         minutes: 0
         hours: 21
         then:
           climate.control:
             id: ntc_climate
-            mode: HEAT
             target_temperature: 15°C
 
 sensor:
index ed60188e1bb2bda306600a1b30779b940472d1c8..9f456d5b01ec4240efc90ed02288b9c24082a2c4 100644 (file)
--- a/ufh.yaml
+++ b/ufh.yaml
@@ -46,26 +46,32 @@ script:
       heat_rate: float # °C/min
     then:
       lambda: |-
+        if (id(ntc_climate).target_temperature == target_temp)
+          return;
+
         auto t = id(sntp_time).now();
         if (!t.is_valid())
           return;
 
         int now_mins = (t.hour * 60) + t.minute;
-        int mins_till_target = target_time - now_mins;
-
-        // Set the target for the *end* of the five-min adjustment window
-        mins_till_target -= 5;
-
-        if (mins_till_target < -4)
-          return; // Already got there.
-
-        float temp = target_temp - (heat_rate * mins_till_target);
-        if (temp < 15)
-          return;
-
+        int time_left = target_time - now_mins;
+        // Should we turn on early?
+        if (time_left > 0) {
+          float current_temp = id(ntc_temperature).state;
+          if (isnan(current_temp))
+            return;
+
+          float temp_delta = target_temp - current_temp;
+          int time_needed = temp_delta / heat_rate;
+          ESP_LOGD("ufh", "Need %d minutes to get to target, have %d",
+                          time_needed, time_left);
+          if (time_needed < time_left)
+            return;
+        }
+
+        // The time has come to turn the the UFH on.
         auto call = id(ntc_climate).make_call();
-        call.set_mode("HEAT");
-        call.set_target_temperature(temp);
+        call.set_target_temperature(target_temp);
         call.perform();
 
 mqtt: