more G-Labs products

Author Topic: How to get Weather Underground working?  (Read 1594 times)

March 16, 2016, 01:36:04 AM
Read 1594 times

HADad

  • *
  • Information
  • Newbie
  • Posts: 8
So I registered on WU and got an API key and edited the options in HG to have my API key and city, yet when I restart it I see this:    Automation Program   Program.Notification   {"Title":"Weather Underground ERROR!","Message":"Unable to get data from service. Cannot perform member binding on `null' value"}

I can see through the WU analytics page that calls are making it to WU from my system.

I thought maybe it's because there are multiple cities with my city's name, so I edited the HG code and added state to the URL, but it's still not working.

I am using HomeGenie Version 1.1 beta r514 on Linux Mint 17.3

Any help would be great!

Thanks!
« Last Edit: March 16, 2016, 01:57:55 AM by HADad »

March 16, 2016, 10:01:27 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Your best bet is to figure out what URL to call from WU to get valid data that HG needs.  You can either use the HG code to determine the URL that's being called, or go from the other side and build the correct URL from the WU example.  Either way, you need to have HG call a URL that has the json formatted data that can be processed.  When I picked the local city for my home, it didn't contain the correct data.  I requested the closest big city and HG was able to display the full data without error.

March 17, 2016, 12:10:36 AM
Reply #2

HADad

  • *
  • Information
  • Newbie
  • Posts: 8
Thank you bkenobi! Can you tell me (or post an example of) the correct json data? I know my URL returns json, but I'm not sure what the correct response is supposed to look like. I will also look at the code and see if I can figure it out.

Thanks!

March 17, 2016, 03:40:39 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
This is what I just pulled:
Code: [Select]
{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "conditions": 1
  }
}
  , "current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
"display_location": {
"full":"San Francisco, CA",
"city":"San Francisco",
"state":"CA",
"state_name":"California",
"country":"US",
"country_iso3166":"US",
"zip":"94101",
"magic":"1",
"wmo":"99999",
"latitude":"37.77500916",
"longitude":"-122.41825867",
"elevation":"47.00000000"
},
"observation_location": {
"full":"SOMA - Near Van Ness, San Francisco, California",
"city":"SOMA - Near Van Ness, San Francisco",
"state":"California",
"country":"US",
"country_iso3166":"US",
"latitude":"37.773285",
"longitude":"-122.417725",
"elevation":"49 ft"
},
"estimated": {
},
"station_id":"KCASANFR58",
"observation_time":"Last Updated on March 17, 7:37 AM PDT",
"observation_time_rfc822":"Thu, 17 Mar 2016 07:37:40 -0700",
"observation_epoch":"1458225460",
"local_time_rfc822":"Thu, 17 Mar 2016 07:37:48 -0700",
"local_epoch":"1458225468",
"local_tz_short":"PDT",
"local_tz_long":"America/Los_Angeles",
"local_tz_offset":"-0700",
"weather":"Clear",
"temperature_string":"53.5 F (11.9 C)",
"temp_f":53.5,
"temp_c":11.9,
"relative_humidity":"91%",
"wind_string":"Calm",
"wind_dir":"South",
"wind_degrees":178,
"wind_mph":0.0,
"wind_gust_mph":0,
"wind_kph":0,
"wind_gust_kph":0,
"pressure_mb":"1014",
"pressure_in":"29.95",
"pressure_trend":"0",
"dewpoint_string":"51 F (11 C)",
"dewpoint_f":51,
"dewpoint_c":11,
"heat_index_string":"NA",
"heat_index_f":"NA",
"heat_index_c":"NA",
"windchill_string":"NA",
"windchill_f":"NA",
"windchill_c":"NA",
"feelslike_string":"53.5 F (11.9 C)",
"feelslike_f":"53.5",
"feelslike_c":"11.9",
"visibility_mi":"10.0",
"visibility_km":"16.1",
"solarradiation":"--",
"UV":"0","precip_1hr_string":"0.00 in ( 0 mm)",
"precip_1hr_in":"0.00",
"precip_1hr_metric":" 0",
"precip_today_string":"0.00 in (0 mm)",
"precip_today_in":"0.00",
"precip_today_metric":"0",
"icon":"clear",
"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
"forecast_url":"http://www.wunderground.com/US/CA/San_Francisco.html",
"history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANFR58",
"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725",
"nowcast":""
}
}

The syntax for the API is:
http://api.wunderground.com/api/<API key>/conditions/q/CA/San_Francisco.json

Where CA is for California.  What city/state are you trying to use?  I can try to find the correct call for you and then you just need to make sure your API key is correct.

I used the documentation to understand what was required when I first started with WU.
https://www.wunderground.com/weather/api/d/docs

If you are logged in, this is your personal API information page:
https://www.wunderground.com/weather/api/

March 17, 2016, 04:08:54 PM
Reply #4

HADad

  • *
  • Information
  • Newbie
  • Posts: 8
Thank you again!

Ok, my json is coming back much different, so I will change the query to see if I can find one which matches more of what you posted.

Thanks again!!! :)

March 18, 2016, 02:32:58 AM
Reply #5

HADad

  • *
  • Information
  • Newbie
  • Posts: 8
Okay, I am happy to report I was able to get it working by hacking the program code and specifying a state and pws as part of the city. So it's working now!

Thanks for the help!

March 18, 2016, 02:41:44 AM
Reply #6

HADad

  • *
  • Information
  • Newbie
  • Posts: 8
So I went back and simplified it by just specifying the city as <STATE>/pws:<station number> and it all works with no code changes. So for example I could specify "CA/pws:92134" and it works. :)

Thanks again!