From 9b1314a1e9749fd2430af2285d411cbb3dbe89e1 Mon Sep 17 00:00:00 2001 From: Malte Date: Fri, 3 Jan 2025 12:36:06 +0100 Subject: [PATCH] remove duplicate dewpoint calculation code --- dewpoint.yaml | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/dewpoint.yaml b/dewpoint.yaml index b3d29ed..a6cca42 100644 --- a/dewpoint.yaml +++ b/dewpoint.yaml @@ -71,35 +71,28 @@ sensor: update_interval: 10s - platform: template name: "Inner Dew Point" - lambda: |- - float A = 17.27; - float B = 237.7; - float temp = id(inner_temperature).state; - float humidity = id(inner_humidity).state; - float alpha = ((A * temp) / (B + temp)) + log(humidity / 100.0); - return (B * alpha) / (A - alpha); unit_of_measurement: °C id: inner_dew_point - update_interval: 30s - platform: template name: "Outer Dew Point" - lambda: |- - float A = 17.27; - float B = 237.7; - float temp = id(outer_temperature).state; - float humidity = id(outer_humidity).state; - float alpha = ((A * temp) / (B + temp)) + log(humidity / 100.0); - return (B * alpha) / (A - alpha); unit_of_measurement: °C id: outer_dew_point - update_interval: 30s - icon: "mdi:thermometer-water" - platform: template id: fan_state_temp name: "Fan state" lambda: |- + auto calc_dewpoint = [](float temp, float humidity) { + float A = 17.27; + float B = 237.7; + float alpha = ((A * temp) / (B + temp)) + log(humidity / 100.0); + return (B * alpha) / (A - alpha); + }; uint8_t fan_state = id(fan_state_temp).state; - float deltadp = id(inner_dew_point).state - id(outer_dew_point).state; + float inner_dewpoint = calc_dewpoint(id(inner_temperature).state, id(inner_humidity).state); + float outer_dewpoint = calc_dewpoint(id(outer_temperature).state, id(outer_humidity).state); + id(inner_dew_point).publish_state(inner_dewpoint); + id(outer_dew_point).publish_state(outer_dewpoint); + float deltadp = inner_dewpoint - outer_dewpoint; if (deltadp > 6.0) { fan_state = 1; } @@ -122,8 +115,8 @@ sensor: root["inner_humidity"] = id(inner_humidity).state; root["outer_temp"] = id(outer_temperature).state; root["outer_humidity"] = id(outer_humidity).state; - root["inner_dewpoint"] = id(inner_dew_point).state; - root["outer_dewpoint"] = id(outer_dew_point).state; + root["inner_dewpoint"] = inner_dewpoint; + root["outer_dewpoint"] = outer_dewpoint; root["fan_state"] = id(fan_relay).state; }); return fan_state;