Wednesday, October 14, 2020

Using Telegraph to collect local PurpleAir sensor data

If you are like me, you enjoy breathing. Perhaps you are not as keen on it but you certainly notice when it starts getting uncomfortable to breathe from heavy smoke or smog. After the latest round of California wildfires, I decided to purchase a PurpleAir sensor so I could know how the air inside my house and outside of my house were likely to affect me. I also have no central AC so understanding what happens when I open my windows turned out to be fairly transformative. I chose PurpleAir because a running friend linked me to it before coordinating a run and it has a fair network of sensors whose data is aggregated and displayed on a map for all to see. The data is also collected for WUnderground and its supporting entities. There was no node within 10 miles of my house and there are now several within 3 miles.

Enough backstory! Let's dive in...

Goals:

1) Understand current and historical data from my shiny new sensor

2) Find sources of air pollution in my home

3) Measure effectiveness of different filters at reducing AQI

I like the aggregated data on the PurpleAir website but they make it difficult to really get the most from the data. Also, they don't expose the full range of measurements on the website. While I appreciate this from a slight privacy standpoint, I need access to it for my own purposes.

My solution:

Setup Grafana, InfluxDB and Telegraf on a small local server (think: RaspberryPi or RockPro.)

There are many tutorials on getting these technologies set up with one-another so I'll just focus on the Telegraf configuration as well as displaying an example Grafana dashboard. It's up to you to fill in the rest!

Telegraf config:

[[inputs.http]]
  interval = "10s"
  urls = [
    "http://purple-outside.example.com/json?live=true"
  ]
  method = "GET"
  timeout = "2s"
  data_format = "json"
  name_override = "purpleair"
  tag_keys = [
    "SensorId",
    "Geo",
    "Mem",
    "place",
    "version",
    "hardwareversion",
    "hardwarediscovered",
    "wlstate",
    "status_0",
    "status_1",
    "status_2",
    "status_3",
    "status_4",
    "status_5",
    "status_6",
    "status_7",
    "status_8",
    "status_9",
    "ssid",
  ]
  ## Unclear that this does the right thing with timezones/utc as the reference
  ## time in go is specific to MST.
  # json_time_key = "DateTime"
  # json_time_format = "2006-01-02T15:04:05z"

"purple-outside.example.com" can be replaced with your sensor's name or IP address depending on your network setup.

This configuration takes the JSON data from the sensor every 10 seconds and treats SensorID/Geo/Mem/place/etc... as tag data in InfluxDB.

Grafana dashboard AQI config:

AQI Query

For those that like to edit queries, the textual version of this config is:

SELECT mean("pm2.5_aqi") FROM "purpleair" WHERE ("url" = 'http://purple-outside.example.com/json?live=true') AND $timeFilter GROUP BY time($__interval) fill(linear)

If you have a fancy two-sensor version, you can add a second query with "pm2.5_aqi_b" instead of "pm2.5_aqi"


AQI graph

I purchased two sensors; One for inside and one for outside. As such, I added three queries and colored the two outside sensors as blue and the inside one as yellow. The resulting graph looks like this:

AQI Graph

Can you tell when the stove is being used? (Hint: it's those tall yellow peaks!)


Temp/Humidity

The sensor also exposes fine-grained counts of different particle sizes, temperature, humidity, dewpoint and and more. For example, instead of "pm2.5_aqi" you can select "current_dewpoint_f", "current_temp_f", and "current_humidity" and create a dual-axis graph:

Temperature Humidity and Dewpoint graph


Pressure


Pressure graph


Particle Size Counts



Results

I found that one of my filters does next to nothing for my air quality while my Honeywell HEPA filter brings the AQI of my house into the single digits from triple digits after some hours of running.

Also, cooking without adequate ventilation releases a surprising amount of fine particulate matter (but it sure smells good!)

Final Remarks

I hope this helps someone else breathe easier. Just knowing what your air quality is can be very helpful for understanding sources of congestion/sleep/wheezing etc. Thanks for reading!

No comments:

Post a Comment