room
room
room
room

Weather station scripts

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at https://github.com/ktrue

Buy Me A Coffee If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on WXForum.net and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Tuesday, 28-Jul-2020 2:45 PM

PHP for NWS Area Forecast Discussion

This PHP script will fetch and cache the Forecast Area Discussion issued by your local NWS office.
Thanks to Mike Challis of Long Beach, WA for the inspiration for and enhancement of this script.

946
FXUS66 KMTR 201202
AFDMTR

Area Forecast Discussion
National Weather Service San Francisco CA
502 AM PDT Mon Apr 20 2026

...New AVIATION, MARINE...

.KEY MESSAGES...
Updated at 1210 AM PDT Mon Apr 20 2026

 - Cool temperatures and beneficial rainfall today through
   Wednesday

 - Isolated to scattered thunderstorms on Tuesday

 - Seasonal temperatures and dry conditions for the later part of
   the week

&&

.SHORT TERM...
Issued at 1210 AM PDT Mon Apr 20 2026
(Today and tonight)

High clouds continue to flow over the Bay Area and Central Coast
tonight, an outgrowth of the cold front that will make Monday a
pretty rainy day -- more on that a little bit later on. KMUX radar
is showing returns from the first rain band off the coast of the Bay
Area and Central Coast, and just now coming ashore in the
northwestern corner of Sonoma County. Southerly winds are prevalent
across the region as the front approaches, leading to some pretty
abnormal nocturnal drying across the Silicon and Santa Clara
valleys, where the southerly winds downslope from the Santa Cruz
Mountains into the region. To give just one example, at 4 PM Sunday
afternoon, San Jose reported a dew point of 48 degrees, a relative
humidity of 40%, and a light northwest breeze. By 9 PM, San Jose
reported a dew point of 8 degrees, a relative humidity of 11%, and a
gentle southerly wind, with gusts reaching 20-24 mph over the
previous couple of hours. Low temperatures this morning should hover
around the middle 40s to the lower 50s, downslope warming effects
notwithstanding, with the interior valleys and mountains dipping
into the middle 30s to lower 40s.

Looking into the big picture, a deep and large upper level low
drives a massive circulation across the eastern Pacific with a
pronounced and highly noticeable comma cloud wrapping up the
California and Oregon coastlines before diverting away from
Washington state into the Pacific. The 03Z, or 8 PM, WPC surface
analysis shows a closed circulation that spans the ocean off the
Central Coast all the way to offshore Washington State, and two
surface lows embedded in the comma cloud, one located around 600
miles west of Cape Mendocino and one around 550 miles west of where
the Columbia River empties into the Pacific Ocean, on the border
between Washington and Oregon. This is the system that will approach
the region through the night, increasing the cloud cover and placing
a few scout showers into the North Bay overnight before light to
moderate rain comes into the North Bay close to the end of the
morning commute on Monday. The rain will start to spread south and
east through Monday as the cold front approaches, with a messy
evening commute expected as rain spreads across the SF Bay Area and
Monterey Bay regions.

As the front approaches, southerly flow should ramp up as the
pressure gradient tightens, with the winds increasing across the
coastal regions through the morning before they spread inland during
the afternoon and evening hours. Winds are not expected to be strong
enough for a Wind Advisory, but wind gusts of 25 to 35 mph, possibly
up to 40 mph in favored coastal or ridgeline areas, are expected.
Given the southerly flow, initial rain chances may be delayed across
downslope and rain shadowed areas -- think the Petaluma region, the
Santa Clara Valley, or the interior Salinas Valley.

Highs in the North Bay will drop into the middle 50s to lower 60s in
the lower elevations, to the upper 40s to middle 50s across the
higher elevations, as the cold front passes through. South of the
Golden Gate, temperatures remain relatively mild with the continuing
warm sector influence and, for some areas, including the Monterey
area, enhancement from the southerly downslope flow. Highs range
from the middle 60s to the lower 70s in the SF Bayshore and Monterey
Bay regions, to the lower to middle 70s in the inland valleys.

&&

.LONG TERM...
Issued at 1210 AM PDT Mon Apr 20 2026
(Tuesday through Sunday)

With the frontal passage passing the Bay Area and Central Coast
Monday night through Tuesday morning, the stage is set for a rather
convective Tuesday afternoon and evening. The cold pool behind the
frontal passage and the arrival of the upper level low will
contribute to a destabilized atmosphere, while the placement of a
left exit region from a jet streak (a pattern that typically results
in upper level divergence) and potential low level shear provide
sources of lift. The latest SPC outlooks continue to place the Bay
Area and Central Coast in a general mention of thunderstorms for
Tuesday. If any storms do develop, lightning, localized heavy rain,
and small hail are the primary threats. Some lingering showers may
hang on through Wednesday afternoon as a shortwave trails behind the
upper level trough as it departs into the Intermountain West.

In total, rainfall totals today through Wednesday remain generally
beneficial, half an inch to an inch and a half in the lower
elevations, up to 3 inches in the coastal ranges and the North Bay
interior mountains. While there is no threat for widespread river
flooding, minor flooding is possible in urban and poor drainage
areas should particularly heavy showers or thunderstorms develop.

As the frontal system passes, temperatures will warm slightly into a
rather dry latter part of the week, close to or slightly below the
seasonal averages as highs in the lower elevations range from the
lower 60s to lower 70s. Ensemble model cluster analysis points to
continued troughing across the state which, if nothing else, should
help moderate the warming trend, particularly towards the latter
part of the 7-day outlook. Extended guidance from the Climate
Prediction Center leans towards temperatures and rain totals above
seasonal averages for the last days of April into the first days of
May.

&&

.AVIATION...
(12Z TAFS)
Issued at 502 AM PDT Mon Apr 20 2026

It`s VFR across the forecast area with exception KHAF reports
MVFR. The low pressure system offshore will approach the forecast
area with rain and breezy southerly winds today. As the cold core
low gets closer tonight and Tuesday it`ll result in occasionally
heavy rain showers and a chance of thunderstorms. It`s still early
to try to narrow the timing of thunderstorms, for now will wait
placing a mention of thunderstorm(s) in the 12z TAFs.

Vicinity of SFO...It`s VFR, the cloud ceiling will gradually
lower to MVFR with rain developing during the morning. Expect MVFR
in occasionally heavy showers tonight and Tuesday. South-southeast
winds 10 knots shifting to south-southwest in the afternoon then
light southeast wind tonight and Tuesday.

SFO Bridge Approach...Similar to SFO.

Monterey Bay Terminals...It`s VFR and with increasingly south-
southeast winds. Downsloping drying winds will occur while cloud
layers and rain with the eastern Pacific low advance to the coast.
Frontal convergence however will catch up to the coastline and
eventually diminish the downsloping drying, resulting in MVFR in
occasionally heavy showers later today, tonight, Tuesday.

&&

.MARINE...
(Today through Saturday)
Issued at 441 AM PDT Mon Apr 20 2026

Southerly winds will increase to a strong breeze through morning
before the cold front passes and winds shift to a moderate
southwesterly breeze by Tuesday. The front will also bring steady
rain today and showers and a chance of thunderstorms on Tuesday.
As the weather breaks, winds will gradually shift back to the
northwest Wednesday before increasing to a strong northwest breeze
by Thursday.

&&

.MTR WATCHES/WARNINGS/ADVISORIES...
CA...None.
PZ...Small Craft Advisory from 9 AM this morning to 9 PM PDT this
     evening for SF Bay N of Bay Bridge.

     Small Craft Advisory from 9 AM this morning to 3 AM PDT Tuesday
     for Mry Bay.

     Small Craft Advisory from 9 AM to 9 PM PDT Tuesday for Mry Bay.

     Small Craft Advisory until 9 PM PDT this evening for Pigeon Pt
     to Pt Pinos 10-60 NM-Pt Arena to Pt Reyes 0-10 nm-Pt Arena
     to Pt Reyes 10-60 NM-Pt Reyes to Pigeon Pt 0-10 nm.

     Small Craft Advisory until 3 AM PDT Tuesday for Pigeon Pt to Pt
     Pinos 0-10 nm-Pt Pinos to Pt Piedras Blancas 0-10 nm.

     Small Craft Advisory from 9 AM to 3 PM PDT Tuesday for Pt Pinos
     to Pt Piedras Blancas 0-10 nm.

&&

$$

SHORT TERM...DialH
LONG TERM....DialH
AVIATION...Canepa
MARINE...Canepa

Visit us at www.weather.gov/sanfrancisco

Follow us on Facebook, X, and YouTube at:
www.facebook.com/nwsbayarea
x.com/nwsbayarea
www.youtube.com/nwsbayarea

NWS MTR Office Area Forecast Discussion

To use, include the output of the script on your webpage by using

<?php
$doIncludeFD = true;
include("forecast-discussion.php"); ?>

to perform the include. Settings inside the script are:

// settings:
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
//
    $myNWS = 'MTR';   // San Francisco, NWS office
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
//
$cacheName = "forecast-discussion.txt"; // used to store the file so we don't have to // fetch it each time $refetchSeconds = 1800; // refetch every nnnn seconds
$cacheFileDir = './'; // default cache file directory // end of settings

The only required setting is for $myNWS which designates the local NWS office.
To find the 3-character abbreviation for your local NWS office for the $myNWS variable, follow these steps:

  1. Browse to www.weather.gov
  2. Use the search box on the left to search for your city, state
  3. Look at the URL in the 'Forecast Discussion' link near the bottom of the page
  4. Use the 3-character abbreviation is in the &issuedby=XXX parameter on the Forecast Discussion link (XXX will be your local office)
  5. put the XXX in the $myNWS = 'XXX'; statement

The script has two optional parameters when you call it by URL from your website::

inc=Y
Will return the contents without the surrounding <html><head></head><body> and </body></html> tags
cache=no
Will override the default $refetchSeconds=1800 so that the cache is refreshed immediately

NWS Area Forecast Discussion PHP script Demo and Download (1.06 - 27-Feb-2018 see history).

PHP for NWS CPC World Extremes

This script was originated by Michael of Relayweather.com and has been rewritten to use the NWS Climate Prediction Center's CSV file for world observations. The script does not produce output (other than HTML comments for status), so you are free to include it in a page, and format the text output as you desire. The script returns data in variables:

$omittedCountry (text list of countries excluded from $world high/low/precip scans)
Note: the setting $ignoreCountrys is the array of country names to to exclude
$worldhigh
$worldlow
$worldprecip

$selectedCountry (setting: country name for selected country high/low/precip)
Note: run http://your.site.com/worldextremes.php?list to see the list of country names to use
$countryhigh
$countrylow
$countryprecip

$usahigh (Note: for lower-48 USA states)
$usalow (Note: for lower-48 USA states)
$usaprecip (Note: for lower-48 USA states)

$selectedState (setting: USA state 2-character name abbreviation in settings area)
$selectState (a copy of $selectedState for compatibility with old stateextremes.php)
$statehigh
$statelow
$stateprecip

$reportDate (nicely formatted date of the report)
$stateReportDate (a copy of $reportDate for compatibility with old stateextremes.php)

You can run the script by using:

<?php
include_once("worldextremes.php");

print "<p>USA Extremes for $reportDate</p>\n";
print "<p>High Temperature<br/><br/>$usahigh</p>\n";
print "<p>Low Temperature<br/><br/>$usalow</p>\n";
print "<p>High Precipatation<br/><br/>$usaprecip</p>\n";
print "<p><small>Data courtesy of <a href=\"";
print "https://www.cpc.ncep.noaa.gov/products/cadb/";
print "\">NWS-CPC</a></small></p>\n";

?>

which produces this result (with live data):

USA Extremes for Sunday, April 19, 2026

High Temperature

97°F at Phoenix Airport, AZ
97°F at Phoenix Goodyear Ap, AZ

Low Temperature

-21°F at Middlesboro Bell County Ap, KY

High Precipatation

10.10in at Hampton Roads Executive Airport, VA

Data courtesy of NWS-CPC

The script has internal settings which you can adjust. If run in a Saratoga template, the cache file will be stored in the ./cache/ directory based on $SITE['cacheFileDir'] in Settings.php.

$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "worldextremesCache.txt";  
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600';
$reportDateFormat = "l, F j, Y"; // Day, Month d, yyyy 
$tUOM = '&deg;F'; // or ='' for no temperature unit display (display in C is default)
$rUOM = 'in';     // or ='' for no rain unit display (display in mm is default)
#
$ignoreCountrys = array('Antarctica','Greenland');     // for world extremes - exclude these country(s)
$ignoreStations = array('99KLRJ');     // list of stn_id (field 0) to ignore for bogus data
$tempDiffAllowed = 40; // max difference Tmax-Tmin (C) for valid data
$selectedCountry = 'Canada'; // for country max/min/precip in $country* variables
// note: the $usa* variables will have the min/max/precip for the lower-48 states
$selectedState   = 'CA';  // for USA state max/min/precip in $state* variables

Note that $cacheFileDir, $tUOM, $rUOM will use the Saratoga template Settings.php values if used in a Saratoga template.

NWS CPC One Day Extremes PHP script Download (5.04 - 28-Jul-2020 see history).

deformed-offering