Add ventilate house toggle to fans.

This commit is contained in:
2022-01-21 08:07:22 -08:00
parent 8f6b651b83
commit 670cf98fdc
3 changed files with 104 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ substitutions:
duct_fan_pwmfreq: 5000Hz
duct_fan_off_spd: "0.0"
duct_fan_lo_spd: "1.0"
duct_fan_vent_spd: "50.0"
duct_fan_hi_spd: "100.0"
prjpwr_pin: GPIO19
prjpwr_name: Prj3 Pwr
@@ -26,6 +27,9 @@ globals:
- id: duct_fan_lo_spd
type: float
initial_value: ${duct_fan_lo_spd}
- id: duct_fan_vent_spd
type: float
initial_value: ${duct_fan_vent_spd}
- id: duct_fan_hi_spd
type: float
initial_value: ${duct_fan_hi_spd}
@@ -98,6 +102,16 @@ sensor:
name: ${dallas_out_name}
id: dallas_out_id
binary_sensor:
- platform: gpio
pin: ${prjpwr_pin}
name: ${prjpwr_name}
device_class: power
- platform: homeassistant
name: "Ventilate House"
entity_id: input_boolean.ventilate_house
id: ventilate_house
number:
- platform: template
id: duct_fan_target_spd_in
@@ -120,6 +134,7 @@ number:
float curtemp;
float off_spd;
float lo_spd;
float vent_spd;
float hi_spd;
float newspd;
lo_temp = id(thermostat_prj_id).target_temperature_low;
@@ -127,18 +142,37 @@ number:
curtemp = id(dallas_prj_id).state;
off_spd = id(duct_fan_off_spd);
lo_spd = id(duct_fan_lo_spd);
vent_spd = id(duct_fan_vent_spd);
hi_spd = id(duct_fan_hi_spd);
if ((curtemp < lo_temp) || (id(thermostat_on_id).state == false)) {
ESP_LOGD("fan_speed", "DEBUG Ventilate House: %d", id(ventilate_house).state);
ESP_LOGD("fan_speed", "DEBUG Current Temp: %f", curtemp);
ESP_LOGD("fan_speed", "DEBUG Thermostat State: %d", id(thermostat_on_id).state);
if ((id(ventilate_house).state == false) &&
((curtemp < lo_temp) || (id(thermostat_on_id).state == false))) {
ESP_LOGD("fan_speed", "DEBUG turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
if (curtemp > hi_temp) {
ESP_LOGD("fan_speed", "DEBUG curtemp > hi_temp");
newspd = hi_spd;
} else {
// Set newspd to same linear proportion of spd range as current temp is of temp range
newspd = lo_spd + ((hi_spd - lo_spd) * (curtemp - lo_temp) / (hi_temp - lo_temp));
ESP_LOGD("fan_speed", "DEBUG New Speed set: %f", newspd);
}
if ((id(ventilate_house).state == true) && (newspd < vent_spd)) {
newspd = vent_spd;
ESP_LOGD("fan_speed", "DEBUG New Speed changed to Vent Speed: %f", newspd);
}
if (newspd < lo_spd) {
ESP_LOGD("fan_speed", "DEBUG New Speed under lo_spd, turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
ESP_LOGD("fan_speed", "DEBUG Setting fan to newspd: %f", newspd);
auto call = id(duct_fan_spd_id).turn_on();
call.set_speed(newspd);
call.perform();
@@ -179,10 +213,3 @@ climate:
- logger.log: "WARNING: Prj3 Thermostat has hit high temp!"
- switch.turn_on: thermostat_on_id
#TODO - provide some kind of warning / action here
# Sense when projector is turned on
binary_sensor:
- platform: gpio
pin: ${prjpwr_pin}
name: ${prjpwr_name}
device_class: power

View File

@@ -3,15 +3,14 @@ substitutions:
duct_fan_name: R2 Duct Fan Spd
duct_fan_tgt_spd_in_name: R2 DF Tgt Spd In
duct_fan_tgt_spd_out_name: R2 DF Tgt Spd Out
# duct_fan_channel: "0"
duct_fan_pwmfreq: 5000Hz
duct_fan_off_spd: "0.0"
duct_fan_lo_spd: "1.0"
duct_fan_vent_spd: "50.0"
duct_fan_hi_spd: "100.0"
wall_fan_pwr_pin: GPIO21
wall_fan_pwr_name: Rack 2 Wall Fan Power
wall_fan_spd_pin: GPIO22
# wall_fan_spd_channel: "2"
wall_fan_spd_pwmfreq: 25000Hz
wall_fan_spd_name: Rack 2 Wall Fan Speed
wall_fan_tach_pin: GPIO23
@@ -31,6 +30,9 @@ globals:
- id: duct_fan_lo_spd
type: float
initial_value: ${duct_fan_lo_spd}
- id: duct_fan_vent_spd
type: float
initial_value: ${duct_fan_vent_spd}
- id: duct_fan_hi_spd
type: float
initial_value: ${duct_fan_hi_spd}
@@ -119,6 +121,12 @@ sensor:
name: ${dallas_out_name}
id: dallas_out_id
binary_sensor:
- platform: homeassistant
name: "Ventilate House"
entity_id: input_boolean.ventilate_house
id: ventilate_house
number:
- platform: template
id: duct_fan_tgt_spd_in
@@ -141,6 +149,7 @@ number:
float curtemp;
float off_spd;
float lo_spd;
float vent_spd;
float hi_spd;
float newspd;
lo_temp = id(thermostat_out_id).target_temperature_low;
@@ -148,18 +157,37 @@ number:
curtemp = id(dallas_out_id).state;
off_spd = id(duct_fan_off_spd);
lo_spd = id(duct_fan_lo_spd);
vent_spd = id(duct_fan_vent_spd);
hi_spd = id(duct_fan_hi_spd);
if ((curtemp < lo_temp) || (id(thermostat_on_id).state == false)) {
ESP_LOGD("fan_speed", "DEBUG Ventilate House: %d", id(ventilate_house).state);
ESP_LOGD("fan_speed", "DEBUG Current Temp: %f", curtemp);
ESP_LOGD("fan_speed", "DEBUG Thermostat State: %d", id(thermostat_on_id).state);
if ((id(ventilate_house).state == false) &&
((curtemp < lo_temp) || (id(thermostat_on_id).state == false))) {
ESP_LOGD("fan_speed", "DEBUG turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
if (curtemp > hi_temp) {
ESP_LOGD("fan_speed", "DEBUG curtemp > hi_temp");
newspd = hi_spd;
} else {
// Set newspd to same linear proportion of spd range as current temp is of temp range
newspd = lo_spd + ((hi_spd - lo_spd) * (curtemp - lo_temp) / (hi_temp - lo_temp));
ESP_LOGD("fan_speed", "DEBUG New Speed set: %f", newspd);
}
if ((id(ventilate_house).state == true) && (newspd < vent_spd)) {
newspd = vent_spd;
ESP_LOGD("fan_speed", "DEBUG New Speed changed to Vent Speed: %f", newspd);
}
if (newspd < lo_spd) {
ESP_LOGD("fan_speed", "DEBUG New Speed under lo_spd, turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
ESP_LOGD("fan_speed", "DEBUG Setting fan to newspd: %f", newspd);
auto call = id(duct_fan_spd_id).turn_on();
call.set_speed(newspd);
call.perform();

View File

@@ -6,6 +6,7 @@ substitutions:
duct_fan_pwmfreq: 5000Hz
duct_fan_off_spd: "0.0"
duct_fan_lo_spd: "1.0"
duct_fan_vent_spd: "50.0"
duct_fan_amppwr_on_lo_spd: "20.0"
duct_fan_hi_spd: "100.0"
amppwr_pin: GPIO19
@@ -27,6 +28,9 @@ globals:
- id: duct_fan_amppwr_on_lo_spd_id
type: float
initial_value: ${duct_fan_amppwr_on_lo_spd}
- id: duct_fan_vent_spd
type: float
initial_value: ${duct_fan_vent_spd}
- id: duct_fan_hi_spd_id
type: float
initial_value: ${duct_fan_hi_spd}
@@ -93,6 +97,17 @@ sensor:
name: ${dallas_out_name}
id: dallas_out_id
binary_sensor:
- platform: gpio
id: amppwr_id
pin: ${amppwr_pin}
name: ${amppwr_name}
device_class: power
- platform: homeassistant
name: "Ventilate House"
entity_id: input_boolean.ventilate_house
id: ventilate_house
number:
- platform: template
id: duct_fan_tgt_spd_in_id
@@ -115,31 +130,52 @@ number:
float curtemp;
float off_spd;
float lo_spd;
float vent_spd;
float hi_spd;
float newspd;
lo_temp = id(thermostat_out_id).target_temperature_low;
hi_temp = id(thermostat_out_id).target_temperature_high;
curtemp = id(dallas_out_id).state;
off_spd = id(duct_fan_off_spd_id);
hi_spd = id(duct_fan_hi_spd_id);
lo_spd = id(duct_fan_lo_spd_id);
vent_spd = id(duct_fan_vent_spd);
hi_spd = id(duct_fan_hi_spd_id);
ESP_LOGD("fan_speed", "DEBUG Ventilate House: %d", id(ventilate_house).state);
ESP_LOGD("fan_speed", "DEBUG Amp Power: %d", id(amppwr_id).state);
ESP_LOGD("fan_speed", "DEBUG Current Temp: %f", curtemp);
ESP_LOGD("fan_speed", "DEBUG Thermostat State: %d", id(thermostat_on_id).state);
if (id(amppwr_id).state == true) {
// Amp is on, use that lo speed.
lo_spd = id(duct_fan_amppwr_on_lo_spd_id);
} else if ((curtemp < lo_temp) || (id(thermostat_on_id).state == false)) {
} else if ((id(ventilate_house).state == false) &&
((curtemp < lo_temp) || (id(thermostat_on_id).state == false))) {
// Amp is off and temp is lo or thermostat is off. Turn the fan off.
ESP_LOGD("fan_speed", "DEBUG turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
if (curtemp > hi_temp) {
ESP_LOGD("fan_speed", "DEBUG curtemp > hi_temp");
newspd = hi_spd;
} else if (curtemp < lo_temp) {
newspd = lo_spd;
} else {
// Set newspd to same linear proportion of spd range as current temp is of temp range
newspd = lo_spd + ((hi_spd - lo_spd) * (curtemp - lo_temp) / (hi_temp - lo_temp));
ESP_LOGD("fan_speed", "DEBUG New Speed set: %f", newspd);
}
if ((id(ventilate_house).state == true) && (newspd < vent_spd)) {
newspd = vent_spd;
ESP_LOGD("fan_speed", "DEBUG New Speed changed to Vent Speed: %f", newspd);
}
if (newspd < lo_spd) {
ESP_LOGD("fan_speed", "DEBUG New Speed under lo_spd, turning off");
auto call = id(duct_fan_spd_id).turn_off();
call.perform();
return off_spd;
}
ESP_LOGD("fan_speed", "DEBUG Setting fan to newspd: %f", newspd);
auto call = id(duct_fan_spd_id).turn_on();
call.set_speed(newspd);
call.perform();
@@ -173,11 +209,3 @@ climate:
- logger.log: "WARNING: Rack3 Thermostat has hit high temp!"
- switch.turn_on: thermostat_on_id
#TODO - provide some kind of warning / action here
# Sense when receiver is turned on
binary_sensor:
- platform: gpio
id: amppwr_id
pin: ${amppwr_pin}
name: ${amppwr_name}
device_class: power