|
| 1 | +interval: |
| 2 | + - interval: 2.5min |
| 3 | + # Send data to AirGradient API server |
| 4 | + then: |
| 5 | + if: |
| 6 | + condition: |
| 7 | + switch.is_on: upload_airgradient |
| 8 | + then: |
| 9 | + - http_request.post: |
| 10 | + # https://api.airgradient.com/public/docs/api/v1/ |
| 11 | + # AirGradient URL with the MAC address all lower case |
| 12 | + url: !lambda |- |
| 13 | + return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures"; |
| 14 | + headers: |
| 15 | + Content-Type: application/json |
| 16 | + # "!lambda return to_string(id(pm_2_5).state);" Converts sensor output from double to string |
| 17 | + json: |
| 18 | + wifi: !lambda return to_string(id(wifi_dbm).state); |
| 19 | + pm01: !lambda return to_string(id(pm_1_0).state); |
| 20 | + pm02: !lambda return to_string(id(pm_2_5).state); |
| 21 | + pm10: !lambda return to_string(id(pm_10_0).state); |
| 22 | + pm003_count: !lambda return to_string(id(pm_0_3um).state); |
| 23 | + rco2: !lambda return to_string(id(co2).state); |
| 24 | + atmp: !lambda return to_string(id(temp).state); |
| 25 | + rhum: !lambda return to_string(id(humidity).state); |
| 26 | + tvoc_index: !lambda return to_string(id(voc).state); |
| 27 | + nox_index: !lambda return to_string(id(nox).state); |
| 28 | + |
| 29 | +switch: |
| 30 | + - platform: template |
| 31 | + name: "Upload to AirGradient Dashboard" |
| 32 | + id: upload_airgradient |
| 33 | + restore_mode: RESTORE_DEFAULT_ON |
| 34 | + optimistic: True |
| 35 | + |
| 36 | +esphome: |
| 37 | + on_boot: |
| 38 | + priority: 200 # Network connections setup |
| 39 | + then: |
| 40 | + if: |
| 41 | + condition: |
| 42 | + switch.is_on: upload_airgradient |
| 43 | + then: |
| 44 | + - http_request.post: |
| 45 | + # Return wifi signal -50 as soon as device boots to show activity on AirGradient Dashboard site |
| 46 | + # Using -50 instead of actual value as the wifi_signal sensor has not reported a value at this point in boot process |
| 47 | + url: !lambda |- |
| 48 | + return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures"; |
| 49 | + headers: |
| 50 | + Content-Type: application/json |
| 51 | + json: |
| 52 | + wifi: !lambda return to_string(-50); |
| 53 | + |
| 54 | +http_request: |
| 55 | + # Used to support POST request to send data to AirGradient |
| 56 | + # https://esphome.io/components/http_request.html |
0 commit comments