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 Michelle Howie

20/12/21

  • Telstra Messaging API
  • REST API

Good APIs start with the docs

With our new docs experience, it's easier than ever to get started with Telstra APIs. ...
anonymous's picture

By Daniel Simpson

17/12/21

  • azure
  • microsoft

A code-first approach to digital twins

Find out how to use code-first digital twins with the Telstra Digital Twins library.   ...
anonymous's picture

By Michelle Howie

25/10/21

  • iot
  • arduino

AgTech and sustainable agribusiness

Our GovHack 2021 challege explored how AgTech can improve sustainable agribusiness.  ...
anonymous's picture

By Quinn Tran

25/9/21

  • iot
  • microsoft

Creative projects with Microsoft Azure

Get your creative juices flowing with the latest in computer vision innovation.   ...
anonymous's picture

By Michelle Howie

15/7/21

  • arduino
  • iot

Trigger an SMS alert when a device is dropped

Learn how Arduino can be used to trigger an SMS alert when a device has been dropped.  Autom...
anonymous's picture

By Michelle Howie

15/7/21

  • arduino
  • iot

Get environmental sensor data via SMS

Learn how to set up on-demand SMS updates for your IoT devices.  Potential use cases If y...
anonymous's picture

By Michelle Howie

15/7/21

  • arduino
  • iot

Use SMS to control your IoT device

In this blog, we look at how to use SMS commands from the Telstra Messaging API to control your IoT...
anonymous's picture

By Michelle Howie

2/7/21

  • iot
  • arduino

Changes to our IoT Developer Kit offer

The IoT Marketplace and Developer Kit trial were retired in July 2021.    Where we...
anonymous's picture

By Alan Quayle

18/5/21

  • iot
  • REST API

Unlocking the IoT: Telstra Track and Monitor API

As Australia’s longest serving telco, Telstra is expanding their developer program to provide...
anonymous's picture

By Sri Amirthalingam

31/3/21

  • iot
  • regional

Your regional mobile coverage questions answered

When developing an IoT solution for your business, coverage and access to a reliable network is crit...
anonymous's picture

By Michelle Howie

23/12/20

  • TDev
  • documentation

TelstraDev End of Year Wrap: 2020

We made it! Welcome to the end of 2020, may it soon be just a distant memory. Though it wasn’t...
iot home garden project with arduino and azure
anonymous's picture

By keith coutlemanis

10/11/20

  • arduino
  • azure

Azure IoT garden project with Arduino

In this blog, I'll showcase some of the interesting things you can do with the Internet of Thing...