DEV Community

Cover image for Share your Netatmo station data on your website
Federico Rinaldi
Federico Rinaldi

Posted on

Share your Netatmo station data on your website

Netatmo is a beautiful weather station we can install in our houses.
I tried some libraries to fetch data from my weather station and show results on my web page, but often I found old versions or some things that didn't corresponds to my needs.
So, I tried to write a library that helped me to achieve my goals.
I simply wrote a Typescript client for Netatmo APIs.

The library is very simple; First, you we'll find a method for authentication, that accepts an object contains mandatory properties to authenticate on Netatmo API.
If authentication process have done, response object contains
access token, refresh token and expiration timestamp.
Now, with this data you can call one of the "core" methods exposed by Netatmo:

getMeasure, getPublicData and getStationData.

Authentication :

const meteoData:StationDataResponse = {} as AuthRequest;
authRequest.client_id = 'your_client_id';
authRequest.client_secret = 'your_client_secret';
authRequest.username = 'your_username_netatmo';
authRequest.password = 'your_password_netatmo';
authRequest.scope = 'read_station';
const lib:NetatmoLib = new NetatmoLib();
const auth:AuthResponse = await lib.authenticate(authRequest);

and then extract from response object the data you'll need:
{"scope":["read_station"],"access_token":"sdqweqweqw","refresh_token":"sadsadasdasdasdas","expires_in":10800,"expire_in":10800}

getStationData:

let datiStazioneMeteo:StationDataResponse;
const dataStation:StationDataRequest = {} as
StationDataRequest;
dataStation.access_token = auth.access_token;
dataStation.device_id = 'YOUR_DEVICE_MAC_ADDR';
datiStazioneMeteo = await
lib.getStationData(datiStation);

And now datiStazioneMeteo object returns a Promise of type StationDataResponse, contains all of data returned from your weather station.

This library is released under the GPLv3 License, feel free to contribute, improve code, and share suggestions.

At this link you will find a working example of usage of this library

Repository: https://github.com/Federico-Rinaldi/netatmo-ts-api

Docs : https://federico-rinaldi.github.io/netatmo-ts-api/index.html

Top comments (0)