Sorry, you need to enable JavaScript to visit this website.

You are here

Air quality SMS alerts during bushfire season

BY Tim McMahon 02 June 2021

I woke up one morning in January 2020 to discover that the air quality in Melbourne had dropped to hazardous levels from bushfire smoke. This hazardous air quality was extremely concerning to my wife and I with our newborn.

I wanted to receive an SMS message whenever PM2.5 levels exceeded 300, so that we could be more alert and take action (wear a mask, try to filter the air). But I didn't have any air quality sensors at home.

Air quality data from the EPA AirWatch API

While looking at the air quality page for a nearby suburb on the EPA Victoria website, I noticed "Connect to our developer portal". I signed up and soon discovered that the EPA have an AirWatch API. Awesome!

There were three things that I needed to do to get air quality info for a nearby suburb:

  1. Sign up and get an API Key via the EPA Developer Portal.
  2. Read the AirWatch API documentation and figure out what the Site ID is for a nearby suburb.
  3. Create a script to call the AirWatch API and get air quality information for a particular site.

SMS alerts via the Telstra Messaging API

Now, I don't want to visit the EPA website every day to see the current reading in my area, and other channels like email can be easily missed. So for this critical alert I wanted to go with SMS.

For the past few years I've been sending SMS messages using the Telstra Messaging API Free Trial for random projects like this. (You can sign up for free on https://dev.telstra.com/ and follow the API documentation to get started).

I found the documentation and error messages pretty helpful for getting my home projects set up quickly and easily.

Air quality alerts

Okay, so with access to the EPA AirWatch API and the Telstra Messaging API I had:

  • air quality data
  • a way to send SMS messages

Now I needed to set up an automated script to pull the air quality data every hour, and compare that to the 300µg/m³ threshold I'd set.

I whipped up a script with bash, curl and scheduled it to run via crontab on my Linux server. But after this initial kneejerk reaction to hazardous air quality, I decided to rewrite the script in Python.

The threshold can be configured in check_air_quality.config.json. I initially used a low threshold of around 50 while testing but I was getting too many SMS alerts, so I raised it to 100. 100 isn't great, but it's pretty alarming when PM2.5 exceeds 300. I'd suggest using a threshold that you're comfortable with.

I scheduled the script to run on my Linux server every hour at 20 minutes past the hour using a cron job entry:

crontab -e
20 * * * * /home/user/air_quality_alert/check_air_quality.py >> /home/user/air_quality_alert/check_air_quality.log 2>&1

The script is up on my GitHub with detailed instructions, feel free to fork it and adapt it for yourself.

So now when the EPA AirWatch registers PM2.5 levels exceeding 300µg/m³  I'll be the first to know. Fingers crossed we won't see this message this year, but better to be safe than sorry.

This is what the script does in a nutshell:

Python all the things

It's amazing to see Python being embraced at schools by organisations like Code Club Australia and now calculators are supporting this language too. (My daughter Evelyn and I are already tinkering with air purifiers!)

I learnt how to code with TI-BASIC on a TI-83 Plus graphing calculator in high school. It came with a thick reference manual. My maths teacher gave me a Borland BASIC book to nurture my curiosity and encourage me to port programs from one BASIC language to another. 

With more and more APIs being made accessible, people can start whipping up solutions quickly in Python to satisfy their needs. Python seems to be a modern day Swiss Army Knife of coding!

What next?

My next project will involve using a cheap PMS7003 air quality sensor to get our own local air quality measurements at home.

If you have any questions about this project, specifically for integrating with the Telstra Messaging API, please post on support forum: https://dev.telstra.com/forums/messaging-api-forum

Related Blogs

anonymous's picture

By Trent Steenholdt

10/11/20

  • iot
  • azure

A home IoT project using Azure

In this blog series, I'll explan how I used the Internet of Things (IoT) to enable my gate, gara...
anonymous's picture

By DIYODE Magazine

9/11/20

  • arduino
  • iot

IoT Arduino MKR NB 1500 and Telstra NB-IoT

We put the Arduino MKR NB 1500 to the test using the Telstra network and show you how to g...
anonymous's picture

By Michelle Howie

20/10/20

  • hackathon
  • iot

GovHack 2020: IoT sustainability

In the second TelstraDev challenge for GovHack 2020 (read part one: emergency comms and the Telstra...
anonymous's picture

By Michelle Howie

20/10/20

  • hackathon
  • Telstra Messaging API

GovHack 2020: emergency comms with the Telstra Messaging API

What do you get when you give 700 hackers, hustlers and hipsters across Australia and New Zealand, a...
anonymous's picture

By Michelle Howie

1/9/20

  • iot
  • developer experience

IoT guidelines for wireless developers

The Internet of Things (IoT) is an all-encompassing suite of technologies, with dozens of options fo...
anonymous's picture

By Michelle Howie

26/8/20

  • iot
  • captis

Introducing Telstra Captis

UPDATE [15/7/21]: This product is no longer available for purchase on TelstraDev. More details...
anonymous's picture

By Tiana Fong

18/8/20

  • iot
  • Telstra IoT Platform

Telstra's IoT Platform

  The Internet of Things (IoT) is a network of physical objects that collects data from the...
anonymous's picture

By Michelle Howie

7/7/20

  • developer experience
  • REST API

New Developer Feature: API Service Status Page

You asked, we listened. Our developer community told us that they wantedgreater transparency and...
anonymous's picture

By Michelle Howie

25/5/20

  • developer experience
  • REST API

Getting virtual in times of uncertainty

Here at TelstraDev, we hope you're continuing to thrive and innovate, staying safe and healthy i...
anonymous's picture

By Brendan Myers

8/4/19

  • arduino
  • MKR NB1500

Introducing the Arduino MKR NB1500

Last year, we were proud to announce our partnership with Arduino to help create an IoT-network...
anonymous's picture

By

11/1/18

  • REST API
  • Telstra Messaging API

Welcoming in the New Year

Happy New year, I hope you had an awesome break and were able to recharge, reset and prepare for...