Every year in California the fire season feels like it gets longer and more devastating. This year with everything else going on it feels especially bad. This year I took the time to build a ingestion script of PurpleAir sensor data, graph it with Grafana and send alerts when the air near my apartment reaches >50 AQI.
To build this I used PurpleAir’s API to pull sensor data every ~5 minutes and write it to MySQL. I then setup Grafana and created a dashboard with a map of sensors and points of interest. Grafana also manages sending a push notification using Pushover.net when AQI is above 50 for 10 minutes.
MySQL and Grafana are both running in containers on my Synology NAS with external volume storage.
I wrote a Python script that runs on my Intel NUC that gets triggered by a CRONJOB every five minutes. This script does the following steps:
- Pull JSON data from PurpleAir
- Filter out any sensor that does not meet the below requirements:
- Not located “outside”
- Not reported in the last 5 minutes
- Not within specific Longitude and Latitude
- Take the raw PM 2.5 Value and convert to US AQI
- Insert all data into database
MySQL Table #
Ingestion Script #