Get Netatmo Stationsdata from PowerShell

As the Netatmo weather API is RESTful it's easy to get access to the data from the weather station sensors from PowerShell! Want to display or store your station weather information? It's easy from PowerShell!

An overview of what you can get from the API can be found at dev.netatmo.com/en-US/resources/technical/reference/weatherstation.

Create your own app

To use the API from PowerShell you need to create an app on the Netatmo developer site. Log on to the dev.netatmo.com site and go on to create a new App. If you need to create an developer account, Netatmo Weather is the Netatmo Connect program that you need to sign up for to do this.

Call your app whatever you want, all fields but the Name is optional. For scope you only need the "Read station" functions. Save the Client id and Client secret values for later, you'll need them in a minute... Just activate your app and you're ready to install the module!


Install the PowerShell module

Now download and unpack netatmo.zip to a folder and import the module. Then use the Set-NetatmoAuthorization function to save your IDs to an encrypted file:

Import-Module .\netatmo.psm1
Set-NetatmoAuthorization -client_id "<id from app>" -client_secret "<secret from app>" `
   -username "<your mail address>" -password "<your netatmo password>"

All these IDs are encrypted with a profile key and are only available on the local computer logged in as the user that ran the Set-NetatmoAuthorization function. Look up ConvertTo-SecureString / ConvertFrom-SecureString for more information on the security if you feel this is unsecure. The file used to store these settings is located in the user $home folder as netatmo-config.json.

Why use a file? As the API use access tokens to authenticate all requests these tokens need to be stored somewhere. See dev.netatmo.com/resources/technical/introduction for technical information. A copy of the last access token is also stored in the $GLOBAL:access_token environment variable for fast access. The $GLOBAL:access_token_maxage variable keep track on the life-time of this token. Want to force creation of a new token for some reason? Try Get-NetatmoAccessToken -Force -Verbose, but there is no real need to fiddle with access tokens as the module handles this.

Have fun with your data!

If everything went well you can now get all weather information from your station and all connected modules! Use the Get-NetatmoStationsdata function and then play with the JSON data. Most modules update and upload their data every 10 minutes, don't expect Get-NetatmoStationsdata to return super-fresh data every second!

Have a look at the demo fuction Get-NetatmoFormated as this return native PS objects as well as format and convert all date and time values from the Unix format returned from the API to local PowerShell [datetime]. The Get-NetatmoFormatedHTML function returns some HTML tables. Want to create a very simple web-page with your data?

ConvertTo-Html -Body ( Get-NetatmoFormatedHTML ) -Head "<h1>Nice web page/h1>" -Title "My data" | Out-File .\Nice.html

License

Feel free to use and modify this module in your own projects, but it would be nice if you left my name in there somewhere...