{"id":1721,"date":"2014-03-25T12:36:11","date_gmt":"2014-03-25T12:36:11","guid":{"rendered":"http:\/\/dollarunderscore.azurewebsites.net\/?p=1721"},"modified":"2017-06-05T20:58:28","modified_gmt":"2017-06-05T18:58:28","slug":"checking-the-weather-with-powershell","status":"publish","type":"post","link":"https:\/\/p0wershell.com\/?p=1721","title":{"rendered":"Checking the weather with PowerShell"},"content":{"rendered":"<p>As a part of my home automation project I wanted to be able to check the weather, and since I&#8217;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?<\/p>\n<p>I was very happy to find out that the Swedish Meteorological and Hydrological Institute (SMHI) actually has <a href=\"http:\/\/www.smhi.se\/klimatdata\/Oppna-data\" target=\"_blank\">a published API<\/a>, open and free to use!<\/p>\n<p>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.<\/p>\n<p>Note: As a visitor pointed out in the comments, SMHI does not have weather data for all countries, I&#8217;ve tested a couple of locations in Europe which seems to work fine though. You will get a &#8220;error 400 bad request&#8221; error if the location is out of scope.<\/p>\n<p>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&#8230;) 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.<\/p>\n<p>This is how Get-SMHIWeatherData looks in action:<br \/>\n<a href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1731\" src=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather.png\" alt=\"SMHIWeather\" width=\"1157\" height=\"402\" srcset=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather.png 1157w, https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather-300x104.png 300w, https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather-1024x355.png 1024w, https:\/\/p0wershell.com\/wp-content\/uploads\/2014\/03\/SMHIWeather-624x216.png 624w\" sizes=\"(max-width: 1157px) 100vw, 1157px\" \/><\/a><\/p>\n<p><em><strong>The code for this cmdlet is available <a title=\"Get-SMHIWeatherData\" href=\"https:\/\/p0wershell.com\/wp-content\/uploads\/2017\/06\/Get-SMHIWeatherData.ps1_.txt\" target=\"_blank\">here<\/a>. (Updated 2016-10-24)<\/strong><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a part of my home automation project I wanted to be able to check the weather, and since I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[621,231,21],"tags":[651,661,631,641],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Zj0A-rL","_links":{"self":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/1721"}],"collection":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1721"}],"version-history":[{"count":0,"href":"https:\/\/p0wershell.com\/index.php?rest_route=\/wp\/v2\/posts\/1721\/revisions"}],"wp:attachment":[{"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p0wershell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}