How to Build an Air Quality Alerting System with n8n
What You Will Learn
In this tutorial-style guide, you will learn how to build an automated Air Quality Alerting System using n8n, an open-source workflow automation platform.
By the end, you will understand how to:
- Schedule a workflow to run automatically every few minutes
- Fetch live air quality data from the OpenAQ API
- Format and calculate an AQI value from pollutant data
- Send processed measurements to an AWS SQS queue
- Check an AQI threshold and decide when to alert
- Post detailed alerts into a Slack channel when air quality worsens
This guide focuses on Los Angeles as an example city, but you can easily adapt it to any location supported by OpenAQ.
Why Automate Air Quality Monitoring with n8n?
Monitoring air quality is important for public health, especially in cities that experience frequent pollution events. Manual checks are easy to forget and do not scale well. With n8n you can:
- Run checks in near real time without manual effort
- Centralize data collection in a queue for later analysis
- Alert teams instantly when conditions become unhealthy
- Extend the workflow as your needs grow
The workflow you will build fetches live data, processes it, stores it, and sends alerts when pollution crosses a defined threshold.
Conceptual Overview of the n8n Workflow
Before we dive into configuration steps, it helps to understand how the workflow is structured in n8n. At a high level, the automation follows this pattern:
- Scheduled Trigger – A Cron node runs the workflow every 5 minutes.
- Fetch AQI Data – An HTTP request retrieves the latest OpenAQ data for Los Angeles.
- Format AQI Record – A Set node extracts key fields and calculates an AQI value.
- Send to AWS SQS – The formatted record is serialized to JSON and pushed into an SQS queue.
- Check AQI Threshold – An IF node checks whether AQI is above 100.
- Alert Environment Channel – A Slack node posts an alert if the threshold is exceeded.
Each step is handled by a specific n8n node, which makes the workflow easy to read, debug, and extend.
Prerequisites
To follow along and implement this air quality alerting system, you will need:
- n8n installed and running (self-hosted or cloud)
- AWS credentials with permission to send messages to an SQS queue
- An AWS SQS queue, for example named
aqi-ingest-queue - A Slack app with permissions to post messages into your chosen channel
- Access to the OpenAQ API (public and free at the time of writing)
Once you have these in place, you can create the workflow in n8n step by step.
Step-by-Step: Building the Air Quality Alerting Workflow in n8n
Step 1 – Configure the Scheduled Trigger (Cron Node)
The first node is responsible for starting the workflow at regular intervals.
- Add a Cron node to your workflow.
- Set the schedule to run every 5 minutes. For example:
- Mode:
Every X minutes - Value:
5
- Mode:
This node ensures near real-time monitoring without requiring you to manually click “Execute” in n8n.
Step 2 – Fetch Air Quality Data from OpenAQ
Next, you will retrieve the most recent air quality measurements from OpenAQ.
- Add an HTTP Request node (or a dedicated OpenAQ node if available in your n8n version).
- Configure it to call the OpenAQ API endpoint that returns measurements for Los Angeles.
- Set query parameters so that:
- The results are limited to the latest single record.
- You filter for the pollutant parameters PM2.5, PM10, and O3.
The response will typically include location information, timestamps, and pollutant concentrations. This raw data is what you will process in the next node.
Step 3 – Format and Enrich the AQI Record
Now you will extract the fields you care about and compute a simple AQI value.
- Add a Set node after the HTTP Request node.
- Use it to:
- Pick out the location details from the API response.
- Extract the pollutant concentrations for PM2.5, PM10, and O3.
- Capture latitude and longitude for geo-referencing.
- In the same node (using expressions or additional fields), calculate an AQI value:
- Apply a multiplier of
4.17to the PM2.5 concentration to derive a basic AQI. - If the PM2.5 value is unavailable, default the AQI to 50.
- Apply a multiplier of
This step turns the raw OpenAQ payload into a structured record that is easier to store, analyze, and display in alerts.
Step 4 – Send Processed Data to AWS SQS
With a clean record in hand, you can now send it to an AWS SQS queue for further processing or logging.
- Add an AWS SQS node.
- Configure your AWS credentials in n8n if you have not already.
- Set the target queue name to
aqi-ingest-queue(or your chosen queue name). - Serialize the formatted data into JSON and use it as the message body.
Storing the data in SQS decouples data ingestion from alerting. Other systems can read from the queue to batch process, archive, or analyze historical air quality trends without affecting this workflow.
Step 5 – Check the AQI Threshold with an IF Node
Next, you will decide whether the current air quality should trigger an alert.
- Add an IF node after the SQS node (or directly after the Set node, depending on your preferred sequence).
- Configure a condition that checks if:
- AQI > 100
An AQI over 100 is commonly used as a cutoff where air quality moves from moderate into unhealthy for sensitive groups. If the condition is met, the workflow follows the “true” path to send an alert. If not, the workflow ends quietly without any notification.
Step 6 – Send an Alert to a Slack Channel
When the threshold is exceeded, you want your team or community to know quickly.
- On the “true” branch of the IF node, add a Slack node.
- Connect your Slack credentials or use an existing Slack integration in n8n.
- Choose the target channel, for example an environment or alerts channel.
- Compose a detailed message that includes:
- The location and timestamp
- The calculated AQI value
- Individual pollutant concentrations for PM2.5, PM10, and O3
- A short health advisory based on the AQI level, such as advising sensitive groups to limit outdoor activity
This Slack node becomes the visible part of your system, turning raw sensor data into actionable information for your audience.
Benefits of This Automated n8n Air Quality System
Once the workflow is live, you gain several advantages:
- Timely alerts – The Cron node checks every 5 minutes so you get near real-time warnings as conditions change.
- Reliable data storage – Using AWS SQS provides a scalable buffer for all processed records, which is ideal for later analysis or integration with other services.
- Easy scalability – You can duplicate or extend nodes to support multiple cities or additional pollutants without redesigning the system.
- Flexible alerting – Slack message formatting is fully customizable, so you can tailor alerts for technical teams, public channels, or other platforms.
Next Steps and Extensions
After your basic air quality alerting system is running, you can build on it with more advanced features:
- Historical data logging – Add a database node to store each record for long-term trend analysis.
- Multi-channel notifications – Extend the alert branch to include email or SMS for critical AQI levels.
- More advanced AQI calculations – Incorporate multiple pollutants and more detailed formulas to improve accuracy.
- Dashboards and visualizations – Connect the data in SQS or your database to a BI tool to create live monitoring dashboards.
Each of these enhancements can be added as extra nodes or branches in the same n8n workflow.
Quick Recap
To summarize, your n8n air quality alerting workflow:
- Uses a Cron node to trigger every 5 minutes.
- Calls the OpenAQ API to fetch the latest Los Angeles measurements for PM2.5, PM10, and O3.
- Formats the response with a Set node, calculates an AQI using a 4.17 multiplier on PM2.5, and captures location and coordinates.
- Sends the structured data as JSON to an AWS SQS queue named
aqi-ingest-queue. - Uses an IF node to check if AQI is greater than 100.
- Posts a detailed alert to a Slack channel if the threshold is exceeded.
FAQ
Can I monitor a different city instead of Los Angeles?
Yes. Update the parameters in the node that calls the OpenAQ API to use your target city or coordinates. The rest of the workflow can remain the same.
Do I have to use AWS SQS?
No. SQS is used here to provide scalable message buffering and decouple ingestion from processing. You can replace it with a database, another queue system, or skip it if you only need alerts.
Is the AQI calculation accurate?
The example uses a simple multiplier of 4.17 on PM2.5 and defaults to 50 when PM2.5 is missing. This is a simplified approach. For production use, you may want to implement a more detailed AQI formula that considers multiple pollutants.
Can I send alerts to other platforms besides Slack?
Yes. n8n supports many integrations. You can add nodes for email, SMS, incident management tools, or other messaging apps alongside or instead of Slack.
Start Building Your Air Quality Alert System
With n8n, you can automate air quality monitoring, protect public health, and stay informed with minimal ongoing effort. Once you have your prerequisites ready, configure each node, test the workflow, then activate it so it runs on schedule.
Explore the n8n documentation and the AWS and Slack integrations to customize this workflow for your specific needs and audience. Small adjustments to thresholds, locations, or alert messages can tailor the system for local communities, workplaces, or city-wide monitoring projects.
If you find this kind of automation helpful, share the idea with your tech community and help raise awareness about clean air initiatives.
