Created
August 13, 2017 08:31
-
-
Save PierpaoloPernici/16bc22079e068d68f51856418da9a56f to your computer and use it in GitHub Desktop.
Netatmo thermostat monitoring with Telegraf (JSON)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import json | |
import requests | |
# setup your variables! | |
data = dict(grant_type='password', client_id='MYCLIENTID', | |
client_secret='MYCLIENTSECRET', username='MYUSERNAME', | |
password='MYPASSWORD', scope='read_thermostat') | |
try: | |
resp = requests.post("https://api.netatmo.com/oauth2/token", data=data) | |
token = resp.json() | |
token['expiry'] = int(time.time()) + token['expires_in'] | |
try: | |
resp = requests.get('https://api.netatmo.com/api/getthermostatsdata?access_token=' + token['access_token']) | |
data = resp.json() | |
print json.dumps(data) | |
#with open('data.json', 'w') as outfile: | |
# json.dump(data, outfile) | |
except requests.exceptions.HTTPError as error: | |
print(error.response.status_code, error.response.text) | |
except requests.exceptions.HTTPError as error: | |
print(error.response.status_code, error.response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment