diff --git a/propbox.yaml b/propbox.yaml index a08b248f97e2872773330d2f232e1013d7385d6a..659a5c57d96fcc6893bbbcf010ec5e48d0925057 100644 --- a/propbox.yaml +++ b/propbox.yaml @@ -10,7 +10,7 @@ substitutions: hostname_fan: "propbox-fan.${domain}" # Sensors - ble_sensor_mac: "A4:C1:38:47:14:50" + ble_sensor_mac: "A4:C1:38:47:14:50" # 'PropBoxBLE' # Schedules #schedule_grow_on: "0 0 3 * * *" @@ -22,10 +22,10 @@ substitutions: schedule_bloom_on: "0 * * * * *" schedule_bloom_off: "30 * * * * *" - temperature_fan_on: "27.0" - temperature_fan_off: "21.0" - humidity_fan_on: "60" - humidity_fan_off: "40" + temperature_max: "27" + temperature_min: "23" + humidity_max: "60" + humidity_min: "50" <<: !include common.yaml @@ -34,6 +34,11 @@ esp32: esp32_ble_tracker: +http_request: + id: http_request_data + useragent: esphome/${devicename} + timeout: 10s + sensor: ### Default Sensors @@ -58,55 +63,15 @@ sensor: temperature: id: ble_temperature name: "Temperature" - on_value_range: - - 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: - - switch.turn_off: propbox_fan - # then: - # - if: - # condition: - # and: - # - lambda: return (x < ${humidity_fan_on}); - # - switch.is_on: propbox_fan - # then: - # - switch.turn_off: propbox_fan + on_value: + then: + - script.execute: fan_control humidity: id: ble_humidity name: "Humidity" - on_value_range: - - 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: - - switch.turn_off: propbox_fan - # then: - # - if: - # condition: - # and: - # - lambda: return (x < ${temperature_fan_on}); - # - switch.is_on: propbox_fan - # then: - # - switch.turn_off: propbox_fan + on_value: + then: + - script.execute: fan_control text_sensor: !include include/text_sensors.yaml @@ -133,45 +98,11 @@ select: auto index = id(select_schedule).active_index(); 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: - platform: template id: propbox_light name: "Light Status" + optimistic: true turn_on_action: - http_request.post: url: http://${hostname_light}/switch/power/turn_on @@ -181,12 +112,21 @@ switch: - platform: template id: propbox_fan name: "Fan Status" + optimistic: true turn_on_action: - http_request.post: url: http://${hostname_fan}/switch/power/turn_on turn_off_action: - http_request.post: 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: - platform: sntp @@ -222,3 +162,53 @@ time: id(propbox_light).turn_off(); 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