appscript.dev
Automation Beginner Gmail

Build a weather-driven alert system

Trigger Northwind actions on forecast conditions — e.g., snow-day email to remote workers.

Published Aug 20, 2025

Northwind’s London studio runs a hybrid week, but bad weather changes the plan. When heavy snow is forecast, someone has to remember to email the team and tell them to work from home — and that someone usually remembers at 8am, by which point half the studio is already on a delayed train.

This script moves the decision to the night before. It checks tomorrow’s forecast against a threshold and, if snow is likely, sends one clear email so everyone wakes up knowing the plan. It uses Open-Meteo, a free weather API that needs no API key, so the whole thing is a single scheduled function.

What you’ll need

  • A Gmail account that can send to your team — the script sends from whoever owns the Apps Script project.
  • The latitude and longitude of the location you want to watch. The script ships with London’s coordinates; swap in your own.
  • Nothing else. Open-Meteo is free and keyless, so there is no setup beyond pasting the script.

The script

// Location to check — Northwind's London studio.
const LATITUDE = 51.5;
const LONGITUDE = -0.12;
const TIMEZONE = 'Europe/London';

// Snowfall threshold in centimetres. Tomorrow's forecast has to clear
// this before an alert goes out — see "Watch out for" for tuning.
const SNOW_THRESHOLD_CM = 2;

// Where the snow-day alert is sent.
const TEAM_EMAIL = '[email protected]';

/**
 * Checks tomorrow's snowfall forecast and emails the team if it
 * crosses the threshold. Designed to run once a day on a trigger.
 */
function checkLondonWeather() {
  // 1. Build the Open-Meteo request. "daily=snowfall_sum" returns one
  //    total per day; "timezone" makes day boundaries align with London.
  const url =
    'https://api.open-meteo.com/v1/forecast' +
    '?latitude=' + LATITUDE +
    '&longitude=' + LONGITUDE +
    '&daily=snowfall_sum' +
    '&timezone=' + encodeURIComponent(TIMEZONE);

  // 2. Fetch the forecast and parse the JSON response.
  const res = JSON.parse(UrlFetchApp.fetch(url).getContentText());

  // 3. The daily array is ordered today, tomorrow, day after... so
  //    index 1 is tomorrow. Default to 0 if the field is missing.
  const snow = (res.daily && res.daily.snowfall_sum[1]) || 0;
  Logger.log('Forecast snowfall for tomorrow: ' + snow + 'cm');

  // 4. Below the threshold? Nothing to do — no email on a clear day.
  if (snow <= SNOW_THRESHOLD_CM) return;

  // 5. Snow is likely — send one alert so everyone has the same plan.
  GmailApp.sendEmail(
    TEAM_EMAIL,
    'Snow day forecast',
    'Tomorrow looks like ' + snow + 'cm of snow. Default to remote — ' +
    'no need to come into the studio.'
  );
  Logger.log('Snow-day alert sent.');
}

How it works

  1. checkLondonWeather builds an Open-Meteo URL from the configured coordinates, asking for snowfall_sum — a single total per day. The timezone parameter makes “tomorrow” line up with the London calendar rather than UTC.
  2. It fetches the URL with UrlFetchApp and parses the JSON reply.
  3. The daily.snowfall_sum array is ordered from today onwards, so index 1 is tomorrow’s forecast. The script logs the value so you can see what it saw even when no email goes out.
  4. If the figure is at or below SNOW_THRESHOLD_CM, the function returns quietly — the team only hears from it when there is something to act on.
  5. When the threshold is crossed, it sends one plain-text email telling everyone to default to remote.

Example run

Open-Meteo returns a daily block like this:

{
  "daily": {
    "time": ["2025-08-20", "2025-08-21"],
    "snowfall_sum": [0, 4.5]
  }
}

Tomorrow’s value is 4.5cm, which clears the 2cm threshold, so the team receives:

FieldValue
To[email protected]
SubjectSnow day forecast
BodyTomorrow looks like 4.5cm of snow. Default to remote — no need to come into the studio.

On a dry day snowfall_sum[1] is 0, the function returns at step 4, and no email is sent.

Trigger it

This should run itself every evening so the team has the plan before bed:

  1. In the Apps Script editor, open Triggers (the clock icon).
  2. Click Add Trigger.
  3. Choose checkLondonWeather, event source Time-driven, type Day timer, and set the hour to 6pm to 7pm.
  4. Save and approve the authorisation prompt.

From then on the script checks the forecast each evening and emails the team only when snow is on the way.

Watch out for

  • Forecasts change. A 6pm check can disagree with the morning reality — snow that was forecast may not fall, and vice versa. Treat the email as a heads-up, not a guarantee.
  • snowfall_sum is the figure that triggers the alert. To react to other conditions — heavy rain, high wind, extreme heat — swap in the matching Open-Meteo daily variable (precipitation_sum, wind_speed_10m_max, temperature_2m_max) and adjust the threshold to suit.
  • The threshold is a blunt instrument. 2cm is a sensible default for a city studio, but tune SNOW_THRESHOLD_CM to how disruptive snow actually is for your team and commute.
  • Open-Meteo is free for reasonable use but rate-limited. One call a day is comfortably within limits; do not loop it.
  • The email sends from whoever authorised the script, and consumer Gmail caps daily sends. One message a day is nowhere near that cap, but keep it in mind if you extend the script to email people individually.

Related