Skip to content

ezhil384/Weather_Alert_Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Daily Weather Automation Workflow

This respository contains an n8n workflow that automates daily weather tracking. It fetches real-time weather data for multiple cities, detects alert conditions (Rain, Snow, Heat, Frost), logs the data to a Supabase Postgres database and emails a formatted HTML summary.

Features

  • Multi-city support: loop through a configurable list of cities defined by latitude/longitude for precision.
  • Smart alerts: flags Rain/Snow, Heat (temperature ≥ 32°C), Frost (temperature < 0°C).
  • Robust error handling: continues processing remaining cities when one API call fails; sends a failure notification for that city.
  • Data persistence: logs structured records to Supabase including raw API response.

1. API Setup & Key Configuration

OpenWeatherMap

This workflow uses the OpenWeatherMap API (https://openweathermap.org/api).

  1. Sign up for a free OpenWeatherMap account and generate an API Key.
  2. In the n8n workflow, find the HTTP Request node that calls the current weather endpoint. Inside the "Query Parameters (JSON)" or params section, replace the placeholder with your API key:
{
	"lat": {{ $json.lat }},
	"lon": {{ $json.lon }},
	"appid": "YOUR_ACTUAL_API_KEY",
	"units": "metric"
}

Notes:

  • Use units: "metric" to receive temperatures in °C. For °F use imperial.

Configuring Cities

To add or remove cities, edit the first Code node (Cities with coordinates) in the workflow. Use the following format (JavaScript):

return [
	{ json: { city: "London", lat: 51.5074, lon: -0.1278 } },
	{ json: { city: "New York", lat: 40.7128, lon: -74.0060 } }
];

Each item must include city, lat, and lon.

2. Supabase Configuration

Create a Supabase project (https://app.supabase.com) and run this SQL in the editor to create the table:

create table weather_logs (
	id uuid default gen_random_uuid() primary key,
	run_at timestamp with time zone default now(),
	city text,
	temperature float,
	temperature_unit text,
	condition text,
	humidity int,
	wind_speed float,
	alert_type text,
	raw_response jsonb
);

Connect to Supabase from n8n by creating a Credential that includes your Project URL and Anon Key (Project Settings > API).

3. Email Configuration

The workflow uses the Gmail node to send daily summaries and error alerts.

Open the Gmail node(s) and configure your SMTP credentials:

  • Credential to connect with: Connect your gmail account by adding OAuth2 connection
  • To: your email address
  • Format: HTML

Test the connection before activating the workflow.

4. How to Import & Run

Import:

  1. Open your n8n instance.
  2. On the top-right menu of the canvas, select Import from File.
  3. Choose the provided workflow JSON file.

Test (manual run):

  1. Open the imported workflow on the canvas and click Execute Workflow.
  2. Watch the node executions, green is success. If a node fails, open its error output to debug.
  3. Check your email inbox for the summary and Supabase table for new rows.

Activate (schedule):

Toggle the Active switch to True to enable the schedule trigger (Schedule Trigger node). Recommended default: daily at 08:00 AM.

5. Workflow internals (node-by-node)

  • Cities with coordinates (Code): returns the array of cities to process.
  • HTTP Request (OpenWeatherMap): fetches the current weather for the city's lat/lon.
  • Function node (Normalize data): extracts fields (temperature, humidity, wind speed, condition), determines alert type (Rain, Snow, Heat, Frost) and shapes data for DB insertion.
  • Supabase node: inserts a row into weather_logs with raw_response stored as JSONB.
  • Summary text node: aggregates processed city results into a single HTML email body.
  • Email node: sends the summary to recipients.
  • Error Email node: receives failure details when a city's API call or a critical node fails.

6. Error handling

  • For per-city API calls and DB inserts, enable Continue On Fail (or catch errors in a Function node) so one failure doesn't stop the entire run.
  • Collect error details (city, error message, timestamp) and send a failure email via the Error Email node.

7. Troubleshooting

  • No email: verify SMTP host, credentials and spam folder.
  • Supabase insert fails: check table schema, RLS policies and that the n8n host can reach Supabase.
  • HTTP Request errors: verify lat/lon, API key and OpenWeatherMap rate limits.

Created: 2025-12-20

About

This respository contains an n8n workflow that automates daily weather tracking. It fetches real-time weather data for multiple cities, detects alert conditions (Rain, Snow, Heat, Frost), logs the data to a Supabase Postgres database and emails a formatted HTML summary.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors