]> www.infradead.org Git - users/dwmw2/esp32-pool.git/commitdiff
Use dimmer switch for hum threshold, harmonise bathroom and toilet
authorDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 6 Aug 2024 08:46:33 +0000 (09:46 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 6 Aug 2024 08:46:33 +0000 (09:46 +0100)
bathroom.yaml
toilet.yaml

index c057ccfa1d6358bf2e6d6eb91f3122159db2a2a3..a220b3b100ea8003a5c0af11a5c257835b2ebae0 100644 (file)
@@ -5,6 +5,12 @@
 # GPIO16: Onboard relay (bathroom fan)
 # GPIO13: DHT22
 
+substitutions:
+  domo_fan: "522"
+  domo_hum: "520"
+  domo_temp: "521"
+  domo_thresh: "902"
+
 esphome:
   name: bathroom
 
@@ -139,8 +145,8 @@ mqtt:
       - light.turn_on: blue_led
       - delay: 2s # Too soon and the first messages don't get through!
       - lambda: |-
-         id(tell_domo_nvalue)->execute(522, id(fan_relay).state);
-         id(tell_domo_svalue)->execute(523, std::to_string(id(hum_threshold)));
+         id(tell_domo_nvalue)->execute(${domo_fan}, id(fan_relay).state);
+         id(tell_domo_nsvalues)->execute(${domo_thresh}, 2, std::to_string(id(hum_threshold)));
 
   on_disconnect:
     then:
@@ -155,7 +161,7 @@ mqtt:
 
             // ESP_LOGD("on_json_message", x["name"]);
             switch (idx) {
-               case 522: /* Fan relay */
+               case ${domo_fan}: /* Fan relay */
                   if (nvalue) {
                     id(fan_relay).turn_on();
                     id(relay_off_time) = ::time(NULL) + id(fan_delay);
@@ -164,8 +170,8 @@ mqtt:
                   }
                   break;
 
-                case 523: /* Humidity threshold */
-                  id(hum_threshold) = x["svalue"].as<float>();
+                case ${domo_thresh}: /* Humidity threshold */
+                  id(hum_threshold) = x["svalue1"].as<float>();
                   ESP_LOGD("mqtt", "Got hum_threshold %f", id(hum_threshold));
                   break;
             }
@@ -190,12 +196,12 @@ switch:
     on_turn_on:
       then:
         - lambda: |-
-            id(tell_domo_nvalue)->execute(522, 1);
+            id(tell_domo_nvalue)->execute(${domo_fan}, 1);
             id(relay_off_time) = 0;
     on_turn_off:
       then:
         - lambda: |-
-            id(tell_domo_nvalue)->execute(522, 0);
+            id(tell_domo_nvalue)->execute(${domo_fan}, 0);
             id(relay_off_time) = 0;
 
 sensor:
@@ -208,7 +214,7 @@ sensor:
         then:
           lambda: |-
             if (!isnan(x))
-              id(tell_domo_svalue)->execute(521, std::to_string(x));
+              id(tell_domo_svalue)->execute(${domo_temp}, std::to_string(x));
     humidity:
       name: "Bathroom Humidity"
       on_value:
@@ -223,5 +229,5 @@ sensor:
               hum_stat = "2"; // Dry
             }
             if (!isnan(x))
-              id(tell_domo_nsvalues)->execute(520, x, hum_stat);
+              id(tell_domo_nsvalues)->execute(${domo_hum}, x, hum_stat);
     update_interval: 10s
index 36d2b373372e4d51a7356370c3796131abc482d6..831be1955d304e8ac541f66678856436342695b8 100644 (file)
@@ -5,6 +5,12 @@
 # GPIO16: Onboard relay (toilet fan)
 # GPIO13: DHT22
 
+substitutions:
+  domo_fan: "900"
+  domo_hum: "898"
+  domo_temp: "899"
+  domo_thresh: "901"
+
 esphome:
   name: toilet
 
@@ -139,8 +145,8 @@ mqtt:
       - light.turn_on: blue_led
       - delay: 2s # Too soon and the first messages don't get through!
       - lambda: |-
-         id(tell_domo_nvalue)->execute(900, id(fan_relay).state);
-         id(tell_domo_svalue)->execute(901, std::to_string(id(hum_threshold)));
+         id(tell_domo_nvalue)->execute(${domo_fan}, id(fan_relay).state);
+         id(tell_domo_nsvalues)->execute(${domo_thresh}, 2, std::to_string(id(hum_threshold)));
 
   on_disconnect:
     then:
@@ -155,7 +161,7 @@ mqtt:
 
             // ESP_LOGD("on_json_message", x["name"]);
             switch (idx) {
-               case 900: /* Fan relay */
+               case ${domo_fan}: /* Fan relay */
                   if (nvalue) {
                     id(fan_relay).turn_on();
                     id(relay_off_time) = ::time(NULL) + id(fan_delay);
@@ -164,8 +170,8 @@ mqtt:
                   }
                   break;
 
-                case 901: /* Humidity threshold */
-                  id(hum_threshold) = x["svalue"].as<float>();
+                case ${domo_thresh}: /* Humidity threshold */
+                  id(hum_threshold) = x["svalue1"].as<float>();
                   ESP_LOGD("mqtt", "Got hum_threshold %f", id(hum_threshold));
                   break;
             }
@@ -190,12 +196,12 @@ switch:
     on_turn_on:
       then:
         - lambda: |-
-            id(tell_domo_nvalue)->execute(900, 1);
+            id(tell_domo_nvalue)->execute(${domo_fan}, 1);
             id(relay_off_time) = 0;
     on_turn_off:
       then:
         - lambda: |-
-            id(tell_domo_nvalue)->execute(900, 0);
+            id(tell_domo_nvalue)->execute(${domo_fan}, 0);
             id(relay_off_time) = 0;
 
 sensor:
@@ -208,7 +214,7 @@ sensor:
         then:
           lambda: |-
             if (!isnan(x))
-              id(tell_domo_svalue)->execute(899, std::to_string(x));
+              id(tell_domo_svalue)->execute(${domo_temp}, std::to_string(x));
     humidity:
       name: "Toilet Humidity"
       on_value:
@@ -223,5 +229,5 @@ sensor:
               hum_stat = "2"; // Dry
             }
             if (!isnan(x))
-              id(tell_domo_nsvalues)->execute(898, x, hum_stat);
+              id(tell_domo_nsvalues)->execute(${domo_hum}, x, hum_stat);
     update_interval: 10s