Public
Cron
Readme

AQI Alerts

Get push notification alerts via Gotify when AQI is unhealthy near you.

Set up

  1. Click Fork
  2. Change location (Line 7) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via nominatim's geocoder API.
  3. Create an app in your Gotify Server and add your message endpoint URL w/ the app's API key (e.g., "https://push.example.de/message?token=") as a Val Town Secret named "gotifyWebhookURL".
  4. Click Run

Background

This val uses nominatim's geocoder to get your lat, lon, and air quality data from OpenAQ. It uses EPA's NowCast AQI Index calculation and severity levels. Learn more: https://www.val.town/v/stevekrouse.easyAQI

Runs every 1 hrs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import process from "node:process";
export async function aqiPushGotify(interval: Interval) {
const location = "Portland, Oregon"; // <-- change to place, city, or zip code
const data = await easyAQI({ location });
if (!interval.lastRunAt) {
const res = await fetchJSON(process.env.gotifyWebhookURL, {
method: "POST",
body: JSON.stringify({
"message": `You're now receiving AQI notifications!`,
}),
});
return res;
}
if (data.severity.includes("Unhealthy")) {
const res = await fetchJSON(process.env.gotifyWebhookURL, {
method: "POST",
body: JSON.stringify({
"message": `AQI in ${location} is ${data.aqi}`,
"priority": 7,
}),
});
return res;
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
November 15, 2023