Skip to content
Snippets Groups Projects
Commit a8362afb authored by Jan Grewe's avatar Jan Grewe
Browse files

fan control

parent 0c2b556f
Branches
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ substitutions: ...@@ -10,7 +10,7 @@ substitutions:
hostname_fan: "propbox-fan.${domain}" hostname_fan: "propbox-fan.${domain}"
# Sensors # Sensors
ble_sensor_mac: "A4:C1:38:47:14:50" ble_sensor_mac: "A4:C1:38:47:14:50" # 'PropBoxBLE'
# Schedules # Schedules
#schedule_grow_on: "0 0 3 * * *" #schedule_grow_on: "0 0 3 * * *"
...@@ -22,10 +22,10 @@ substitutions: ...@@ -22,10 +22,10 @@ substitutions:
schedule_bloom_on: "0 * * * * *" schedule_bloom_on: "0 * * * * *"
schedule_bloom_off: "30 * * * * *" schedule_bloom_off: "30 * * * * *"
temperature_fan_on: "27.0" temperature_max: "27"
temperature_fan_off: "21.0" temperature_min: "23"
humidity_fan_on: "60" humidity_max: "60"
humidity_fan_off: "40" humidity_min: "50"
<<: !include common.yaml <<: !include common.yaml
...@@ -34,6 +34,11 @@ esp32: ...@@ -34,6 +34,11 @@ esp32:
esp32_ble_tracker: esp32_ble_tracker:
http_request:
id: http_request_data
useragent: esphome/${devicename}
timeout: 10s
sensor: sensor:
### Default Sensors ### Default Sensors
...@@ -58,55 +63,15 @@ sensor: ...@@ -58,55 +63,15 @@ sensor:
temperature: temperature:
id: ble_temperature id: ble_temperature
name: "Temperature" name: "Temperature"
on_value_range: on_value:
- above: ${temperature_fan_on}
then:
- switch.turn_on: propbox_fan
# then:
# - if:
# condition:
# and:
# - lambda: return (x > ${humidity_fan_off});
# - switch.is_off: propbox_fan
# then:
# - switch.turn_on: propbox_fan
- below: ${temperature_fan_off}
then: then:
- switch.turn_off: propbox_fan - script.execute: fan_control
# then:
# - if:
# condition:
# and:
# - lambda: return (x < ${humidity_fan_on});
# - switch.is_on: propbox_fan
# then:
# - switch.turn_off: propbox_fan
humidity: humidity:
id: ble_humidity id: ble_humidity
name: "Humidity" name: "Humidity"
on_value_range: on_value:
- above: ${humidity_fan_on}
then:
- switch.turn_on: propbox_fan
# then:
# - if:
# condition:
# and:
# - lambda: return (x > ${temperature_fan_off});
# - switch.is_off: propbox_fan
# then:
# - switch.turn_on: propbox_fan
- below: ${humidity_fan_off}
then: then:
- switch.turn_off: propbox_fan - script.execute: fan_control
# then:
# - if:
# condition:
# and:
# - lambda: return (x < ${temperature_fan_on});
# - switch.is_on: propbox_fan
# then:
# - switch.turn_off: propbox_fan
text_sensor: text_sensor:
!include include/text_sensors.yaml !include include/text_sensors.yaml
...@@ -133,45 +98,11 @@ select: ...@@ -133,45 +98,11 @@ select:
auto index = id(select_schedule).active_index(); auto index = id(select_schedule).active_index();
id(schedule) = index.value(); id(schedule) = index.value();
http_request:
id: http_request_data
useragent: esphome/${devicename}
timeout: 10s
interval:
- id: propbox_light_state
interval: 1min
then:
- lambda: |-
HTTPClient http;
bool state = false;
http.begin("http://${hostname_light}/switch/power");
if (http.GET() == 200) {
DynamicJsonDocument doc(200);
deserializeJson(doc, http.getString());
state = (doc["state"] == "ON") ? true : false;
}
id(propbox_light).publish_state(state);
http.end();
- id: propbox_fan_state
interval: 1min
then:
- lambda: |-
HTTPClient http;
bool state = false;
http.begin("http://${hostname_fan}/switch/power");
if (http.GET() == 200) {
DynamicJsonDocument doc(200);
deserializeJson(doc, http.getString());
state = (doc["state"] == "ON") ? true : false;
}
id(propbox_fan).publish_state(state);
http.end();
switch: switch:
- platform: template - platform: template
id: propbox_light id: propbox_light
name: "Light Status" name: "Light Status"
optimistic: true
turn_on_action: turn_on_action:
- http_request.post: - http_request.post:
url: http://${hostname_light}/switch/power/turn_on url: http://${hostname_light}/switch/power/turn_on
...@@ -181,6 +112,7 @@ switch: ...@@ -181,6 +112,7 @@ switch:
- platform: template - platform: template
id: propbox_fan id: propbox_fan
name: "Fan Status" name: "Fan Status"
optimistic: true
turn_on_action: turn_on_action:
- http_request.post: - http_request.post:
url: http://${hostname_fan}/switch/power/turn_on url: http://${hostname_fan}/switch/power/turn_on
...@@ -188,6 +120,14 @@ switch: ...@@ -188,6 +120,14 @@ switch:
- http_request.post: - http_request.post:
url: http://${hostname_fan}/switch/power/turn_off url: http://${hostname_fan}/switch/power/turn_off
interval:
- interval: 1min
then:
- script.execute: propbox_light_state
- interval: 1min
then:
- script.execute: propbox_fan_state
time: time:
- platform: sntp - platform: sntp
id: sntp_time id: sntp_time
...@@ -222,3 +162,53 @@ time: ...@@ -222,3 +162,53 @@ time:
id(propbox_light).turn_off(); id(propbox_light).turn_off();
id(propbox_light).publish_state(false); id(propbox_light).publish_state(false);
} }
script:
- id: fan_control
then:
- lambda: |-
// switch fan on when temperature/humidity is above the limit, unless humidity/temperature is below the limit
if (
!id(propbox_fan).state &&
(id(ble_temperature).state >= ${temperature_max} && id(ble_humidity).state >= ${humidity_min}) ||
(id(ble_humidity).state >= ${humidity_max} && id(ble_temperature).state >= ${temperature_min})
) {
id(propbox_fan).turn_on();
id(propbox_fan).publish_state(true);
}
// switch fan off when temperature and humidity are below the limits
else if (
id(propbox_fan).state &&
id(ble_temperature).state <= ${temperature_max} && id(ble_humidity).state <= ${humidity_max}
) {
id(propbox_fan).turn_off();
id(propbox_fan).publish_state(false);
}
- id: propbox_light_state
then:
- lambda: |-
HTTPClient http;
bool state = false;
http.begin("http://${hostname_light}/switch/power");
if (http.GET() == 200) {
DynamicJsonDocument doc(200);
deserializeJson(doc, http.getString());
state = (doc["state"] == "ON") ? true : false;
}
id(propbox_light).publish_state(state);
http.end();
- id: propbox_fan_state
then:
- lambda: |-
HTTPClient http;
bool state = false;
http.begin("http://${hostname_fan}/switch/power");
if (http.GET() == 200) {
DynamicJsonDocument doc(200);
deserializeJson(doc, http.getString());
state = (doc["state"] == "ON") ? true : false;
}
id(propbox_fan).publish_state(state);
http.end();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment