Private GIT

Skip to content
Snippets Groups Projects
Commit 08a9721a authored by Florian Beer's avatar Florian Beer
Browse files

Initial commit

parent c02ae6ba
Branches
No related tags found
No related merge requests found
# grafana-netatmo # grafana-netatmo
Netatmo Weather Station dashboard for Grafana Netatmo Weather Station dashboard for Grafana
## Installation
* Create a [Netatmo developer account](https://dev.netatmo.com/apidocumentation) and fill in your CLIENT_ID, CLIENT_SECRET, USERNAME and PASSWORD in the script.
* This script assumes you have InfluxDB running on the same machine as this script and it uses no authentication.
* Create a cron job to run the script periodically e.g.
```
# cat /etc/cron.d/netatmo
*/5 * * * * root /usr/local/bin/netatmo_influx.py > /dev/null 2>&1
```
#!/usr/bin/env python3
# encoding=utf-8
import lnetatmo
from influxdb import InfluxDBClient
CLIENT_ID = ''
CLIENT_SECRET = ''
USERNAME = ''
PASSWORD = ''
authorization = lnetatmo.ClientAuth(
clientId=CLIENT_ID,
clientSecret=CLIENT_SECRET,
username=USERNAME,
password=PASSWORD,
scope='read_station'
)
weatherData = lnetatmo.WeatherStationData(authorization)
client = InfluxDBClient()
if {'name': 'netatmo'} not in client.get_list_database():
client.create_database('netatmo')
for station in weatherData.stations:
station_data = []
module_data = []
station = weatherData.stationById(station)
station_name = station['station_name']
altitude = station['place']['altitude']
country= station['place']['country']
timezone = station['place']['timezone']
longitude = station['place']['location'][0]
latitude = station['place']['location'][1]
for module, moduleData in weatherData.lastData(exclude=3600).items():
for measurement in ['altitude', 'country', 'longitude', 'latitude', 'timezone']:
value = eval(measurement)
if type(value) == int:
value = float(value)
station_data.append({
"measurement": measurement,
"tags": {
"station": station_name,
"module": module
},
"time": moduleData['When'],
"fields": {
"value": value
}
})
for sensor, value in moduleData.items():
if sensor.lower() != 'when':
if type(value) == int:
value = float(value)
module_data.append({
"measurement": sensor.lower(),
"tags": {
"station": station_name,
"module": module
},
"time": moduleData['When'],
"fields": {
"value": value
}
})
client.write_points(station_data, time_precision='s', database='netatmo')
client.write_points(module_data, time_precision='s', database='netatmo')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment