diff --git a/propbox.yaml b/propbox.yaml index 83f5ca0ed048c87169da7b4eb0c5b7f6938cecb4..a08b248f97e2872773330d2f232e1013d7385d6a 100644 --- a/propbox.yaml +++ b/propbox.yaml @@ -27,11 +27,6 @@ substitutions: humidity_fan_on: "60" humidity_fan_off: "40" -# fix for 2022.5.0 -external_components: - - source: github://martgras/esphome@nvs-fix - components: [esp32] - <<: !include common.yaml esp32: @@ -55,11 +50,13 @@ sensor: - platform: pvvx_mithermometer mac_address: ${ble_sensor_mac} battery_level: - name: "Battery Level" + id: ble_battery_level + name: "BLE Battery Level" battery_voltage: - name: "Battery Voltage" + id: ble_battery_voltage + name: "BLE Battery Voltage" temperature: - id: "ble_temperature" + id: ble_temperature name: "Temperature" on_value_range: - above: ${temperature_fan_on} @@ -85,7 +82,7 @@ sensor: # then: # - switch.turn_off: propbox_fan humidity: - id: "ble_humidity" + id: ble_humidity name: "Humidity" on_value_range: - above: ${humidity_fan_on} @@ -119,18 +116,10 @@ globals: type: int restore_value: true initial_value: '0' - - id: state_light - type: int - restore_value: true - initial_value: '0' - - id: state_fan - type: int - restore_value: true - initial_value: '0' select: - platform: template - id: "select_schedule" + id: select_schedule name: "Light Schedule" options: - "Disabled" @@ -149,61 +138,55 @@ http_request: 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" + id: propbox_light name: "Light Status" - lambda: |- - if (id(state_light) == 1) { - return true; - } else { - return false; - } turn_on_action: - http_request.post: url: http://${hostname_light}/switch/power/turn_on - on_response: - then: - - lambda: |- - if (status_code == 200) { - id(state_light) = 1; - } turn_off_action: - http_request.post: url: http://${hostname_light}/switch/power/turn_off - on_response: - then: - - lambda: |- - if (status_code == 200) { - id(state_light) = 0; - } - platform: template - id: "propbox_fan" + id: propbox_fan name: "Fan Status" - lambda: |- - if (id(state_fan) == 1) { - return true; - } else { - return false; - } turn_on_action: - http_request.post: url: http://${hostname_fan}/switch/power/turn_on - on_response: - then: - - lambda: |- - if (status_code == 200) { - id(state_fan) = 1; - } turn_off_action: - http_request.post: url: http://${hostname_fan}/switch/power/turn_off - on_response: - then: - - lambda: |- - if (status_code == 200) { - id(state_fan) = 0; - } time: - platform: sntp @@ -216,26 +199,26 @@ time: - lambda: |- if (id(schedule) == 1) { id(propbox_light).turn_on(); - id(state_light) = 1; + id(propbox_light).publish_state(true); } - cron: ${schedule_grow_off} then: - lambda: |- if (id(schedule) == 1) { id(propbox_light).turn_off(); - id(state_light) = 0; + id(propbox_light).publish_state(false); } - cron: ${schedule_bloom_on} then: - lambda: |- if (id(schedule) == 2) { id(propbox_light).turn_on(); - id(state_light) = 1; + id(propbox_light).publish_state(true); } - cron: ${schedule_bloom_off} then: - lambda: |- if (id(schedule) == 2) { id(propbox_light).turn_off(); - id(state_light) = 0; + id(propbox_light).publish_state(false); }