Checking the weather with PowerShell

As a part of my home automation project I wanted to be able to check the weather, and since I’m trying to do as many parts of the automation as possible with PowerShell, I needed to write a cmdlet for this. But where to get the data?

I was very happy to find out that the Swedish Meteorological and Hydrological Institute (SMHI) actually has a published API, open and free to use!

The API is very simple, after you send a request with longitude and latitude it sends back a json-object with weather data for that location (tagged with the location of the closest weather station used for the report) for up to 10 days.

Note: As a visitor pointed out in the comments, SMHI does not have weather data for all countries, I’ve tested a couple of locations in Europe which seems to work fine though. You will get a “error 400 bad request” error if the location is out of scope.

The cmdlet does some small changes to the returned object (expands a few properties and changes some shortnames to something that is easier to understand, converting some values to percentages and so on…) and returns each forecast as a separate object. The forecasts can cover anything from 1 hour to a day or so, so make sure you check the start/end dates.

This is how Get-SMHIWeatherData looks in action:
SMHIWeather

The code for this cmdlet is available here. (Updated 2016-10-24)

6 thoughts on “Checking the weather with PowerShell

  1. Anders Post author

    Sad to hear that! I tested a couple of locations in europe that worked, but it seems you are right, SMHI does not have any weather data for US.

    If I find another API with global weather data I will write a new cmdlet for this! If anyone know a good one please add a comment here!

    I’ll give Google a try later on, shouldn’t be too hard to find.

    Reply
  2. Pingback: Brewing coffee with Azure Automation | DollarUnderscore

  3. Pingback: Buying groceries with PowerShell | DollarUnderscore

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.