NetAtmo Programming

Netatmo Weather Station Shell Script

I got a lot of feedback for my blog post Read NetAtmo weather station data via Script and Export NetAtmo weather station data to CSV / Excel. A lot of people seem to be interested by using the data from thier Netatmo weather station.

Bernd G. – one of my blog readers, extended my scripts and build a complete Linux shell wrapper around it. That makes it much easier and adds more flexibility to the scripts. Bernd allowed me to post his script on my blog to share it.

Download:
netatmo.sh

Usage:
– Download and remove .txt file extension
– chmod +x netatmo.sh
– Run the script using ./netatmo.sh -h

The parameter “-h” will display a help message containing all available parameters and options:

usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

Usage: netatmo.sh -h

       netatmo.sh [-u <user>] [-p <pass>] -D

       netatmo.sh [OPTIONS]

General options
---------------
 -h  Display this help message and exit

 -u <username>
     User to use (default is set in the configuration area of this script)

     A guest user is sufficient.

 -p <password>
     Password to use (default is set in the configuration area of this script)

 -D  Don't fetch data, but get device info and current readings.
     If jq is available, it's used to format and pretty-print the output.

Additional general options for data fetching (not -D) mode only
---------------------------------------------------------------
 -x  Get the data as Excel, not as CSV

 -i  In the output filename, use the module's ID instead of it's name

 -o  <directory>
     Directory to put the received files in (defaults to the current directory)

Date/time selection options (not for -D mode)
---------------------------------------------
 -s <date time>
     Start time (format: 'YYYY-MM-DD HH:MM:SS')

     Defaults to now - 3600 seconds

 -e <date time>
     End time (format: 'YYYY-MM-DD HH:MM:SS')

     Defaults to now

Date/time selection shortcuts (not for -D mode)
-----------------------------------------------
 -n <seconds>
     Get data for the last <seconds> seconds

 -y  Get yesterday's data
 
 -t  Get today's data (00:00:00 until now)
 
 -d <yyyy-mm-dd>
     Get historical data for the specified day
 
 -T  Get this month' data

 -L  Get last month' data
 
 -M <yyyy-mm>
     Get data for the specified month

Output
------

In -D mode, netatmo.sh prints out the received JSON object to STDOUT.

In data fetching mode, netatmo.sh generates a separate output file
for each sensor. For the main module e.g. you'll get five different files,
one for temperature, humidity, co2, noise and pressure each.

The files will be placed in your current directory (or in whatever directory
you specified using the -o option).

Filenames are 
    <module>_<sensor>_<time or timerange>.<extension>

    <module>
        Is the module's name as given in your configuration, or it's
        ID ('aa:bb:cc:dd:ee:ff') if requested via -i.

    <sensor>
        Is the name of the sensor as defined by NetAtmo 
        (co2, humidity, noise, pressure, rain, temperature etc.)

    <time or timerange>
        Depends on your request.

        If you request data for a specific day (-d, -y, -t), it will be
        the day (e.g. '2016-01-16'). For today, where you don't get a
        whole day's worth of data (but only from midnight to now),
        a '-(partially)' is added (-> '2016-01-17-(partially)').

        If you request data for a specific month (-M, -L, -T), it will be
        the month (2016-01). For 'this month', where you don't get a whole
        month' worth of data (but only from the 1st to now), a '-(partially)'
        is added (-> '2016-01-(partially)').

        In any other case, it will be the exact timerange as time span
        like '<2016-01-17-10-00-00_2016-01-18-13-42-51>'
        
    <extension>
        Is 'csv' for csv files, 'xls' for Excel (if requested using -x)

    Some filename examples:

    livingroom_temperature_2016-02-16-13-31-57_2016-02-17-11-41-57.csv
    (generic)

    aa:bb:cc:dd:ee:ff_temperature_2016-02-16-13-31-57_2016-02-17-11-41-57.csv
    (generic with -i)

    livingroom_temperature_2016-01.csv
    livingroom_temperature_2016-02-(partially).csv
    (specific day)

    livingroom_temperature_2016-02-16.csv
    livingroom_temperature_2016-02-17-(partially).csv
    (specific month)

Examples
--------

$ netatmo.sh -h

  Get the help screen

$ netatmo.sh -D

  Fetch device information

$ netatmo.sh

  Get data for the last hour

$ netatmo.sh -n 1800

  Get data for the last half hour (= 1800s)

$ netatmo.sh -t

  Get data since midnight until now

$ netatmo.sh -T

  Get data since the 1st of the current month until now

$ netatmo.sh -y

  Get data for yesterday

$ netatmo.sh -L

  Get data for the last month

$ netatmo.sh -d 2016-02-17

  Get data for February 17th 2016

$ netatmo.sh -M 2016-02

  Get data for February 2016

$ netatmo.sh -s '2016-05-03 17:31:15' -e '2016-05-04 12:21:17'

  Get data from 2016-05-03 17:31:15 to 2016-05-04 12:21:17

$ netatmo.sh-s '2016-08-30 17:31:15'

  Get data from 2016-08-30 17:31:15 until now
You may also like
VBScript: Change Word Document Template
LotusScript: Move all items without a view into Inbox Folder
Evernote Backup using Apple Script
2 Comments
  • zuecho
    2017-11-12T20:56:55+00:000000005530201711 at 20:56
    Reply

    Thanks for the nice script!

    As a mac user small adjustments are needed.
    1. The heavily used date command in the script does not work as expected. Mac ships with BSD date, instead of GNU date. Therefore you need to install gdate (which is the GNU date) and adjust all the date commands in the script.
    2. There is a similar problem with the stat command (line 614). As a mac user you want to change it to “$(stat -f%z “${outfilename}”)”

    Cheers

  • Christoph Steffin
    2017-11-08T15:01:05+00:000000000530201711 at 15:01
    Reply

    Wonderful piece of script…I run it through CygWin on a Windows Server to catch the data. Is it normal, that fetching the data takes around 5 min and sometimes hours per module and sensor? 😀
    Does anybody else got this behavior?

Leave Your Comment

Your Comment*

Your Name*
Your Webpage