|
| 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 | + # http://api.airgradient.com/public/docs/api/v1/ |
| 11 | + # AirGradient URL with the last 6 of 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 | + json: |
| 17 | + wifi: !lambda return to_string(id(wifi_dbm).state); |
| 18 | + rco2: !lambda return to_string(id(co2).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 | + pm003Count: !lambda return to_string(id(pm_0_3um).state); |
| 23 | + atmp: !lambda return to_string(id(temp_raw).state); |
| 24 | + atmpCompensated: !lambda return to_string(id(temp).state); |
| 25 | + rhum: !lambda return to_string(id(humidity_raw).state); |
| 26 | + rhumCompensated: !lambda return to_string(id(humidity).state); |
| 27 | + tvocIndex: !lambda return to_string(id(voc).state); |
| 28 | + noxIndex: !lambda return to_string(id(nox).state); |
| 29 | + # Uptime in minutes as the boot value |
| 30 | + boot: !lambda return to_string(round(id(device_uptime).state/60)); |
| 31 | + |
| 32 | +switch: |
| 33 | + - platform: template |
| 34 | + name: "Upload to AirGradient Dashboard" |
| 35 | + id: upload_airgradient |
| 36 | + restore_mode: RESTORE_DEFAULT_OFF |
| 37 | + optimistic: True |
| 38 | + |
| 39 | +esphome: |
| 40 | + on_boot: |
| 41 | + priority: 200 # Network connections setup |
| 42 | + then: |
| 43 | + if: |
| 44 | + condition: |
| 45 | + switch.is_on: upload_airgradient |
| 46 | + then: |
| 47 | + - http_request.post: |
| 48 | + # Return wifi signal -50 as soon as device boots to show activity on AirGradient Dashboard site |
| 49 | + # Using -50 instead of actual value as the wifi_signal sensor has not reported a value at this point in boot process |
| 50 | + url: !lambda |- |
| 51 | + return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures"; |
| 52 | + headers: |
| 53 | + Content-Type: application/json |
| 54 | + json: |
| 55 | + wifi: !lambda return to_string(-50); |
| 56 | + |
| 57 | +http_request: |
| 58 | + timeout: 1s # Setting short to try to prevent watchdog reboots http://github.com/esphome/issues/issues/2853 |
| 59 | + # Used to support POST request to send data to AirGradient |
| 60 | + # http://esphome.io/components/http_request.html |
| 61 | + verify_ssl: false # Must be explicityly set to false when using Arduino framework |
0 commit comments