Announcement

Collapse
No announcement yet.

Script to update Weather Underground

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to update Weather Underground

    Hi all,

    Below is a vb.net script (save it with a .vb extension) to update Weather Underground (WU) with local weather data. Since I used Oregon Scientific sensors with the RFXCom plugin, I did not have a direct way to upload sensor data to WU and therefore created this script. To use it, you need to have a WU account and station set up. You'll need to modify the script with your own station ID and password, along with the device IDs of your own weather devices. Since WU expect data based on specific units of measure, I had to use formulas to change the values RFXCom reports to ones that WU needs. Depending on how you have your devices configured, you may need to alter or eliminate those formulas. How WU expects data is explained here: http://wiki.wunderground.com/index.p...pload_Protocol.

    Cheers
    Al

    Code:
    Sub Main(Parms As Object)
    	'http://wiki.wunderground.com/index.php/PWS_-_Upload_Protocol
    
    	Dim Debug as Boolean = False
    	Dim logName As String = "WUnderground"				'set log name for HS log
    
    	Dim cDateTime As Date = Now.ToUniversalTime()		'retrieve current time and convert to UTC
    	If Debug Then hs.writelog(logName,CStr(cDateTime))
    	Dim sDateTime As String = cDateTime.ToString("yyyy-MM-dd+HH:mm:ss")	'change time to format required by WUnderground
    	sDateTime = Replace(sDateTime,":","%3A")							'URLEncode :
    	If Debug Then hs.writelog(logName,sDateTime)
    
    	Dim httpCommand As String = "/weatherstation/updateweatherstation.php?ID=ZZZZZZ&PASSWORD=xxxxxx"  'Change to use your own station ID and password
    	httpCommand = httpCommand & "&dateutc=" & sDateTime
    
    	If hs.DeviceString(513) <> "Communication Failure" Then httpCommand = httpCommand & "&winddir=" & CStr(hs.DeviceValueEx(513))
    	If hs.DeviceString(506) <> "Communication Failure" Then httpCommand = httpCommand & "&windspeedmph=" & CStr(CDbl(hs.DeviceValueEx(506) * 2.23694))
    	If hs.DeviceString(512) <> "Communication Failure" Then httpCommand = httpCommand & "&windgustmph="  & CStr(CDbl(hs.DeviceValueEx(512) * 2.23694))
    	If hs.DeviceString(519) <> "Communication Failure" Then httpCommand = httpCommand & "&tempf=" & Replace(CStr(CDbl((hs.DeviceValueEx(519) * 9/5) + 32)),",",".")
    	If hs.DeviceString(525) <> "Communication Failure" Then httpCommand = httpCommand & "&dailyrainin=" & CStr(CDbl(hs.DeviceValueEx(525) * 0.0393701))
    	If hs.DeviceString(505) <> "Communication Failure" Then httpCommand = httpCommand & "&baromin=" & CStr(CInt(hs.DeviceValueEx(505) * 0.029529988))
    	If hs.DeviceString(520) <> "Communication Failure" Then httpCommand = httpCommand & "&dewptf=" & Replace(CStr(CDbl((hs.DeviceValueEx(520) * 9/5) + 32)),",",".")
    	If hs.DeviceString(516) <> "Communication Failure" Then httpCommand = httpCommand & "&humidity=" & CStr(hs.DeviceValueEx(511))
    	If hs.DeviceString(516) <> "Communication Failure" Then httpCommand = httpCommand & "&uv=" & CStr(hs.DeviceValueEx(516))
    
    	httpCommand = httpCommand & "&softwaretype=hs"
    	httpCommand = httpCommand & "&action=updateraw"
    	If Debug Then hs.writelog(logName, httpCommand)
    
    	Dim info2 As String = hs.GetURL("weatherstation.wunderground.com",httpCommand,False,80)
    	If InStr(info2,"success") > 0 Then
    		hs.writelog(logName, "Succesfully Updated")
    	Else
    		hs.writelog(logName, info2)
    	End If
    End Sub
    Last edited by sparkman; January 20th, 2016, 09:07 PM.
    HS 3.0.0.548: 1965 Devices 1146 Events
    Z-Wave 3.0.1.262: 122 Nodes on one Z-Net
Working...
X