Climate change has raised many new problems impacting everyday life. One challenge we recently wrestled with was the combined effects of smoke from surrounding forest fires and the stifling mugginess of a heat wave. Keeping the windows closed to keep the smoke out made it more difficult to control the temperature in the house, but beyond that, too long with the windows closed leads to a very stuffy environment.
Near the beginning of the 2020 California wildfire season, the air quality around our house varied widely, and conditions changed rapidly. The AQI could be over 150 in the morning, and clear up to a reading under 50 by evening. We wanted to be able to open our windows as soon as possible when conditions improved, but we didn't want to leave them open when another cloud of smoke passed through town. This was particularly important at night. If we went to sleep with the windows open, by the time worsening air conditions woke us up, the house would already be full of smoke. We couldn't take the risk, so the windows stayed closed.
The obvious solution that we needed was an audible notification whenever the air quality went over a certain threshold, and again when it came back down to a breathable level. We already had the advantage of having a small low-power Linux box that we keep running 24/7 to run our local network services. This little computer also has a built-in sound card, despite its small size, and with a little digging around in the basement, I soon had a pair of speakers to hook up to it.
To determine what the current air quality index was, I used the public API published by purpleair.com. It was pretty easy to pull air quality data from this tool; Purple Air has sensors all over, so I just picked one nearby. I set up my script to run on a timer every ten minutes, and made a simple web-based tool to display the last-read AQI value and select the high and low threshold values. The hardest part of the project was getting sound to work. By default, the audio driver on my computer was only active when someone was logged in. With a bit of digging, I found some documentation on how to run it in system mode; once I had that set up, I could play sounds from my background process.
Our new system is working great now, and gave us a couple of good notifications the first day we had it running. The only ironic thing is that since then, the air quality has not varied much. We are still waiting and looking forward to the day when current conditions improve enough for our computer to speak up and let us know that things have cleared up. It would have been great to have earlier, and, the way things are going, we'll probably need it again in 2021.
If you want more information on how this was implemented, the source code is available on GitHub.