Netatmo collector is a PHP script for requesting measures from Netatmo devices.
- Automatic script (can be used with cron for example),
- Initialization step (providing a start date and wait for the magic),
- Store measures into an InfluxDB database,
- Explore data with Grafana.
Download this project and extract files to directory of your choice.
In order to authenticate yourself on the Netatmo API, you must:
- create a Netatmo application,
- generate a token with
read_station
scope, - enter your
client_id
andclient_secret
values inconfig.php
, - create a
tokens.json
file with this content (replace the 2 values between<>
with your tokens):
{"access_token":"<yourAccessToken>","refresh_token":"<yourRefreshToken >","scope":["read_station"],"expires_in":10800,"expire_in":10800,"expires_at":0}
Install dependencies with composer: composer install
.
You need InfluxDB installed.
Default values are ok, but configuration can be changed (see docs).
Script will create database.
You need Grafana installed.
Import JSON file from Grafana GUI (Create / Import).
Create InfluxDB data source, mainly name and influxDB URL, for example: http://localhost:8086
(Configuration / Data sources / Add).
Configure dashboard variables (Dashboard / Settings / Variables):
datasource
= the data source name you set up,devices
= the Netatmo station name (only one station by dashboard),modules
= comma separated list of modules name,windGauge
= wind gauge module name (obviously),rainGauge
= rain gauge module name (obviously),mainModule
= main module name (obviously).
In order to collect oldest measures, script accepts a start date (YYYY-MM-DD) as an optional argument.
Open a shell, go in script directory and execute it: php -f index.php 2018-12-31
.
Add to your scheduler (cron for exemple) following command (change the path /usr/local/bin/netatmo-collect/
according to your installation):
# /etc/cron.d/netatmo-collect: crontab fragment for requesting Netatmo measures
# Requesting Netatmo measures and storing to database every 12 hours
0 */12 * * * root php -f /usr/local/bin/netatmo-collect/index.php >> /var/log/syslog 2>&1
Log settings can be found in config.xml
file.
In production mode, the default configuration use a file (netatmo-collect.log
) for logging at level INFO
.
For debugging, you can output to console and set a more verbose level (DEBUG
or even TRACE
) by overriding the root
section:
<root>
<level value="DEBUG"/>
<appender_ref ref="console"/>
</root>
This project is maintained under the semantic versioning guidelines.
See the releases on this repository for changelog.
Pull requests are welcomed.
- Nioc - Initial work
See also the list of contributors to this project.
This project is powered by the following components:
- Netatmo-API-PHP
- influxdb-php (MIT)
- Apache log4php (Apache License)
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.