Skip to content

Instantly share code, notes, and snippets.

@PierpaoloPernici
Created August 13, 2017 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierpaoloPernici/16bc22079e068d68f51856418da9a56f to your computer and use it in GitHub Desktop.
Save PierpaoloPernici/16bc22079e068d68f51856418da9a56f to your computer and use it in GitHub Desktop.
Netatmo thermostat monitoring with Telegraf (JSON)
#!/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