]> www.infradead.org Git - users/dwmw2/esp32-pool.git/commitdiff
Turn off UFH when no valid temperature readings to avoid overheating
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 8 Dec 2024 16:46:39 +0000 (16:46 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 8 Dec 2024 16:46:39 +0000 (16:46 +0000)
And bump the minimum to 8°C because the kitchen unit seems to be reporting
6.95°C even while the NTC isn't connected yet.

ufh.yaml

index 9f456d5b01ec4240efc90ed02288b9c24082a2c4..035d3ea37996c2279c650a893374702dd60f055c 100644 (file)
--- a/ufh.yaml
+++ b/ufh.yaml
 # turn on GPIO25, trigger *three* readings a second apart, and turn GPIO25 off
 # again. The ADC sensor has a filter to average the three readings.
 
+esphome:
+  includes:
+    - chrono.h
+
+globals:
+  - id: last_valid_temp
+    type: long long
+    restore_value: no
+
 script:
   - id: mqtt_connect_domo
     then:
@@ -74,6 +83,27 @@ script:
         call.set_target_temperature(target_temp);
         call.perform();
 
+time:
+  - platform: sntp
+    on_time:
+      - seconds: 0
+        minutes: /1
+        then:
+          lambda: |-
+            long long now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
+            if (!id(last_valid_temp)) {
+              id(last_valid_temp) = now;
+              return;
+            }
+            // No valid readings for ten minutes? Turn heat off!
+            if (now > id(last_valid_temp) + 600) {
+              ESP_LOGI("ufh", "No valid temperature readings! Turning heating off");
+              auto call = id(ntc_climate).make_call();
+              call.set_mode("OFF");
+              call.perform();
+              id(ufh_relay).turn_off();
+            }
+
 mqtt:
   on_connect:
     then:
@@ -141,14 +171,16 @@ sensor:
           send_every: 1
           send_first_at: 1
       - clamp:
-          min_value: 5
+          min_value: 8
           max_value: 35
           ignore_out_of_range: true
     on_value:
       then:
         lambda: |-
-          if (!isnan(x))
+          if (!isnan(x)) {
             id(tell_domo_svalue)->execute(${domo_temp}, std::to_string(x));
+            id(last_valid_temp) = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
+          }
 
   - platform: resistance
     id: ntc_resistance