This project will poll an AirVisual Pro device-specific API endpoint using a cron trigger and alert if the CO2 concentration or PM2.5 is above a configurable threshold. This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. You must have an AirVisual Pro device linked to an iqair.com account to make use of this respository.
The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Node.js - Install Node.js, including the NPM package management tool.
- Docker - Install Docker community edition
You will also need a Twilio account with Account SID and Auth Token.
To build and deploy your application for the first time, run the following in your shell:
sam build
sam deploy --guided
The following environment variables should be configured:
- TWILIO_ACCOUNT_SID: Your Twilio Account SID from the Twilio Console
- TWILIO_AUTH_TOKEN: Your Twilio Auth Token from the Twilio Console
- TWILIO_PHONE_NUMBER: Your Twilio Phone number in E164 format
- DESTINATION_ALERT_PHONE_NUMBER: Your destination alert phone number in E164 format
- AIR_QUALITY_API: The HTTPS URL to your AirVisual Node API obtained from your AirVisual devices dashboard in format https://www.airvisual.com/api/v2/node/{uniqueDeviceApiLink}
- PM2_LIMIT: PM2.5 limit in µg/m^3
- CO2_LIMIT: CO2 threshold in PPM (parts per million)
In your template.yaml, configure the cron expression desired for alerting. The alert text message will only be sent during the cron schedule if one of the measured values exceeds the threshold defined in the two limits. An example cron expression which checks every 15 minutes between 1300-2300 UTC during weekdays (MON-FRI) is provided.