View unanswered posts | View active topics It is currently Sun May 19, 2013 6:34 pm



Reply to topic  [ 55 posts ]  Go to page: Previous  1, 2, 3, 4  Next
 Icon display problems with Wunderground Script 
Author Message
User avatar

Joined: Nov 18, 2008
Posts: 1720
Location: Berkeley, CA
Post Re: Icon display problems with Wunderground Script
Try this in a terminal window: cd to the contents/variables directory
Then:
chmod 777 current*png

Then re-run the Wunderground script and see what happens.
If that doesn't work, try manually copying one of the observation_icons images to current.png and current+true.png in the variables folder.


Wed Sep 01, 2010 2:22 pm
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
I ran terminal with the following and got:

KleinMini-2:~ KleinMini$ cd /Library/Application\ Support/Perceptive\ Automation/Indigo\ 4/IndigoWebServer/images/controls/variables
KleinMini-2:variables KleinMini$ chmod 777 current*png

Ran the script and not change so restarted the Indigo server and got nothing as well.

I did a save-as for two weather icons in the Observation_Icons folder and saved them to the variables folder and still no effect after running the script. The icon in the Edit Control Page still indicates Image not found or unreadable.


Wed Sep 01, 2010 5:24 pm
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
Just took a look at my control page through the Indigo IOS application and the icon shows. Not the right one. When I go into Indigo and open the control page it matches the current condition. Although I run the script it doesn't make it to the live view when viewed with Indigo Touch.


Attachments:
photo.jpg
photo.jpg [ 75.45 KiB | Viewed 3803 times ]
Wed Sep 01, 2010 10:39 pm
Profile

Joined: May 07, 2008
Posts: 8
Post Re: Icon display problems with Wunderground Script
Hi. I'm having an identical problem to AlaskaDave. Wunderground script is running, icons are in the right place, the proper variables are set in Indigo, I'm getting weather updates on my control page, and I've modified permissions on the current.png file w/chmod 777 current*png. I just can't get the weather icon to display. The best I can get Is "image not found or unreadable."

Any ideas?

Cheers.


Fri Nov 26, 2010 10:42 am
Profile
User avatar

Joined: Nov 18, 2008
Posts: 1720
Location: Berkeley, CA
Post Re: Icon display problems with Wunderground Script
notfamous wrote:... I just can't get the weather icon to display. The best I can get Is "image not found or unreadable."

Any ideas?

Without direct access to your computer it is essentially impossible to debug this problem. THere is nothing magical going on... The script simply takes the appropriate image from the image set in the Observation_Icons sub-directory and copies that image to current.png and current+true.png in Indigo's IndigoWewbServer/images/controls/variables directory.

The error message your are receiving seems to indicate either:
    a) The Observation_Icons directory was placed in the wrong location. Or...
    b) The control page settings are wrong. Probably the wrong variable is referenced. Or...
    c) Incorrect modifications were made in the script.

It is not really possible to help remotely in cases b & c, but if the problem is related to file structure you can do the following: from the terminal, enter this command:
ls -lR "/Library/Application Support/Perceptive Automation/Indigo 4/IndigoWebServer/images/controls/variables"
then post the results back to this topic.


Mon Nov 29, 2010 1:12 pm
Profile

Joined: May 07, 2008
Posts: 8
Post Re: Icon display problems with Wunderground Script
Thanks for the reply. Oddly enough, it just started working on it's own. I don't know why. I suspect a complete server restart had something to do with it. I did find an error handling bug, as I get a 1701 error from a PWS that doesn't return last high/low variables. I had to comment out the offending string to get the script to work. Other than that, it's all good now.
Cheers.


Mon Nov 29, 2010 1:18 pm
Profile

Joined: Jan 31, 2011
Posts: 13
Location: Menlo Park, CA
Post Re: Icon display problems with Wunderground Script
I just installed the Wunderground script, and had the same problems with getting the conditional icons to work. I finally figured it out (with much help from this forum). The two tricky parts I found were:

1. You have to be really careful to put the entire folder "Observation_Icons" into the variables folder. The first time around, I put the individual icons in the variables folder. After parsing the instructions word for word I realized that it specified to put the folder in, but it wasn't intuitively obvious (at least to me).

2. The first time around I only had the "_Wunderground_PWS_List" variable defined with the value of my local personal weather station. I was not getting values for the "Wunderground_Condition" and the "Wunderground_Icon" in my variables list. I realized that this was probably why the conditional script to display the correct icon was not working. The conditions on the Weather Underground web page said "Scattered Clouds". After a little trial and error, I looked at the xml code on Weather Underground (http://api.wunderground.com/weatherstat ... KCASANFR58) to see if it was providing the condition "Scattered Clouds". It turned that out is was not. I then checked the xml web page for my local Airport. The condition was being provided there. So I added the variable "_Wunderground_APT", added the value for my local Airport, executed the script, and voila, I received values for the Wunderground_Condition and Wunderground_Icon. I am now displaying the conditional icons in my control page.

Now that it is working, I must say it is a very cool script. Kudos to the author. Now on to integrating my irrigation system...


Mon Jan 31, 2011 11:19 pm
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
Wish I had so good. I should probably throw out everything and start over when it comes to the script. I've tried everything and have had to just leave untouched due to frustration. I had my current icons for a while and now they don't seem to want to build. I've done as all as suggested and there must be something about permissions perhaps that is preventing the icon display working for me. Below is a screen shot of several windows showing that all icons are in their proper place and I have variables coming in but no icons result. Any new ideas??

Image


Tue Feb 01, 2011 12:42 am
Profile

Joined: Mar 28, 2010
Posts: 13
Post Re: Icon display problems with Wunderground Script
AlaskaDave,

I was getting a bit frustrated with this as well, so I downloaded a trial copy of Script Debugger to inspect the script. I noticed in the setIcon function the copy command would fail, and saw the iconName already had the nt_ prefix. So the function was trying to copy nt_nt_xxx.png and would fail.

I did not take the time to properly debug the script, instead put in a little hack for now to strip the nt_ prefix first from the iconName, which the function adds if isDaylight is false. I added the code in red. Even the icons for the six day forecasts also work now.

Not sure why I was having this issue when a few others have been able to successfully run the script. The icons are pretty cool, so I hope this works for you.

Haseen


on setIcon(iconName, isDaylight, iconType)
set prefix to text 1 thru 3 of iconName as text
if prefix = "nt_" then
set iconName to text 4 thru (length of iconName) of iconName
end if


--Rest of the function is the same...
end setIcon


Sun Mar 06, 2011 1:43 am
Profile
User avatar

Joined: Nov 18, 2008
Posts: 1720
Location: Berkeley, CA
Post Re: Icon display problems with Wunderground Script
haseenalam wrote:...Not sure why I was having this issue when a few others have been able to successfully run the script. The icons are pretty cool, so I hope this works for you.
... ...
on setIcon(iconName, isDaylight, iconType)
set prefix to text 1 thru 3 of iconName as text
if prefix = "nt_" then
set iconName to text 4 thru (length of iconName) of iconName
end if


--Rest of the function is the same...
end setIcon


Are you using the latest version (2.5) of the Wunderground script? In this version (and at least as far back as version 2.1) the definition of the setIcon handler has different arguments than the snippet you posted - iconType is not used. I suspect you may have a hacked version rather than an original distribution from the contributions library.

Note that the script takes the variable iconName directly from the Wunderground XML feed and then the nt_ prefix is added in the setIcon handler. So, it is a little mysterious how the iconName passed to the handler could already contain the nt_ prefix.

Here is the setIcon handler code from version 2.5:
Code: Select all
on setIcon(iconName, isDaylight)
   if isDaylight is true then
      set iconFile to iconName & ".png"
   else
      set iconFile to "nt_" & iconName & ".png"
   end if
   
   set iconDir to "/Library/Application Support/Perceptive Automation/Indigo 4/IndigoWebServer/images/controls/variables/Observation_Icons"
   -- copy the appropriate icon ong to the "current" icon files
   do shell script "cd " & quoted form of iconDir & ";" & "cp -f " & iconFile & " ../current.png; cp -f " & iconFile & " ../current+true.png"
end setIcon


Mon Mar 07, 2011 1:59 pm
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
When I get home I'll check to see what version I'm running and it not the latest will update and see if my issues are resolved. We have very few stations in my area and I'm afraid the ones that were running have froze due to our crazy winds, rain, snow...etc because the feeds were coming up empty. Now that they have apparently thawed I'll give it another try.


Mon Mar 07, 2011 3:02 pm
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
haseenalam wrote:AlaskaDave,

I was getting a bit frustrated with this as well, so I downloaded a trial copy of Script Debugger to inspect the script. I noticed in the setIcon function the copy command would fail, and saw the iconName already had the nt_ prefix. So the function was trying to copy nt_nt_xxx.png and would fail.

I did not take the time to properly debug the script, instead put in a little hack for now to strip the nt_ prefix first from the iconName, which the function adds if isDaylight is false. I added the code in red. Even the icons for the six day forecasts also work now.

Not sure why I was having this issue when a few others have been able to successfully run the script. The icons are pretty cool, so I hope this works for you.

Haseen


on setIcon(iconName, isDaylight, iconType)
set prefix to text 1 thru 3 of iconName as text
if prefix = "nt_" then
set iconName to text 4 thru (length of iconName) of iconName
end if


--Rest of the function is the same...
end setIcon


Thanks for the suggestion. I tried it (see screenshot) and no change in my icons showing up. Still indicates that it can not find them. The previous script was 2.5, verified before making the suggested changes. Any more ideas? I'm about to give up on this one, just not meant to be. Perhaps some future update will take care of the mystery issue. Any moderators care to screen share to see if they can find the issue?


Attachments:
IndigoSnapshot.jpg
IndigoSnapshot.jpg [ 118.46 KiB | Viewed 2653 times ]
Tue Mar 08, 2011 1:07 am
Profile

Joined: Nov 26, 2009
Posts: 923
Location: Kalispell, MT
Post Re: Icon display problems with Wunderground Script
Just my 2¢ but why not just lose the icons folder, rename the icons Wunderground_Icon+.png, Wunderground_Icon+clear.png etc.?

Carl


Tue Mar 08, 2011 1:34 am
Profile
User avatar

Joined: Nov 18, 2008
Posts: 1720
Location: Berkeley, CA
Post Re: Icon display problems with Wunderground Script
AlaskaDave and haseenalam:
Based on what you have posted, you are not running the release version 2.5 of the Wunderground script. The code you are running has three arguments for setIcon. But, the code posted to the User Contribution library only has two. (See my previous post in this thread.) Could one of you please post your code so I can see if I can figure out what you have.

ckeys888:
The point of this bit of code is to automatically change the weather icon to match current conditions. This is done by copying icon files with name matching the current condition to two fixed file names. So, losing the folder would defeat the design.


Tue Mar 08, 2011 2:01 am
Profile
User avatar

Joined: Oct 16, 2008
Posts: 214
Location: Juneau, Alaksa
Post Re: Icon display problems with Wunderground Script
Since my post above and edits suggested by haseenalam, I have since reinstalled and restarted 2.5 with no edits, below is the script in use. After restart of Indogo I see that my variables are still being brought in, to include Wunderground_Condition and Wunderground_Icon but control page still indicates "Image not found or unreadable".

Code: Select all
if not dupeProcCheck("Wunderground") then
   LogWunderground("Cancelled attempt to start script while another instance was running.", "", 0)
   error number -128
end if

set debug to false
-- *----------------- USER DEFINED VARIABLES -----------------------*

-- The following two property sections define the  fields to be retrieved from the XML data
-- from the XML data. These should be seto to either the source of the data:
-- "PWS" for Personal Weather Stations, or
-- "APT": for Airport stations,
-- or "" (Null) for fields you do not wish to retrieve and save in Indigo

-- The following fields are available from airport and personal weather stations
property GetDewpointC : ""
property GetDewpointF : "PWS"
property GetDewpointString : "PWS"
property GetElevation : "PWS"
property GetHeatIndexC : ""
property GetHeatIndexF : "PWS"
property GetHeatIndexString : ""
property GetObservationTime : "PWS"
property GetPrecip_1hr_in : "PWS"
property GetPrecip_1hr_m : ""
property GetPrecip_1hr_string : "PWS"
property GetPrecip_today_in : "PWS"
property GetPrecip_today_m : ""
property GetPrecip_today_string : "PWS"
property GetPressureIN : "PWS"
property GetPressureMB : ""
property GetPressureString : "PWS"
property GetRelativeHumidity : "PWS"
property GetTempC : "PWS"
property GetTempF : "PWS"
property GetTempString : "PWS"
property GetWindDegrees : "PWS"
property GetWindDirection : "PWS"
property GetWindGustMPH : "PWS"
property GetWindMPH : "PWS"
property GetWindString : "PWS"
property GetWindchillC : ""
property GetWindchillF : ""
property GetWindchillString : ""
property GetObservationTimerfc822 : "PWS"
property GetStationID : "PWS"
property GetFull : "PWS"
property GetNeighborhood : "PWS"
property GetCity : "PWS"
property GetState : ""
property GetZip : ""
property GetLatitude : ""
property GetLongitude : ""

-- The following fields are usually only available from an airport station
property GetWeather : "APT"
property GetIcon : "APT"

-- the following properties control the script behavior for optional features:
-- saveHighLow controls the saving of high and low temperature observations
-- runSetIcon controls the setting of the weather icon for Indigo control pages
property saveHighLow : true
property runSetIcon : true

property downloadTimeout : 30 -- seconds to wait for download to complete. Make this longer if you are on a very slow connection
property downloadRetryDelay : 30 -- seconds to wait between retries

--(*-------------- DO NOT MODIFY AFTER THIS -------------------*)
global myFile
global location, station_id, observation_time, observation_time_rfc822, weather, temperature_string, temp_c, temp_f, relative_humidity, wind_string, wind_dir, wind_degrees, wind_mph, wind_gust_mph, pressure_string, pressure_mb, pressure_in, dewpoint_string, dewpoint_f, dewpoint_c, heat_index_string, heat_index_f, heat_index_c, windchill_string, windchill_f, windchill_c, precip_1hr_string, precip_1hr_in, precip_1hr_m, precip_today_string, precip_today_in, precip_today_m, loc_full, loc_neighborhood, loc_city, loc_state, loc_zip, loc_latitude, loc_longitude, loc_elevation, icon, conditionIcon

-- main()
ClearVariables() -- initialize the data variables to a known state
if debug then LogWunderground("Script Launched", "", 0) -- Tell Indigo we've started, IF we are in Debug mode
set errorID1 to false
set errorID2 to false
set errorCount to 0


-- get some information from Indigo: the date of the last update, Night/Day and the station IDs      
tell application "AppleScript Editor"
   -- the time of the last update
   if not («class Vrbl» "Wunderground_Observation_Time_rfc822" exists) then -- create it.
      make new «class Vrbl» with properties {name:"Wunderground_Observation_Time_rfc822", «class Valu»:"Fri, 1 January 2010 00:00:00 GMT"}
   else if «class Valu» of «class Vrbl» "Wunderground_Observation_Time_rfc822" is equal to "" then
      set the «class Valu» of «class Vrbl» "Wunderground_Observation_Time_rfc822" to "Fri, 1 January 2010 00:00:00 GMT" as text
   end if
   
   set theLastRFCDate to «class Valu» of «class Vrbl» "Wunderground_Observation_Time_rfc822" as text
   set isDaylight to «class Valu» of «class Vrbl» "isDaylight" as boolean -- use for setting the Icon
   
   -- Get the Airport station if it has been defined
   if («class Vrbl» "_Wunderground_APT" exists) then
      set stationAPT to «class Valu» of «class Vrbl» "_Wunderground_APT" as text
   else
      set stationAPT to "none" as text
   end if
   
   -- Get the PWS list if it has been defined      
   if («class Vrbl» "_Wunderground_PWS_List" exists) then
      set pwsList to «class Valu» of «class Vrbl» "_Wunderground_PWS_List"
   else
      set pwsList to ""
   end if
   set stationCount to count words of pwsList
end tell

-- Make sure we have at least 1 station to check, if not, log the problem and bail
if stationAPT is equal to "none" and stationCount is equal to 0 then
   LogWunderground("Script exiting: No stations (Airport or PWS) defined", "", 0)
   return false
end if

try -- the Airport station
   if stationAPT is not equal to "none" then -- we have an airport station ID, so let's try it.
      -- setup a temporary file to receive the xml data
      if GetTemp(stationAPT, "APT") is true then
         -- get the xml file from the Wunderground web site and save it in the temporary folder
         if GetXMLfile(stationAPT, "APT") is true then
            if ParseXML("APT") is false then -- we failed, otherwise we will save the data, below
               -- at the end of the repeat
               LogWunderground("Error parsing data from from Airport Station: " & stationAPT, "", 0)
            end if
         else
            LogWunderground("Error getting data from Station 1: " & stationAPT, "", 0)
         end if
      else
         LogWunderground("Error creating data file for Airport Station: " & stationAPT, "", 0)
      end if
   end if
on error errString number errNum
   LogWunderground("Script Failed: Airport station" & stationAPT, errString, errNum)
end try

repeat with PWS from 1 to stationCount -- cycle through the PWS station(s) until we get a good one
   set stationPWS to word PWS of pwsList
   
   if debug then
      set logMsg to "DEBUG: Start PWS loop- Station # is: " & PWS & ", Error count is: " & errorCount
      LogWunderground(logMsg, "", 0)
   end if
   
   try
      -- setup a temporary file to receive the xml data
      if GetTemp("PWS") is true then
         if debug then log "We received a file for station: " & PWS
         -- get the xml file from the Wunderground web site and save it in the temporary folder
         if GetXMLfile(stationPWS, "PWS") is true then
            if debug then log "The file was valid for station: " & PWS
            -- read the xml file values to send to indigo and check that
            -- the observation we just received is newer than the one we already had
            if ParseXML("PWS") is true and length of observation_time_rfc822 is greater than 0 then
               if debug then log "We parsed the file for station: " & PWS
               set theNewRFCDate to observation_time_rfc822 as text
               if debug then log "The last rfc observation date: " & theLastRFCDate
               if debug then log "The new rfc observation date: " & theNewRFCDate
               set lastObservation to dateToEpoch(theLastRFCDate)
               set newObservation to dateToEpoch(theNewRFCDate)
               if debug then log "Compared new ==>" & newObservation & "<== to old ==>" & lastObservation & "<=="
               if newObservation is greater than lastObservation then -- send the data into Indigo variables
                  if errorCount > 0 then
                     LogWunderground("Found current valid Observation from Station: " & stationPWS, "", 0)
                  end if
                  exit repeat -- our work here is done, for now
               else
                  set errorCount to errorCount + 1
                  LogWunderground("Stale Observation from Station: " & stationPWS, "", 0)
               end if
            else
               set errorCount to errorCount + 1
               LogWunderground("Null data from Station 1: " & stationPWS, "", 0)
            end if
         else
            errorCount to errorCount + 1
            LogWunderground("No data from Station 1: " & stationPWS, "", 0)
         end if
      end if
   end try
end repeat

--log errorCount

if errorCount is equal to stationCount and stationCount is greater than 1 then
   LogWunderground("No Available PWS Servers or no current data", "", 0)
else -- save the data and meta data
   SendToIndigo()
   
   if saveHighLow is true then
      set currentTemp to temp_f as number
      SetHighLow(currentTemp, observation_time)
   end if
   
   if runSetIcon is true and stationAPT is not equal to "none" then
      setIcon(icon, isDaylight)
   end if
   
end if
return
-- end of main()

on ClearVariables()
   -- Wunderground location vars
   set loc_full to ""
   set loc_neighborhood to ""
   set loc_city to ""
   set loc_state to ""
   set loc_zip to ""
   set loc_latitude to ""
   set loc_longitude to ""
   set loc_elevation to ""
   -- Wunderground observation vars
   set station_id to ""
   set observation_time to ""
   set observation_time_rfc822 to ""
   set weather to ""
   set temperature_string to ""
   set temp_c to ""
   set temp_f to ""
   set relative_humidity to ""
   set wind_string to ""
   set wind_dir to ""
   set wind_degrees to ""
   set wind_mph to ""
   set wind_gust_mph to ""
   set pressure_string to ""
   set pressure_mb to ""
   set pressure_in to ""
   set dewpoint_string to ""
   set dewpoint_f to ""
   set dewpoint_c to ""
   set heat_index_string to ""
   set heat_index_f to ""
   set heat_index_c to ""
   set windchill_string to ""
   set windchill_f to ""
   set windchill_c to ""
   set precip_1hr_string to ""
   set precip_1hr_in to ""
   set precip_1hr_m to ""
   set precip_today_string to ""
   set precip_today_in to ""
   set precip_today_m to ""
   set icon to ""
   -- Internal script vars and flags
   set stationID1 to ""
   set stationID2 to ""
   set newObservation to ""
   set lastObservation to ""
   set theLastRFCDate to ""
   set theNewRFCDate to ""
end ClearVariables

on GetTemp(stationType)
   try
      -- get a path to a file in the temporary folder to save the xml file
      tell application "Finder"
         set myFile to "var:tmp:wunderground_" & stationType & "_sync_temp.xml"
      end tell
      return true
   on error errString number errNumber
      LogWunderground("GetTemp", errString, errNum)
      return false
   end try
end GetTemp

on GetXMLfile(stationID, stationType)
   if stationType is equal to "PWS" then
      set wunderURL to "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=/"
   else if stationType is equal to "APT" then
      set wunderURL to "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query="
   else
      return false
   end if
   
   set myPath to POSIX path of myFile -- convert the path for the shell call below
   set tryCount to 1
   set success to false
   
   repeat 4 times -- we will wait 30 seconds for a response, and wait another 30 seconds between retries
      with timeout of downloadTimeout + 2 seconds
         try
            do shell script "> " & myPath & ";/usr/bin/curl -s -S -m " & downloadTimeout & " " & wunderURL & stationID & " >" & myPath
            
            --tell application "URL Access Scripting"
            --   download wunderURL & stationID to file myFile replacing yes
            --   -- work around -31040 error:
            --   tell application "URL Access Scripting" to quit
            -- end tell
            -- a quick check to make sure we got something valid
            -- If this command fails, the script will jump to the on error clause
            -- and then try again up to 4 times, otherwise, we will set the success flag
            do shell script "/usr/bin/egrep \"<station_id>" & stationID & "</station_id>\" " & myPath
            set success to true
            exit repeat
         on error errString number errNum
            if errString is equal to "The command exited with a non-zero status." then
               set errString to "Null Station ID in XML data"
            end if
            LogWunderground("GetXMLfile: " & stationID & " try #" & tryCount, errString, errNum)
            set tryCount to tryCount + 1
         end try
      end timeout
      delay downloadRetryDelay -- and then try again
   end repeat
   
   return success
end GetXMLfile

on ParseXML(staTyp)
   try
      tell application "System Events"
         set elem1 to XML element 1 of XML file myFile
         if staTyp is equal to "PWS" then set elem2 to XML element "location" of elem1
         if staTyp is equal to "APT" then set elem2 to XML element "display_location" of elem1
         if GetObservationTime is equal to staTyp then set observation_time to value of XML elements of elem1 whose name is "observation_time"
         if GetObservationTimerfc822 is equal to staTyp then set observation_time_rfc822 to value of XML elements of elem1 whose name is "observation_time_rfc822"
         if GetStationID is equal to staTyp then set station_id to value of XML elements of elem1 whose name is "station_id"
         if GetWeather is equal to staTyp then set weather to value of XML elements of elem1 whose name is "weather"
         if GetTempString is equal to staTyp then set temperature_string to value of XML elements of elem1 whose name is "temperature_string"
         if GetTempF is equal to staTyp then set temp_f to value of XML elements of elem1 whose name is "temp_f"
         if GetTempC is equal to staTyp then set temp_c to value of XML elements of elem1 whose name is "temp_c"
         if GetRelativeHumidity is equal to staTyp then set relative_humidity to value of XML elements of elem1 whose name is "relative_humidity"
         if GetWindString is equal to staTyp then set wind_string to value of XML elements of elem1 whose name is "wind_string"
         if GetWindDirection is equal to staTyp then set wind_dir to value of XML elements of elem1 whose name is "wind_dir"
         if GetWindDegrees is equal to staTyp then set wind_degrees to value of XML elements of elem1 whose name is "wind_degrees"
         if GetWindMPH is equal to staTyp then set wind_mph to value of XML elements of elem1 whose name is "wind_mph"
         if GetWindGustMPH is equal to staTyp then set wind_gust_mph to value of XML elements of elem1 whose name is "wind_gust_mph"
         if GetPressureString is equal to staTyp then set pressure_string to value of XML elements of elem1 whose name is "pressure_string"
         if GetPressureMB is equal to staTyp then set pressure_mb to value of XML elements of elem1 whose name is "pressure_mb"
         if GetPressureIN is equal to staTyp then set pressure_in to value of XML elements of elem1 whose name is "pressure_in"
         if GetDewpointString is equal to staTyp then set dewpoint_string to value of XML elements of elem1 whose name is "dewpoint_string"
         if GetDewpointF is equal to staTyp then set dewpoint_f to value of XML elements of elem1 whose name is "dewpoint_f"
         if GetDewpointC is equal to staTyp then set dewpoint_c to value of XML elements of elem1 whose name is "dewpoint_c"
         if GetHeatIndexString is equal to staTyp then set heat_index_string to value of XML elements of elem1 whose name is "heat_index_string"
         if GetHeatIndexF is equal to staTyp then set heat_index_f to value of XML elements of elem1 whose name is "heat_index_f"
         if GetHeatIndexC is equal to staTyp then set heat_index_c to value of XML elements of elem1 whose name is "heat_index_c"
         if GetWindchillString is equal to staTyp then set windchill_string to value of XML elements of elem1 whose name is "windchill_string"
         if GetWindchillF is equal to staTyp then set windchill_f to value of XML elements of elem1 whose name is "windchill_f"
         if GetWindchillC is equal to staTyp then set windchill_c to value of XML elements of elem1 whose name is "windchill_c"
         if GetPrecip_1hr_string is equal to staTyp then set precip_1hr_string to value of XML elements of elem1 whose name is "precip_1hr_string"
         if GetPrecip_1hr_in is equal to staTyp then set precip_1hr_in to value of XML elements of elem1 whose name is "precip_1hr_in"
         if GetPrecip_1hr_m is equal to staTyp then set precip_1hr_m to value of XML elements of elem1 whose name is "precip_1hr_metric"
         if GetPrecip_today_string is equal to staTyp then set precip_today_string to value of XML elements of elem1 whose name is "precip_today_string"
         if GetPrecip_today_in is equal to staTyp then set precip_today_in to value of XML elements of elem1 whose name is "precip_today_in"
         if GetPrecip_today_m is equal to staTyp then set precip_today_m to value of XML elements of elem1 whose name is "precip_today_metric"
         if GetIcon is equal to staTyp then set icon to value of XML elements of elem1 whose name is "icon"
         if GetFull is equal to staTyp then set loc_full to value of XML elements of elem2 whose name is "full"
         if GetNeighborhood is equal to staTyp then set loc_neighborhood to value of XML elements of elem2 whose name is "neighborhood"
         if GetCity is equal to staTyp then set loc_city to value of XML elements of elem2 whose name is "city"
         if GetState is equal to staTyp then set loc_state to value of XML elements of elem2 whose name is "state"
         if GetZip is equal to staTyp then set loc_zip to value of XML elements of elem2 whose name is "zip"
         if GetLatitude is equal to staTyp then set loc_latitude to value of XML elements of elem2 whose name is "latitude"
         if GetLongitude is equal to staTyp then set loc_longitude to value of XML elements of elem2 whose name is "longitude"
         if GetElevation is equal to staTyp then set loc_elevation to value of XML elements of elem2 whose name is "elevation"
         
      end tell
      
      return true
   on error errString number errNum
      LogWunderground("ParseXML", errString, errNum)
      return false
   end try
end ParseXML

on SendToIndigo()
   -- Sometimes rain data can be negative, probably due to PWS errors. we fix that here.   
   
   if precip_1hr_in < 0 then
      --set precip_1hr_in to precip_1hr_in as real
      set precip_1hr_in to 0
   end if
   
   if precip_1hr_m < 0 then
      --set precip_1hr_m to precip_1hr_m as real
      set precip_1hr_m to 0
   end if
   
   if precip_today_in < 0 then
      --set precip_today_in to precip_today_in as real
      set precip_today_in to 0
   end if
   
   if precip_today_m < 0 then
      --set precip_today_m to precip_today_m
      set precip_today_m to 0
   end if
   
   
   -- load the data into an array to be sent to Indigo.
   -- the array contains three elements:
   -- 1) the name of the Indogo var;
   -- 2) the source flag to control whether this var should be updated;
   -- 3) and the variable value  from the Wunderground XML data
   set arr to {¬
      {"Wunderground_Location_Full", GetFull, loc_full}, ¬
      {"Wunderground_Location_Neighborhood", GetNeighborhood, loc_neighborhood}, ¬
      {"Wunderground_Location_City", GetCity, loc_city}, ¬
      {"Wunderground_Location_State", GetState, loc_state}, ¬
      {"Wunderground_Location_Zip", GetZip, loc_zip}, ¬
      {"Wunderground_Location_Latitude", GetLatitude, loc_latitude}, ¬
      {"Wunderground_Location_Longitude", GetLongitude, loc_longitude}, ¬
      {"Wunderground_Location_Elevation", GetElevation, loc_elevation}, ¬
      {"Wunderground_Observation_Time", GetObservationTime, observation_time}, ¬
      {"Wunderground_Observation_Time_rfc822", GetObservationTimerfc822, observation_time_rfc822}, ¬
      {"Wunderground_StationID", GetStationID, station_id}, ¬
      {"Wunderground_Condition", GetWeather, weather}, ¬
      {"Wunderground_Temperature", GetTempString, temperature_string}, ¬
      {"Wunderground_Temperature_F", GetTempF, temp_f}, ¬
      {"Wunderground_Temperature_C", GetTempC, temp_c}, ¬
      {"Wunderground_Relative_Humidity", GetRelativeHumidity, relative_humidity}, ¬
      {"Wunderground_Wind", GetWindString, wind_string}, ¬
      {"Wunderground_Wind_Direction", GetWindDirection, wind_dir}, ¬
      {"Wunderground_Wind_Degrees", GetWindDegrees, wind_degrees}, ¬
      {"Wunderground_Wind_MPH", GetWindMPH, wind_mph}, ¬
      {"Wunderground_Wind_Gust", GetWindGustMPH, wind_gust_mph}, ¬
      {"Wunderground_Pressure", GetPressureString, pressure_string}, ¬
      {"Wunderground_Pressure_mb", GetPressureMB, pressure_mb}, ¬
      {"Wunderground_Pressure_in", GetPressureIN, pressure_in}, ¬
      {"Wunderground_Dewpoint", GetDewpointString, dewpoint_string}, ¬
      {"Wunderground_Dewpoint_F", GetDewpointF, dewpoint_f}, ¬
      {"Wunderground_Dewpoint_C", GetDewpointC, dewpoint_c}, ¬
      {"Wunderground_Heat_Index", GetHeatIndexString, heat_index_string}, ¬
      {"Wunderground_Heat_Index_F", GetHeatIndexF, heat_index_f}, ¬
      {"Wunderground_Heat_Index_C", GetHeatIndexC, heat_index_c}, ¬
      {"Wunderground_Windchill", GetWindchillString, windchill_string}, ¬
      {"Wunderground_Windchill_F", GetWindchillF, windchill_f}, ¬
      {"Wunderground_Windchill_C", GetWindchillC, windchill_c}, ¬
      {"Wunderground_Precip_1hr_string", GetPrecip_1hr_string, precip_1hr_string}, ¬
      {"Wunderground_Precip_1hr_in", GetPrecip_1hr_in, precip_1hr_in}, ¬
      {"Wunderground_Precip_1hr_m", GetPrecip_1hr_m, precip_1hr_m}, ¬
      {"Wunderground_Precip_today_string", GetPrecip_today_string, precip_today_string}, ¬
      {"Wunderground_Precip_today_in", GetPrecip_today_in, precip_today_in}, ¬
      {"Wunderground_Precip_today_m", GetPrecip_today_m, precip_today_m}, ¬
      {"Wunderground_Icon", GetIcon, icon} ¬
         }
   
   repeat with thisArr in arr
      try
         tell application "AppleScript Editor"
            if (item 2 of thisArr) is not "" then
               -- if the update flag is true, and the var does not exist in Indigo, then create it
               if not («class Vrbl» (item 1 of thisArr) exists) then
                  --make new variable with properties {name:(item 1 of thisArr), value:(item 3 of thisArr)}
                  make new «class Vrbl» with properties {name:(item 1 of thisArr), «class Valu»:""}
                  set «class Valu» of «class Vrbl» (item 1 of thisArr) to (item 3 of thisArr) as string
               else
                  -- Update the var value in Indigo.
                  -- Note: We set the variables as strings in case any are null
                  -- which is common in PWS data
                  set «class Valu» of «class Vrbl» (item 1 of thisArr) to (item 3 of thisArr) as string
               end if
            else -- if the update flag is false, and the var exists in Indigo, then delete it from Indigo
               if («class Vrbl» (item 1 of thisArr) exists) then delete «class Vrbl» (item 1 of thisArr)
            end if
         end tell
      on error errString number errNum
         LogWunderground("SendToIndigo", errString, errNum)
      end try
   end repeat
   return true
end SendToIndigo

on SetHighLow(currentTemp, thedate)
   set thedate to thedate as text
   set theTime to word 6 of thedate & ":" & word 7 of thedate & " " & word 8 of thedate
   
   tell application "AppleScript Editor"
      -- First, check if we have a new high      
      set oldHigh to the «class Valu» of «class Vrbl» "Local_High_Temp" as real
      if oldHigh is equal to "" then set oldHigh to 0 as real
      if currentTemp is greater than oldHigh then
         set the «class Valu» of «class Vrbl» "Local_High_Temp" to temp_f
         set the «class Valu» of «class Vrbl» "Local_High_Time" to theTime
      end if
      
      -- And now, check if we have a new high   
      set oldLow to the «class Valu» of «class Vrbl» "Local_Low_Temp" as real
      if oldLow is equal to "" or oldLow is equal to 0 then set oldLow to 100 as real
      if currentTemp is less than oldLow then
         set the «class Valu» of «class Vrbl» "Local_Low_Temp" to temp_f
         set the «class Valu» of «class Vrbl» "Local_Low_Time" to theTime
      end if
   end tell
end SetHighLow

on setIcon(iconName, isDaylight)
   if isDaylight is true then
      set iconFile to iconName & ".png"
   else
      set iconFile to "nt_" & iconName & ".png"
   end if
   
   set iconDir to "/Library/Application Support/Perceptive Automation/Indigo 4/IndigoWebServer/images/controls/variables/Observation_Icons"
   -- copy the appropriate icon ong to the "current" icon files
   do shell script "cd " & quoted form of iconDir & ";" & "cp -f " & iconFile & " ../current.png; cp -f " & iconFile & " ../current+true.png"
end setIcon

on dupeProcCheck(myName)
   set procCount to do shell script "ps axww|grep -e \"osascript.*" & myName & "\"|grep -v grep|wc -l"
   
   if procCount as integer is greater than 1 then
      return false
   else
      return true
   end if
end dupeProcCheck

on dateToEpoch(rfcDate)
   return do shell script "/bin/date -j -f \"%a, %d %B %Y %T %Z\" \"" & rfcDate & "\"  \"+%s\""
end dateToEpoch

on LogWunderground(errText, errString, errNum)
   tell application "AppleScript Editor"
      try
         if errString is not "" then
            «event INDOLog » errText & ":" & errString & "(" & (errNum as string) & ")" given «class LgTy»:"Wunderground"
         else
            «event INDOLog » errText given «class LgTy»:"Wunderground"
         end if
      end try
   end tell
end LogWunderground


Tue Mar 08, 2011 11:33 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 55 posts ]  Go to page: Previous  1, 2, 3, 4  Next

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.