Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nest_grafana_polling.py
import nest
#https://github.com/jkoelker/python-nest
import sys
from influxdb import client as influxdb
db = influxdb.InfluxDBClient("localhost", 8086, "", "", "cacti2")
client_id = 'xx'
client_secret = 'xx'
access_token_cache_file = 'xx'
napi = nest.Nest(client_id=client_id, client_secret=client_secret, access_token_cache_file=access_token_cache_file)
if napi.authorization_required:
print('Go to ' + napi.authorize_url + ' to authorize, then enter PIN below')
if sys.version_info[0] < 3:
pin = raw_input("PIN: ")
else:
pin = input("PIN: ")
napi.request_token(pin)
for structure in napi.structures:
#return structure object
for device in structure.thermostats:
#loop over each thermostat
temperature = float(device.temperature)
target = float(device.target)
#Cleanup Mode
if device.mode == 'cool':
#print("Mode is cool")
finalmode = 1
else:
#print("Mode is not cool")
finalmode = 0
data = [
{
"tags": {
"host": device.name,
},
"measurement": "temp",
"fields": {
"Float_value": temperature,
"mode2": finalmode,
"target": target
}
}
]
db.write_points(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.