]> www.infradead.org Git - users/dwmw2/esp32-pool.git/commitdiff
Force bypass valve open before turning pump on in the morning
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 8 May 2024 11:39:34 +0000 (12:39 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 8 May 2024 11:58:36 +0000 (12:58 +0100)
pool.yaml

index 71b1aa8941aca684943e2a93a7c6e40f6dbd270a..badd2781a7bc4e65398b285687244aed84711ecc 100644 (file)
--- a/pool.yaml
+++ b/pool.yaml
@@ -101,15 +101,15 @@ script:
             return;
         }
 
-        static time_t last_change = 0;
         time_t now = ::time(NULL);
 
-        if (now < last_change + 300) {
-            ESP_LOGD("control_valve", "Too soon to turn %s (%d seconds)", want_state ? "ON" : "OFF", now - last_change);
+        if (now < id(control_valve_last_change) + 300) {
+            ESP_LOGD("control_valve", "Too soon to turn %s (%d seconds)", want_state ? "ON" : "OFF",
+                     now - id(control_valve_last_change));
             return;
         }
 
-        last_change = now;
+        id(control_valve_last_change) = now;
         id(valve_output).toggle();
 
     # As soon as we know what the time is (and at 7am and 7pm), decide if the pump should be on.
@@ -170,6 +170,11 @@ globals:
     restore_value: no
     initial_value: '1'
 
+  - id: control_valve_last_change
+    type: time_t
+    restore_value: no
+    initial_value: '0'
+
 time:
   - platform: sntp
     id: sntp_time
@@ -214,6 +219,27 @@ time:
           script.execute:
             id: pump_default
             force: true
+
+        # Before turning the pump on in the morning, both 'solar in'
+        # both 'solar in' and 'solar out' sensors will be reading the
+        # ambient temperature, as no water is flowing. So open the
+        # bypass valve (pump directly back to pool) and set the
+        # control_valve_last_change time so that the temperature logic
+        # in the control_valve script won't close it again for at
+        # least five minutes. By which time the 'solar in' sensor
+        # should be giving *water* temperature, so we won't close the
+        # valve until the roof genuinely is warmer than the
+        # water. This means we don't use the pool water to heat up the
+        # rubber and plastic sitting on the roof; let the *sun* do
+        # that first!
+      - seconds: 0
+        minutes: 59
+        hours: 6
+        then:
+          lambda: |-
+             id(control_valve_last_change) = ::time(NULL);
+             id(valve_output).turn_off();
+
     on_time_sync:
       then:
         script.execute: