This code is intended to give other developers insights into how to pull data from the nest thermostat. Making changes to websocket.py will break other parts of wfpiconsole Nest_main.py runs separate from wfpiconsole. It uses Nest_Read.py and Nest_Min_Max.py to read the temperature and humidity, create history files for the past 24 hours. It then creates a file data.txt with the data that will be displayed in the console. The program then sleeps for 5 minutes before it loops. The changes to websocket.py will take Data.txt and place them into the display. Nest_main.py import Nest_Read import time import Nest_Min_Max import json Nest_Min_Max.Define_arrays() while True: temperature, humidity = Nest_Read.read_temperature() Nest_Min_Max.add_record(temperature, humidity) temp_max, temp_max_ts = Nest_Min_Max.get_max(Nest_Min_Max.temp_arr) temp_min, temp_min_ts = Nest_Min_Max.get_min(Nest_Min_Max.temp_arr) print('Minimum',temp_min,temp_min_ts) print('Maximum',temp_max,temp_max_ts) # # Write information to file # x = {"temperature":temperature, "humidity":humidity, "temp_min":temp_min, "temp_min":temp_min, "temp_min_ts":temp_min_ts, "temp_max":temp_max, "temp_max_ts":temp_max_ts } y = json.dumps(x) if len(y)>= 10: f = open("data.txt", "w") f.write(y) f.close time.sleep(300) Nest_Read import json import requests import datetime project_id = 'MY PROJECT ID' client_id="MY CLIENT ID FOR NEST" client_secret = "MY CLIENT SECRET FOR NEST" redirect_uri = "https://www.google.com" code = 'MY CODE obtained when authorizing Nest Data access' def Open_Tokens(): # # Open token.txt and read Access Code and Refresh Code # print('open tokens') #f = open("C:/Nest_Python/tokens.txt", "r") f = open("tokens.txt", "r") y = f.read() f.close() dictionary = json.loads(y) access_token = dictionary["access_token"] expires = dictionary["expires"] refresh_token = dictionary["refresh_token"] print("access_token: ",access_token) #print("refresh_token: ",refresh_token) print("Expires ",expires) return(access_token, expires, refresh_token) def Write_Tokens(access_token, expires, refresh_token): # # Write information to file # print('write tokens') x = {"access_token": access_token, "expires":expires, "refresh_token":refresh_token } y = json.dumps(x) #f = open("C:/Nest_Python/tokens.txt", "w") f = open("tokens.txt", "w") f.write(y) f.close def get_access(client_id, client_secret, code, redirect_uri): # Getting access tokens #print ("") #print ("#") print ("Getting Tokens") #print ("#") params = ( ('client_id', client_id), ('client_secret', client_secret), ('code', code), ('grant_type', 'authorization_code'), ('redirect_uri', redirect_uri), ) response = requests.post('https://www.googleapis.com/oauth2/v4/token', params=params) response_json = response.json() #print (response_json) access_token = response_json['token_type'] + ' ' + str(response_json['access_token']) access_token = access_token[7:] #print('Access token: ' + access_token) refresh_token = response_json['refresh_token'] #print('Refresh token: ' + refresh_token) return access_token, refresh_token def refresh_access(client_id, client_secret, refresh_token): # Refresh access token #print ("") #print ("#") print ("Refreshing Token") #print ("#") params = ( ('client_id', client_id), ('client_secret', client_secret), ('refresh_token', refresh_token), ('grant_type', 'refresh_token'), ) print(params) response = requests.post('https://www.googleapis.com/oauth2/v4/token', params=params) print(response) response_json = response.json() access_token = response_json['token_type'] + ' ' + response_json['access_token'] expires_in = response_json['expires_in'] #print(response_json) #print(expires_in) expires_d = datetime.timedelta(seconds=(expires_in-15)) expires_dt = datetime.datetime.now() + expires_d expires = expires_dt.strftime("%d-%b-%Y (%H:%M:%S.%f)") #print(expires) #print('Access token: ' + access_token) Write_Tokens(access_token, expires, refresh_token) return access_token, expires def get_devices(project_id, access_token, expires, refresh_token): print('get devices') # Check for expired token expires_dt = datetime.datetime.strptime(expires,"%d-%b-%Y (%H:%M:%S.%f)") now = datetime.datetime.now() if now > expires_dt: access_token, expires = refresh_access(client_id, client_secret, refresh_token) url_get_devices = 'https://smartdevicemanagement.googleapis.com/v1/enterprises/' + project_id + '/devices' headers = { 'Content-Type': 'application/json', 'Authorization': access_token, } response = requests.get(url_get_devices, headers=headers) print(response.json()) response_json = response.json() #print(response_json) device_0_name = response_json['devices'][0]['name'] #print(device_0_name) return device_0_name def get_device_stats(device_0_name,access_token, expires, refresh_token): print('get_device_stats') # Check for expired token expires_dt = datetime.datetime.strptime(expires,"%d-%b-%Y (%H:%M:%S.%f)") now = datetime.datetime.now() if now > expires_dt: access_token, expires = refresh_access(client_id, client_secret, refresh_token) url_get_device = 'https://smartdevicemanagement.googleapis.com/v1/' + device_0_name headers = { 'Content-Type': 'application/json', 'Authorization': access_token, } response = requests.get(url_get_device, headers=headers) response_json = response.json() humidity = response_json['traits']['sdm.devices.traits.Humidity']['ambientHumidityPercent'] #print('Humidity:', humidity) temperature = response_json['traits']['sdm.devices.traits.Temperature']['ambientTemperatureCelsius'] temperature = (temperature * 9/5) + 32 temperature = round(temperature,1) print('Temperature:', temperature) return(temperature, humidity) def read_temperature(): print('read_temperature') access_token, expires, refresh_token = Open_Tokens() device_0_name = get_devices(project_id, access_token, expires, refresh_token) print(device_0_name) temperature, humidity = get_device_stats(device_0_name, access_token, expires, refresh_token) return temperature, humidity temperature, humidity = read_temperature() Nest_Min_Max.py import datetime import time import json def Define_arrays(): # Define arrays import array import json global temp_arr, time_arr, humid_arr f = open("history_temp.txt", "r") y = f.read() f.close() d = json.loads(y) temp_arr = array.array('f') temp_arr.fromlist(d) f = open("history_time.txt", "r") y = f.read() f.close() d = json.loads(y) time_arr = array.array('I') time_arr.fromlist(d) f = open("history_humid.txt", "r") y = f.read() f.close() d = json.loads(y) humid_arr = array.array('f') humid_arr.fromlist(d) def get_min(array_var): min_var = min(array_var) min_ind = temp_arr.index(min_var) min_ts_raw = time_arr[min_ind] min_ts = datetime.datetime.fromtimestamp(min_ts_raw) min_ts_str = min_ts.strftime("%I:%M %p") return min_var, min_ts_str def get_max(array_var): max_var = max(array_var) max_ind = temp_arr.index(max_var) max_ts_raw = time_arr[max_ind] max_ts = datetime.datetime.fromtimestamp(max_ts_raw) max_ts_str = max_ts.strftime("%I:%M %p") return max_var, max_ts_str def add_record(temperature, humidity): temp_arr.append(temperature) humid_arr.append(humidity) time_now = int(round(datetime.datetime.now().timestamp())) time_arr.append(time_now) loop_case = True while loop_case: count = time_arr.index(time_arr[-1]) if count > 288: temp_arr.pop(0) humid_arr.pop(0) time_arr.pop(0) else: loop_case = False temp_arr_z = json.dumps(temp_arr.tolist()) f = open("history_temp.txt", "w") f.write(temp_arr_z) f.close humid_arr_z = json.dumps(humid_arr.tolist()) f = open("history_humid.txt", "w") f.write(humid_arr_z) f.close time_arr_z = json.dumps(time_arr.tolist()) f = open("history_time.txt", "w") f.write(time_arr_z) f.close Nest_Data def get_data(): # # Open data.txt and read Values # import json f = open("data.txt", "r") y = f.read() f.close() dictionary = json.loads(y) in_temp = dictionary["temperature"] in_temp_min = dictionary["temp_min"] in_temp_min_ts = dictionary["temp_min_ts"] in_temp_max = dictionary["temp_max"] in_temp_max_ts = dictionary["temp_max_ts"] return(in_temp, in_temp_min,in_temp_min_ts, in_temp_max, in_temp_max_ts) Changes to websocket.py After line 219 # Update wfpiconsole display with derived TEMPEST observations # # get nest data # derivedObs.update(nest()) at the end def nest(): import Nest_Data in_temp, in_temp_min,in_temp_min_ts, in_temp_max, in_temp_max_ts = Nest_Data.get_data() # Store derived indoor AIR observations in Data dictionary derivedObs = {} derivedObs['inTemp'] = observation.Format([in_temp,'f'],'Temp') derivedObs['inTempMax'] = observation.Format([in_temp_max,'f',in_temp_max_ts],'Temp') derivedObs['inTempMin'] = observation.Format([in_temp_min,'f',in_temp_min_ts],'Temp') # Update wfpiconsole display with derived indoor AIR observations #updateDisplay(derivedObs,wfpiconsole,'indoorAir') return(derivedObs)