Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nest
- import sys
- from influxdb import client as influxdb
- db = influxdb.InfluxDBClient("localhost", 8086, "", "", "cacti2")
- client_id = 'e4ca1071-d674-4475-9401-3952b38577c4'
- client_secret = 'VOkkbMOqvdgVjPuw9BzrYA46K'
- access_token_cache_file = 'nest.json'
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement