friedmanwd
Jan 24, 2010, 04:24 PM
My HCA is linked to an Elk M1 security system which in turn is linked to the Air Conditioning system. When it is very cold, I would like to put the AC system in a mode where it continually heats. I can do this already using the METAR weather data and actual temperatures. However, I would like to improve this based on the weather *forecast* - e.g. if the forecast temperature is below 10 degrees, put the AC into continous heat mode. Any suggestions how to achieve this simply?
friedmanwd
Sep 09, 2010, 03:51 PM
Solution outline using standard Windows XP only:
Get a text file with the forecast from NOAA
Use wscript/vbScript to parse the file to extract the forecast high/low temperatures
Produce a text file that contains HCA flags
Read the text file in HCA and take action depending on the state of the flags
This approach could also be adapted (for instance) to take action based on precipitation forecast. I'm omitting some detail with regard to paths etc as these will be particular to your environment.
GET THE TEXT FILE
This is easy to do with Windows XP's ftp appliation.
Create an ftp script (let's call it script.txt) that looks like this:
anonymous
email@gmail.com
ascii
cd data/forecasts/city/pa
get pittsburgh.txt
quitInvoke ftp from a script, like this:
cmd.exe -d -s:script.txt tgftp.nws.noaa.govNow you will have a file (pittsburgh.txt) such as:
FPUS41 KPBZ 090846
City Forecast for Pittsburgh, PA
Issued Thursday morning - Sep 9, 2010
.Thursday... Partly cloudy, high 67, 5% chance of precipitation.
.Thursday night... Low 48, 5% chance of precipitation.
.Friday... Partly cloudy, high 69, 5% chance of precipitation.
.Friday night... Low 48.
.Saturday... High 75.The figures of interest are 67 (which is the forecast high) and 48 (the forecast low).
EXTRACT
The following VBS script fragment extracts these two values from the pittsburgh.txt file:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, MyFile, FileName, TextLine
LowTemp = 999
HiTemp = 999
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "pittsburgh.txt"
Set MyFile = fso.OpenTextFile(FileName, ForReading)
' Read from the file and parse
Do While MyFile.AtEndOfStream <> True
TextLine = MyFile.ReadLine
Low = instr(TextLine,"Low ")
if (Low > 0 ) and ( LowTemp = 999) then
LowTemp = cint(mid(TextLine,Low+4,3))
end if
Hi = instr(TextLine,"high ")
if (Hi > 0) and (HiTemp = 999) then
HiTemp = cint(mid(TextLine,Hi+5,3))
end if
Loop
MyFile.Close
MAKE FLAGS
Continue the VBS script with something like the following:
if (HiTemp <> 999) and (LowTemp <>999) then
Set MyFile = fso.OpenTextFile("flags.txt", ForWriting, True)
if (LowTemp < 25) then
MyFile.Writeline "ColdSpell = Yes"
else
MyFile.Writeline "ColdSpell = No"
end if
if (HiTemp > 81) then
MyFile.Writeline "HeatWave = Yes"
else
MyFile.Writeline "HeatWave = No"
end if
MyFile.close
End ifWhat this will do is set flag "ColdSpell" if the forecast temperature is below 25 degrees, and "HeatWave" if the forecast temperature is above 81. Assuming you have the previous two VBS fragments in a file called "GetForecast.VBS", run it using
wscript GetForecast.VBS Now you have a file called flags.txt consisting of two lines, maybe like this:
ColdSpell = Yes
HeatWave = No
READ FLAGS IN HCA
Now, in HCA, use the program element "Read Data" to read file flags.txt. This will update the HCA flag values to whatever is in the file. Now you can use the visual programmer to take whatever action you wish to.
ewelin
Sep 09, 2010, 04:24 PM
Excellent tutorial, thanks for sharing. I hope you don't mind but I cleaned up the formatting a bit. I'm going to have to give this a try here as well.
vBulletin® v3.8.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.