remove duplicate dewpoint calculation code

This commit is contained in:
Malte 2025-01-03 12:36:06 +01:00
parent e6df71f10b
commit 9b1314a1e9

View file

@ -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;