Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.45 KB | None | 0 0
  1. import nest
  2. import sys
  3. from influxdb import client as influxdb
  4.  
  5. db = influxdb.InfluxDBClient("localhost", 8086, "", "", "cacti2")
  6.  
  7.  
  8. client_id = 'e4ca1071-d674-4475-9401-3952b38577c4'
  9. client_secret = 'VOkkbMOqvdgVjPuw9BzrYA46K'
  10. access_token_cache_file = 'nest.json'
  11.  
  12. napi = nest.Nest(client_id=client_id, client_secret=client_secret, access_token_cache_file=access_token_cache_file)
  13.  
  14. if napi.authorization_required:
  15.    print('Go to ' + napi.authorize_url + ' to authorize, then enter PIN below')
  16.     if sys.version_info[0] < 3:
  17.         pin = raw_input("PIN: ")
  18.    else:
  19.        pin = input("PIN: ")
  20.        napi.request_token(pin)
  21.  
  22. for structure in napi.structures:
  23.    #return structure object
  24.    for device in structure.thermostats:
  25.        #loop over each thermostat
  26.        temperature = float(device.temperature)
  27.        target = float(device.target)
  28.        #Cleanup Mode
  29.        if device.mode == 'cool':
  30.            #print("Mode is cool")
  31.            finalmode = 1
  32.        else:
  33.            #print("Mode is not cool")
  34.            finalmode = 0
  35.  
  36.        data = [
  37.            {
  38.                "tags": {
  39.                    "host": device.name,
  40.                },
  41.                "measurement": "temp",
  42.                "fields": {
  43.                    "Float_value": temperature,
  44.                    "mode2": finalmode,
  45.                    "target": target
  46.                }
  47.            }
  48.        ]
  49.        db.write_points(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement