A Google Apps Script that monitors temperature differences between two cities and sends Slack notifications when one becomes colder than the other.
- Checks temperatures every 10 minutes using OpenWeather API
- Logs temperature data to Google Sheets
- Sends Slack notifications only when the temperature relationship changes
Create a new Google Sheet where temperature data will be logged.
- In your Google Sheet, go to Extensions > Apps Script
- Delete any existing code
- Paste the code from
Code.gs - Save the project (name it whatever you want)
- Sign up at OpenWeatherMap
- Go to your API keys section
- Copy your API key (free tier allows 1,000 calls/day)
- Go to Slack API: Incoming Webhooks
- Create a new webhook for your workspace
- Select the channel where notifications should be posted
- Copy the webhook URL
- In the Apps Script editor, click the Settings icon (⚙️) in the left sidebar
- Scroll to Script Properties
- Add the following properties:
- In the Apps Script editor, select
createTriggerfrom the function dropdown - Click Run (
▶️ ) - Grant necessary permissions when prompted
- This creates a time-based trigger to run every 10 minutes
- Select
checkWeatherfrom the function dropdown - Click Run
- Check your Google Sheet for a new row with temperature data
- If this is the first run, no Slack message will be sent (needs a state change)
To monitor different cities, add/update these Script Properties:
CITY_1: The reference city (e.g., "New York", "London", "Tokyo")CITY_2: The comparison city (e.g., "Miami", "Paris", "Sydney")
Note: City names should match OpenWeather's city database.
- Every 10 minutes, the script fetches current temperatures for both cities
- It logs the data to your Google Sheet
- It compares the current state (is City 2 colder?) with the previous state
- If the relationship has changed, it sends a Slack notification
- The new state is saved for the next comparison
- OpenWeather Free Tier: 1,000 calls/day
- This script: ~144 calls/day (one per city, every 10 minutes)
- Headroom: ~712 calls/day remaining for other uses or shorter intervals