From: David Woodhouse Date: Tue, 6 Aug 2024 08:46:33 +0000 (+0100) Subject: Use dimmer switch for hum threshold, harmonise bathroom and toilet X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fa802a33c14c478f1f375f552a6a69378a417ff4;p=users%2Fdwmw2%2Fesp32-pool.git Use dimmer switch for hum threshold, harmonise bathroom and toilet --- diff --git a/bathroom.yaml b/bathroom.yaml index c057ccf..a220b3b 100644 --- a/bathroom.yaml +++ b/bathroom.yaml @@ -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(); + case ${domo_thresh}: /* Humidity threshold */ + id(hum_threshold) = x["svalue1"].as(); 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 diff --git a/toilet.yaml b/toilet.yaml index 36d2b37..831be19 100644 --- a/toilet.yaml +++ b/toilet.yaml @@ -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(); + case ${domo_thresh}: /* Humidity threshold */ + id(hum_threshold) = x["svalue1"].as(); 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