Time to go outside

At this point I was feeling pretty good about the little Pi’s ability to collect the internal weather. Not ready to call the project complete I decided it was time for a little feature creep: what is the current and historical weather outside?

I didn’t want to pay for weather data, and I also didn’t want to figure out how to mount the sensors to the outside of my apartment. Thankfully NOAA offers a weather API and it’s completely free! They even have some (all?) of the API code on GitHub but it looks a little abandoned.

Finding the weather outside

Browsing the API specification /stations/{stationId}/observations/latest is exactly what I want. But how do I find the closest station? Browsing the other APIs my plan was to go:

  1. My GPS -> Grid Point
  2. Grid Point -> Station ID
  3. Station ID -> Weather (profit!)

My apartment is roughly at the GPS coordinates 47.618420, -122.328695, the /points/{latitude},{longitude} API returns metadata about that GPS location. Most importantly it returns the weather.gov’s “Grid” information I need for the forecast. Also kind of interesting it will redirect https://api.weather.gov/points/47.618420,-122.328695 to https://api.weather.gov/points/47.6184,-122.3287, I guess they don’t care about that level of precision.

Inside the JSON response from the point’s API there is the gridID, gridX, and gridY we need. For me that is: gridId: SEW, gridX: 125, gridY: 69. With that we can find the closest station to my apartment https://api.weather.gov/gridpoints/SEW/125,69/stations. This returns 68 stations that appear to be sorted by distance, the closest and interesting ones are:

  • SEAW1: National Oceanic and Atmospheric Administration Western Regional Center next to Warren G. Magnuson Park
  • KBFI: King County International Airport - Boeing Field
  • E0123: A random spot on Bainbridge Island near Perennial Vintners
  • KRNT: Renton Municipal Airport
  • KSEA: Seattle-Tacoma International Airport
  • KPAE: Paine Field
  • KTIW: Tacoma Narrows Airport

Taking any of those station identifiers we can get the current weather by going to https://api.weather.gov/stations/SEAW1/observations/latest. In that response we get lots of cool data, relevant to this site is: temperature, humidity, and pressure.

Currently I’m only tracking the Boeing field weather but as I write this I’m already thinking about tracking them all and making some kind of live heat map of Seattle with all the data.

Thank you NOAA

Running this API and providing nice documentation isn’t free. Someone at NOAA probably had to fight to make it, and fights every year to keep it going. To that person, or team of people, thank you. I’m sure this API powers tons of Apps that take this free data, put a fancy UI on it, and then charge thousands of customers $0.99 a month to get the data, or worse shove a bunch of ads in their face. Finding this API and getting to use it for my project genuinely made my day a little better. This is the stuff the internet was made for.