diff --git a/README.md b/README.md index 50a2931..6e58ba3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ESPHome yaml files for AirGradient devices to maintain the research and accuracy * Remove substitution line such as `config_version: 2.0.5` from the main file, as this has been moved into the board package file * Updated to 4.0.0 versions, skipping 3.x to avoid confusion with current AirGradient official firmware +* Now defaulting to https for AirGradient API communication. If older devices (DIY and Pro models) go into constant reboots, switch to the api package `airgradient_api_d1_mini_insecure.yaml` to revert to the original communication method ## Changes diff --git a/packages.md b/packages.md index c6dd2fd..4090969 100644 --- a/packages.md +++ b/packages.md @@ -10,6 +10,12 @@ Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/d Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard). This file is for devices based on the D1 Mini chip (AG Basic and AG Pro) with all current sensors, including SGP41 +# airgradient_api_d1_mini_insecure.yaml + +Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard) using http instead of https. Some boards, such as the ESP8266 D1 Mini can sometimes go into a reboot loop when communicating over https. Original firmware used http without issue, so offering this as an alternative for devices that require it. + + This file is for devices based on the D1 Mini chip (AG Basic and AG Pro) with all current sensors, including SGP41 + ## airgradient_api_esp32-c3_dual_pms5003t.yaml Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard). This file is for devices based on the ESP32-C3 chip (AG ONE and OpenAir) with dual PMS5003t sensors. Designed for the Outdoor OpenAir model O-PPT1 diff --git a/packages/airgradient_api_d1_mini_insecure.yaml b/packages/airgradient_api_d1_mini_insecure.yaml new file mode 100644 index 0000000..364fd3a --- /dev/null +++ b/packages/airgradient_api_d1_mini_insecure.yaml @@ -0,0 +1,61 @@ +interval: + - interval: 2.5min + # Send data to AirGradient API server + then: + if: + condition: + switch.is_on: upload_airgradient + then: + - http_request.post: + # http://api.airgradient.com/public/docs/api/v1/ + # AirGradient URL with the last 6 of MAC address all lower case + url: !lambda |- + return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures"; + headers: + Content-Type: application/json + json: + wifi: !lambda return to_string(id(wifi_dbm).state); + rco2: !lambda return to_string(id(co2).state); + pm01: !lambda return to_string(id(pm_1_0).state); + pm02: !lambda return to_string(id(pm_2_5).state); + pm10: !lambda return to_string(id(pm_10_0).state); + pm003Count: !lambda return to_string(id(pm_0_3um).state); + atmp: !lambda return to_string(id(temp_raw).state); + atmpCompensated: !lambda return to_string(id(temp).state); + rhum: !lambda return to_string(id(humidity_raw).state); + rhumCompensated: !lambda return to_string(id(humidity).state); + tvocIndex: !lambda return to_string(id(voc).state); + noxIndex: !lambda return to_string(id(nox).state); + # Uptime in minutes as the boot value + boot: !lambda return to_string(round(id(device_uptime).state/60)); + +switch: + - platform: template + name: "Upload to AirGradient Dashboard" + id: upload_airgradient + restore_mode: RESTORE_DEFAULT_OFF + optimistic: True + +esphome: + on_boot: + priority: 200 # Network connections setup + then: + if: + condition: + switch.is_on: upload_airgradient + then: + - http_request.post: + # Return wifi signal -50 as soon as device boots to show activity on AirGradient Dashboard site + # Using -50 instead of actual value as the wifi_signal sensor has not reported a value at this point in boot process + url: !lambda |- + return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures"; + headers: + Content-Type: application/json + json: + wifi: !lambda return to_string(-50); + +http_request: + timeout: 1s # Setting short to try to prevent watchdog reboots http://github.com/esphome/issues/issues/2853 + # Used to support POST request to send data to AirGradient + # http://esphome.io/components/http_request.html + verify_ssl: false # Must be explicityly set to false when using Arduino framework diff --git a/packages/airgradient_d1_mini_board.yaml b/packages/airgradient_d1_mini_board.yaml index 519f351..b6c3186 100644 --- a/packages/airgradient_d1_mini_board.yaml +++ b/packages/airgradient_d1_mini_board.yaml @@ -1,5 +1,5 @@ substitutions: - config_version: 4.0.4 + config_version: 4.0.5 esphome: name: "${name}" diff --git a/packages/airgradient_esp32-c3_board.yaml b/packages/airgradient_esp32-c3_board.yaml index 0aad12a..9b4250e 100644 --- a/packages/airgradient_esp32-c3_board.yaml +++ b/packages/airgradient_esp32-c3_board.yaml @@ -1,5 +1,5 @@ substitutions: - config_version: 4.0.3 + config_version: 4.0.5 esphome: name: "${name}"