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:
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:
For those that like to edit queries, the textual version of this config is:
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:
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: