Get neighbourhood weather data ... without owning a weather station.

123

Senior Member
If you don't own a weather station but need weather data, measured in your neighbourhood, Weather Underground's Personal Weather Station service might be of interest to you.

Weather Underground's Personal Weather Station (PWS) service collects weather data from private weather stations located in the USA, Canada, and in many other countries. The raw data is available via an XML feed, formatted charts, and a near-real-time display. With a little elbow-grease, you can probably create a PWS driver for your Home Automation program.

I live in a suburb of a major city. There are three PWS stations in my neighbourhood, all within two miles of my home. There's a good chance there's a PWS close to you.

XML Feed
The first step is determine if there is a private weather station in your neighbourhood. Go to the following URL and locate the nearest station: http://www.wunderground.com/weatherstation/index.asp

Make a note of the station's "Station ID". For example, "KNYBUFFA16" is for a station near Buffalo. Here is the URL to the station's weather data:
Code:
http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KNYBUFFA16
Charts
A station's weather data is also available in charts. Here's the URL that displays several charts for a given day (for KNYBUFFA16):
Code:
http://www.wunderground.com/cgi-bin/wxStationGraphAll?day=28&year=2009&month=10&ID=KNYBUFFA16&type=3&width=500&showtemp=1&showpressure=1&showwind=1&showwinddir=1&showrain=1
Here's how the URL works.
Indicate the date.
&day=28
&year=2009
&month=10


Specify the Station ID.
&ID=KNYBUFFA16

Specify the chart type, where 1=Month, 2=Week, 3=Day, 4=ThreeMonths, 5=SixMonths, and the width in pixels.
&type=3
&width=500


Specify which charts to display where 1=Enable 0=Disable
&showtemp=1
&showpressure=1
&showwind=1
&showwinddir=1
&showrain=1
&showsolarradiation=1


Near Real-time Display
The following URL leads to a Flash widget that displays weather data in near real-time:
Code:
http://www.wunderground.com/swf/Rapid_Fire.swf?units=metric&station=KNYBUFFA16
To view the data in Imperial units, simply remove "units=metric" from the URL.
 
Great information! I appreciate you walking through the XML codes. I'll be able to use that information to get local feeds into CQC with this.

Thanks,
 
Thanks! I regulary troll the CQC forum for tips (I used the URL to Bing's interactive Weather Map) so it's about time to return the favour. :)

I'm unfamiliar with CML so I can't provide a tailored example of parsing XML. However, here's one from Premise that uses Microsoft's XMLDOM object. Hopefully it is similar to the way CML parses XML.

There's certainly more than one way to glean XML data and I simply loop through the nodes. The displayed sample has been stripped of repetitive code for clarity. The attached file contains all of the code.
Code:
'
dim NoTemperature: NoTemperature = -274

set oXML = CreateObject("Microsoft.XMLDOM") 
oXML.validateOnParse = false 
oXML.async = false

sURL = "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=" & this.GetStationID

err.clear
on error resume next
this.Status = "Acquiring weather data ..."
If oXML.Load(sURL) Then
	' Get Current Conditions
	for each oNode in oXML.GetElementsByTagName("current_observation")
		for each oChild in oNode.childNodes
			with oChild
				select case .nodeName
					case "observation_time":
						if .text <> empty then
							sNodeValue = .text
							set oRegEx = new RegExp
							with oRegEx
								.ignoreCase = true
								.global = true
								.pattern = "[0-9]*:[0-9]* [A|P]M"
								set oMatches = .Execute(sNodeValue)
								if oMatches.Count > 0 then
									this.ObservationTime = cdate(oMatches(0).Value)
								end if
							end with
							set oMatches = nothing
						set oRegEx = nothing
						end if

					case "observation_time_rfc822":
						...
						
					case "temp_f":
						if .text <> empty then
							Value = .text
						else
							Value= NoTemperature
						end if
						this.Temperature.Fahrenheit = Value
					
					case "relative_humidity":
						...
					case "wind_dir":
						...										
					case "wind_degrees":
						...					
					case "wind_mph":
						if .text <> empty then
							Value = .text
							this.WindSpeed.FeetPerSecond = this.MPHtoFPS(Value)
						else
							this.WindSpeed.FeetPerSecond = -1
						end if
					
					case "wind_gust_mph":
						...
					case "windchill_f":
						...
					case "heat_index_f":
						...						
					case "pressure_mb":
						...
					case "dewpoint_f":
						...					
					case "solar_radiation":
						...
					case "UV":
						...					
					case "precip_1hr_in":
						...
					case "precip_today_in":
						...
				end select
			end with
		next
	next

	...						
else
	this.Status = "Error. Unable to acquire weather data."
end if

if err.number <> 0 then 
	this.Status = "Error. An error occurred while processing the weather data."
end if
on error goto 0
 

Attachments

  • PWS_Data_Parser.txt
    4.3 KB · Views: 19
Back
Top