Schedule icon
Queries icon
Fail icon
Download icon
Get icon
Set icon
If icon
Loop icon
Switch icon
Return icon
SlackIncomingWebhook icon
Log icon

Alert on USGS Stream Gauges Crossing NWS Action and Flood Stage, with Rate of Rise and Stale-Data Detection

Watch USGS gauges every 15 minutes against NWS action and flood stage, with rate of rise, stale-data detection, KV state and Slack alerts on change only.

Categories
Data

A river crossing its action or flood stage is the moment someone has to move equipment, close a road or call a levee crew, and the USGS publishes the gage height of thousands of stream gauges within minutes of the reading. The NWS publishes the stage at which each gauge becomes a concern. This flow joins the two: it reads the last six hours of gage height and discharge for your gauges in a single request to the USGS Water Data OGC API, computes the latest stage, how fast it is moving and how much it changed, compares it with the thresholds you give per gauge, and alerts in Slack when a gauge enters or leaves action stage, flood stage or a data gap. Severity is kept in the KV store so a river sitting above flood stage for two days alerts once, not two hundred times, and every evaluation is appended to a rolling history CSV.

How it works

  1. A Schedule trigger runs every 15 minutes (recoverMissedSchedules: LAST, so a restart replays only the latest missed run), and concurrency.limit: 1 keeps two runs from racing on the KV state.
  2. prepare_sites (DuckDB) normalises the sites JSON input: trims ids, accepts USGS-02228000 or 02228000, keeps the first entry of a duplicated site and separates malformed ids (not 8 to 15 digits), which the API would silently answer with nothing. require_sites (Fail) stops the run if no valid id is left.
  3. fetch_readings (HTTP Download) makes one request to the continuous collection for all gauges: monitoring_location_id as a comma list, parameter_code=00065,00060 (gage height in ft, discharge in ft³/s), time=PT6H, properties limited to the fields used and skipGeometry=true. fetch_locations makes one request to monitoring-locations for the official names; a site missing there does not exist. Both retry with exponential backoff and can send an API key.
  4. previous_state and previous_history (KV Get, errorOnMissing: false) read the last severity per gauge and the URI of the history CSV. Both are missing on the first run, the BASELINE run.
  5. evaluate (DuckDB) flattens the GeoJSON to one row per reading, drops readings without a numeric value (ice, equipment problems) and, when a gauge has more than one time series for a parameter, keeps the one with the newest reading. Per gauge it computes the latest stage and discharge, the age of the reading, the last-hour and 6-hour rates of change (least-squares slope in ft/h), the 6-hour change and peak, and the hours to flood stage at the current rate when rising. Severity is stale if there is no reading in six hours, the site does not exist or the reading is older than stale_minutes; otherwise flood, action or normal. A gauge in action or flood stays there until it drops hysteresis_ft below the threshold. A transition is a severity different from the stored one; on the baseline run every gauge that is not normal alerts once. The summary also flags a truncated response (a next page link).
  6. save_state and save_history (KV Set) store the new severities and point the history key at the new CSV, which keeps history_days of rows.
  7. alert_transitions (If) runs each_transition (Loop) over the gauges that changed. route_by_severity (Switch) writes a different message for each new severity: flood (stage over flood stage, trend, peak, discharge), action (adds the hours to flood stage at the current rate), stale (the reason and the last good reading), normal (back below action stage, or data restored after a gap). Each case posts to Slack with allowFailure, so a missing webhook warns instead of failing. log_alerts prints every message in the parent execution. With no transition, no_transitions logs one status line.
  8. warn_invalid_sites names the malformed ids, summary logs the counts, and errors posts to Slack if the run itself fails, because the gauges are unwatched until it recovers.

What you get

  • Slack alerts on state changes only, with stage, threshold, rate of rise, 6-hour change and peak, discharge, observation time and links to the USGS and NWS gauge pages.
  • A per-gauge CSV per run (severity, previous severity, since, stale reason, hysteresis flag, stage, discharge, rates, peak, hours to flood, number of readings) and a rolling history CSV for charts or post-event review, both as flow outputs.
  • Stale-data alerts for gauges that stop reporting, and an explicit "no such USGS site" for a wrong site number, so a silent gauge is never read as a calm river.
  • Hysteresis so a river hovering at the line does not flap.

Who it's for

  • Emergency management, public works and utility operations teams who act at specific river stages.
  • Facility, construction and agriculture operators with assets in a floodplain.
  • Hydrologists and data teams who want a reproducible stage-threshold feed without running a database.

Why orchestrate this with Kestra

  • Two HTTP calls and SQL replace a polling script: the classification, rates and hysteresis are readable in the flow.
  • The KV store keeps the severity per gauge and the history pointer, so alerting on change needs no database.
  • Loop plus Switch gives each severity its own message; paging on-call for flood only is one more task in one case.
  • Retries, concurrency and recoverMissedSchedules handle API hiccups and restarts; errors reports a broken check.

Prerequisites

  • Kestra 2.0 with the JDBC DuckDB plugin and the Slack plugin (io.kestra.plugin.slack.notifications.SlackIncomingWebhook).
  • Outbound HTTPS to api.waterdata.usgs.gov. No key is needed for two requests every 15 minutes; a free api.data.gov key raises the rate limit.
  • The thresholds for each gauge from its NWS gauge page (water.noaa.gov/gauges/<LID>, "Flood Categories"): action stage and minor flood stage, in feet of gage height at the USGS gauge.

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook for transition alerts and failure notices (optional; without it the Slack tasks warn and the check still runs).
  • USGS_API_KEY: api.data.gov key sent as X-Api-Key when use_api_key is true (optional).

Quick start

  1. Import the flow and click Execute with the defaults: Satilla River at Atkinson, GA (action 11 ft, flood 13 ft), Raccoon River at Des Moines (8 / 12 ft), Potomac at Little Falls (5 / 10 ft) and Mississippi at St. Louis (28 / 30 ft). On 19 October 2026 the baseline run found the Satilla in flood at 14.18 ft, the Raccoon at action stage at 8.32 ft and the other two normal, and alerted twice. Your result depends on the rivers today.
  2. Execute again: No state changes across 4 gauges.
  3. Add a site number that does not exist: it alerts once as stale with "no such USGS site". Add a malformed one such as 0222-800: warn_invalid_sites names it and it is not sent.
  4. Set stale_minutes to 10 to see the stale alerts, then run with the default to see the recovery messages.
  5. Replace the gauges with yours, add SLACK_WEBHOOK_URL and enable the schedule.

How to extend

  • Add moderate_ft and major_ft to the input and two more Switch cases, or page on-call for flood only.
  • Pull the thresholds from the NWS National Water Prediction Service API (api.water.noaa.gov/nwps/v1/gauges/<LID>) instead of typing them, and add its stage forecast to alert before the crossing.
  • Alert on rate of rise alone (rate_1h_ft_per_hr above a limit) for flashy creeks that go from normal to flood within an hour.
  • Load the history CSV into Postgres, BigQuery or a DuckDB file for dashboards.
  • The legacy USGS Water Services endpoint (waterservices.usgs.gov/nwis/iv/?format=json&sites=...&parameterCd=00065,00060&period=PT6H) answers the same question, but it is scheduled for shutdown on 22 February 2027 and in our tests it returned the latest readings about an hour later than the OGC API, so this flow uses the OGC API.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.