132 lines
3.5 KiB
YAML
132 lines
3.5 KiB
YAML
#<<: !include secrets.yaml
|
|
esphome:
|
|
name: dewpointfan
|
|
|
|
esp32:
|
|
board: esp32doit-devkit-v1
|
|
framework:
|
|
type: arduino
|
|
|
|
# Enable logging
|
|
logger:
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
password: !secret ota_password
|
|
|
|
ota:
|
|
- platform: esphome
|
|
password: !secret ota_password
|
|
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: "Dewpoint Fan Fallback Hotspot"
|
|
password: !secret ota_password
|
|
|
|
mqtt:
|
|
id: mqtt_client
|
|
topic_prefix: dewpoint
|
|
discovery: false
|
|
broker: mqtt.fd
|
|
port: 1883
|
|
|
|
i2c:
|
|
sda: 21
|
|
scl: 22
|
|
|
|
display:
|
|
- platform: lcd_pcf8574
|
|
dimensions: 20x4
|
|
address: 0x27
|
|
update_interval: 10s
|
|
lambda: |-
|
|
it.printf(0, 0, "Fan: %s", id(fan_relay).state ? "ON" : "OFF");
|
|
it.printf(0, 1, "Temp I/O: %.1f/%.1f", id(inner_temperature).state, id(outer_temperature).state);
|
|
it.printf(0, 2, "Hum I/O: %.1f/%.1f", id(inner_humidity).state, id(outer_humidity).state);
|
|
it.printf(0, 3, "Dew I/O: %.1f/%.1f", id(inner_dew_point).state, id(outer_dew_point).state);
|
|
sensor:
|
|
- platform: dht
|
|
pin: 25
|
|
model: DHT22
|
|
temperature:
|
|
name: "Inner Temperature"
|
|
id: inner_temperature
|
|
humidity:
|
|
name: "Inner Humidity"
|
|
id: inner_humidity
|
|
update_interval: 10s
|
|
- platform: dht
|
|
pin: 26
|
|
model: DHT22
|
|
temperature:
|
|
name: "Outer Temperature"
|
|
id: outer_temperature
|
|
humidity:
|
|
name: "Outer Humidity"
|
|
id: outer_humidity
|
|
update_interval: 10s
|
|
- platform: template
|
|
name: "Inner Dew Point"
|
|
unit_of_measurement: °C
|
|
id: inner_dew_point
|
|
- platform: template
|
|
name: "Outer Dew Point"
|
|
unit_of_measurement: °C
|
|
id: outer_dew_point
|
|
- 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 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;
|
|
}
|
|
if (deltadp < 5.0) {
|
|
fan_state = 0;
|
|
}
|
|
if (id(inner_temperature).state < 10.0) {
|
|
fan_state = 0;
|
|
}
|
|
if (id(outer_temperature).state < -10.0) {
|
|
fan_state = 0;
|
|
}
|
|
if (fan_state == 1) {
|
|
id(fan_relay).turn_on();
|
|
} else {
|
|
id(fan_relay).turn_off();
|
|
}
|
|
id(mqtt_client).publish_json("sensor/dewpointfan", [=](JsonObject root) {
|
|
root["inner_temp"] = id(inner_temperature).state;
|
|
root["inner_humidity"] = id(inner_humidity).state;
|
|
root["outer_temp"] = id(outer_temperature).state;
|
|
root["outer_humidity"] = id(outer_humidity).state;
|
|
root["inner_dewpoint"] = inner_dewpoint;
|
|
root["outer_dewpoint"] = outer_dewpoint;
|
|
root["fan_state"] = id(fan_relay).state;
|
|
});
|
|
return fan_state;
|
|
unit_of_measurement: ""
|
|
update_interval: 30s
|
|
|
|
switch:
|
|
- platform: gpio
|
|
name: "Relay"
|
|
id: fan_relay
|
|
pin: 13
|
|
|
|
captive_portal:
|