Weather information on your Control Panel.

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

Jim is working on a plugin called WeatherReport - http://www.cebotics.com/phpbb2/viewtopi ... eport#1282



I also put together a quick script to download weather data from TWC (free registration required) and display images on my remote as dynamic images. This isn't documented so you'll have to read through the code to figure out how to setup a 'Weather' device but you should get the general idea.

Code: Select all

'	Set folder location of Weather.com icons and downloaded images
DestFolder = "c:\Program Files\HouseBot\Config\Themes\Common\weather\"

'	Weather.com partner ID
WeatherComPar = "xxxxxxxx"

'	Weather.com key
WeatherComKey = "xxxxxxxx

'	Get weather for this postal code
WeatherComZip = "xxxxx"


Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1 

Set xml = CreateObject("Microsoft.XMLHTTP")
set oStream = createobject("Adodb.Stream")
oStream.type = adTypeBinary

Set MSXML = CreateObject("MSXML.DOMDocument")
MSXML.Async = False
MSXML.preserveWhiteSpace = False
MSXML.validateOnParse = True
MSXML.resolveExternals = False
XMLURL = "http://xoap.weather.com/weather/local/" + WeatherComZip + "?cc=*&prod=xoap&par=" + WeatherComPar + "&key=" + WeatherComKey + "&dayf=5"


'	Get weather images and update device properties
'	(customize this for your own use)
getImage "http://image.weather.com/web/radar/us_atl_metroradar_large_usen.jpg", "W_radar"
getImage "http://image.weather.com/images/sat/regions/southeast_sat_720x486.jpg", "W_sat"

set oStream = nothing
Set xml = Nothing


Loaded = MSXML.Load(XMLURL)
If (Loaded) Then
	SetPropertyValue "Weather.W_cc_lsup", MSXML.SelectSingleNode("/weather/cc/lsup").text
	SetPropertyValue "Weather.W_cc_tmp", MSXML.SelectSingleNode("/weather/cc/tmp").text + "°F"
	SetPropertyValue "Weather.W_cc_flik", MSXML.SelectSingleNode("/weather/cc/flik").text + "°F"
	SetPropertyValue "Weather.W_cc_t", MSXML.SelectSingleNode("/weather/cc/t").text
	SetPropertyValue "Weather.W_cc_icon", DestFolder + MSXML.SelectSingleNode("/weather/cc/icon").text + ".png"
	SetPropertyValue "Weather.W_cc_bar_r", MSXML.SelectSingleNode("/weather/cc/bar/r").text
	SetPropertyValue "Weather.W_cc_bar_d", MSXML.SelectSingleNode("/weather/cc/bar/d").text
	SetPropertyValue "Weather.W_cc_wind", "From the " + MSXML.SelectSingleNode("/weather/cc/wind/t").text + " at "+ MSXML.SelectSingleNode("/weather/cc/wind/s").text + " mph"
	SetPropertyValue "Weather.W_cc_hmid", MSXML.SelectSingleNode("/weather/cc/hmid").text + "%"
	SetPropertyValue "Weather.W_cc_vis", MSXML.SelectSingleNode("/weather/cc/vis").text
	SetPropertyValue "Weather.W_cc_uv", MSXML.SelectSingleNode("/weather/cc/uv/i").text + " " + MSXML.SelectSingleNode("/weather/cc/uv/t").text
	SetPropertyValue "Weather.W_cc_dewp", MSXML.SelectSingleNode("/weather/cc/dewp").text + "°F"
	SetPropertyValue "Weather.W_dayf_lsup", MSXML.SelectSingleNode("/weather/dayf/lsup").text

	Set NodeList = MSXML.documentElement.selectNodes("/weather/dayf/day") 
	For Each Node In NodeList
		SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_t", Node.attributes.getNamedItem("t").nodeValue
		SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_dt", Node.attributes.getNamedItem("dt").nodeValue
		SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_hi", Node.selectSingleNode("hi").text + "°F"
		SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_low", Node.selectSingleNode("low").text + "°F"

		set PartList = Node.selectNodes("part")
		For Each Part In PartList
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_icon", DestFolder + Part.selectSingleNode("icon").text + ".png"
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_t", Part.selectSingleNode("t").text
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_wind_s", Part.selectSingleNode("wind/s").text + "mph"
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_wind_gust", Part.selectSingleNode("wind/gust").text
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_wind_d", Part.selectSingleNode("wind/d").text
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_wind_t", Part.selectSingleNode("wind/t").text
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_ppcp", Part.selectSingleNode("ppcp").text + "%"
			SetPropertyValue "Weather.W_dayf_day" + Node.attributes.getNamedItem("d").nodeValue + "_part" + Part.attributes.getNamedItem("p").nodeValue + "_hmid", Part.selectSingleNode("hmid").text + "%"
		Next
	Next

End If


Sub getImage(URL, PropName)
	DirArray = Split(URL, "/")
	ImageFile = DirArray(UBound(DirArray))
	xml.Open "GET", URL, False
	xml.Send
	oStream.open
	oStream.write xml.responseBody
	oStream.savetofile DestFolder & ImageFile, adSaveCreateOverWrite
	oStream.close
	SetPropertyValue "Weather." + PropName, DestFolder + ImageFile
End Sub


Click these thumbnails for bigger pictures:

Image Image
gorfllub
Member
Posts: 40
Joined: Tue Feb 10, 2004 11:24 pm

Post by gorfllub »

That is Fantastic! That is pretty much exactly what I want to do (Except that site isnt set up well for Canada)





Anyhow, Knowing absolutey nothing about scripts, I have a couple of questions:





1st, can you advise an FAQ somewhere to get the lowdown on scripting?



2nd, What type of file would that script be? I save it as an .EXE and I have tried a .JAR and it does some things when I execute it, but always comes up with errors and such......



I understand this scripting thing is a long conversation in its own self, but I certainly appreciate any knowledge that can be passed along.



Thanks
kbosscawen
Member
Posts: 71
Joined: Thu Jul 03, 2003 8:53 am
Location: Raleigh, NC
Contact:

Post by kbosscawen »

acheslow - I agree with gorfllub - This is a great script, and I plan to use it until the plug in is ready. I have a question on the Weather device set up, though...



When you set up the device, did you add properties to HB's property list, or just use the User definable ones that are already there. From the script it looks like there are many, many properties - I'm not sure I can find that many user definable already in HB.



Would you be willing to export your Weather device and either post it here or email it to me ([email protected])?



Scott: What do you think of having a script area where people can post scripts that may be useful for those of us who either only have VBS available to us or aren't that programmatically inclined?
ScottBot
Site Admin
Posts: 2790
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post by ScottBot »

kbosscawen wrote:Scott: What do you think of having a script area where people can post scripts that may be useful for those of us who either only have VBS available to us or aren't that programmatically inclined?
I'm open to changing the site to meet whatever demands HouseBot needs. There's only been a small handful of great scripts that I've seen (this is one of them). Many times the script works directly with another Device or specific Properties, so it may be better to actually do a configuration export of the Script Device (and script file). I can include the export file in the existing configuration sample section.



If user contributions increase, I may add a method for users to simply upload their work directly to the site. That has its advantages and disadvantages as you might be able to guess. For now, just let me know if you want to share something and send it to me.
Scott
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

Ok give me a little time and I'll do an export of the configuration including the script and hopefully a little documentation. Look for it hopefully by early next week.
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

OK here is a link to the export. Scott, feel free to download this and put it in your site somewhere. I'll continue to host it on my site as well. I hope this works out OK, please let me know if anyone has any problems or needs help.
ScottBot
Site Admin
Posts: 2790
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post by ScottBot »

Alan,



Thanks! I made one minor modification to the export (hope you don't mind). Your path to the script file included your machine name so the export process didn't escape it with the HouseBot path (something it does to resolve differences in file locations between different machines).



I've posted it in the configuration samples.



Thanks again.
Scott
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

Thanks Scott, I updated the download on my site too.
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

I've updated the download on my site to include a sample theme which makes use of many of the Weather device properties.



http://www.cheslow.com/modules.php?op=m ... load&cid=3
smillar
Member
Posts: 1
Joined: Wed May 05, 2004 10:00 pm
Location: Bradford, ON

Canadian Weather

Post by smillar »

Any idea how to get around the Zip Code request for TWN. I can't seem to get weather for Toronto, or Barrie, Ontario.



Since neither have a U.S. Zip...any suggestions?
acheslow
Senior Member
Posts: 168
Joined: Wed Aug 20, 2003 3:23 pm
Location: Bothell, WA
Contact:

Post by acheslow »

markd
Advanced Member
Posts: 234
Joined: Fri Jul 21, 2006 4:32 pm

Post by markd »

I found it a pain to make the weather device, so if anyone is looking, here is a start. (I didn't do all the variables- for instance I only needed one days forecast) Hope it helps someone.

Markd
Attachments
Weather_device.hbx
(1.13 KiB) Downloaded 393 times
Post Reply