def getStatus(self): from core import ffNest from nest import utils as nest_utils self.deviceIndex(ffNest) structure = ffNest.structures[0] # TODO: This isnt working yet. This needs to use the same logic as above. if self._structure: structure = ffNest.structures[self._structure] self._away = structure.away device = ffNest.devices[self._device_index] self._temp = device.temperature if self._f: self._temp = nest_utils.c_to_f(self._temp) if device.mode == 'range': self._target_temperature_low, self._target_temperature_high = device.target else: self._target_temperature = device.target if self._f: self._target_temperature = nest_utils.c_to_f(device.target) self._target_temperature_type = device.mode self._hvac_fan_state = device.fan
def getStatus(self): from core import ffNestModule from nest import utils as nest_utils logging.critical('*************************** NEST GET STATUS **********************************') self.deviceIndex(ffNestModule) structure = ffNestModule.structures[0] # TODO: This isnt working yet. This needs to use the same logic as above. if self._structure: structure = ffNestModule.structures[self._structure] self._away = structure.away device = ffNestModule.devices[self._device_index] self._temp = device.temperature if self._f: self._temp = nest_utils.c_to_f(self._temp) if device.mode == 'range': self._target_temperature_low, self._target_temperature_high = device.target else: self._target_temperature = device.target if self._f: self._target_temperature = nest_utils.c_to_f(device.target) self._target_temperature_type = device.mode self._hvac_fan_state = device.fan
def gather_nest(u=USER, p=PASS): napi = nest.Nest(u, p) data = [] # Jason loves mad precision, yo. Lets turn that shiz down a notch. nu.decimal.getcontext().prec = 4 for structure in napi.structures: struct_name = structure.name for device in structure.devices: for m in metrics: data.append({'measurement': m, 'tags': {'structure': struct_name, 'device': device.name}, 'fields': {'value': getattr(device, m)}}) for m in metrics_convert: data.append({'measurement': m, 'tags': {'structure': struct_name, 'device': device.name}, 'fields': {'value': nu.c_to_f(getattr(device, m))}}) t = nu.c_to_f(structure.weather.current.temperature) data.append({'measurement': 'temperature', 'tags': {'structure': struct_name, 'device': 'Outside'}, 'fields': {'value': t}}) data.append({'measurement': 'humidity', 'tags': {'structure': struct_name, 'device': 'Outside'}, 'fields': {'value': structure.weather.current.humidity}}) return data
def _setlow(self, **kwargs): inc = False val = None try: try: val = int(kwargs.get('value')) except TypeError: inc = True self._checkconnect() for device in self.napi.devices: if self.address == device.serial[-14:].lower(): if device.mode == 'range': if not inc: device.temperature = (nest_utils.f_to_c(val), device.target[1]) self.logger.info("Mode is ranged, Setting lower bound to %i F", val) else: val = int(round(nest_utils.c_to_f(device.target[0]) - 1)) self.logger.info("Mode is ranged, decrementing lower bound to %i F", val) device.temperature = (nest_utils.f_to_c(val), device.target[1]) else: if not inc: device.temperature = nest_utils.f_to_c(val) else: val = int(round(nest_utils.c_to_f(device.target) - 1)) device.temperature = nest_utils.f_to_c(val) self.logger.info("Setting temperature to %i F.", val) self.set_driver('CLISPH', val) except requests.exceptions.HTTPError as e: self.logger.error('NestThermostat _settemp Caught exception: %s', e) return True
def report_data(thermostats): Away = structure.away devices = structure.devices Time_s = structure.weather.current.datetime.strftime('%H:%M:%S') for device in devices: try: Thermostat = device.where if Thermostat in thermostats: T_room = nest_utils.c_to_f(device.temperature) if Away: T_target = nest_utils.c_to_f(device.away_temperature[0]) app_log.info('-- Away mode enabled --') ## print('-- Away mode enabled --') else: T_target = nest_utils.c_to_f(device.target) H_stat = device.hvac_heater_state T_diff = T_room - T_target T_outside = nest_utils.c_to_f(structure.weather.current.temperature) app_log.info('\tSample Time : %s' % Time_s) app_log.info('\tRequesting_Thermostat : %s' % Thermostat) app_log.info('\tTemp_Differential : %s' % str(T_diff)) app_log.info('\tTemp_Room : %s' % str(T_room)) app_log.info('\tTemp_Target : %s' % str(T_target)) app_log.info('\tTemp_Outside : %s' % str(T_outside)) my_handler.setFormatter(blnk_formatter) app_log.info('') my_handler.setFormatter(log_formatter) except: pass
def gather_nest(u=USER, p=PASS): napi = nest.Nest(u, p) data = [] # Jason loves mad precision, yo. Lets turn that shiz down a notch. nu.decimal.getcontext().prec = 4 for structure in napi.structures: struct_name = structure.name for device in structure.devices: for m in metrics: data.append({ 'measurement': m, 'tags': { 'structure': struct_name, 'device': device.name }, 'fields': { 'value': getattr(device, m) } }) for m in metrics_convert: data.append({ 'measurement': m, 'tags': { 'structure': struct_name, 'device': device.name }, 'fields': { 'value': nu.c_to_f(getattr(device, m)) } }) t = nu.c_to_f(structure.weather.current.temperature) data.append({ 'measurement': 'temperature', 'tags': { 'structure': struct_name, 'device': 'Outside' }, 'fields': { 'value': t } }) data.append({ 'measurement': 'humidity', 'tags': { 'structure': struct_name, 'device': 'Outside' }, 'fields': { 'value': structure.weather.current.humidity } }) return data
def _discover(self, **kwargs): try: manifest = self.parent.config.get('manifest', {}) self.parent.poly.LOGGER.info("Discovering Nest Products...") self.parent.poly.LOGGER.info("User: %s", USERNAME) self.napi = nest.Nest(USERNAME,PASSWORD, local_time=True) for structure in self.napi.structures: self.parent.poly.LOGGER.info('Structure : %s' % structure.name) self.parent.poly.LOGGER.info(' Away : %s' % structure.away) self.parent.poly.LOGGER.info(' Postal Code : %s' % structure.postal_code) self.parent.poly.LOGGER.info(' Country : %s' % structure.country_code) self.parent.poly.LOGGER.info(' dr_reminder_enabled : %s' % structure.dr_reminder_enabled) self.parent.poly.LOGGER.info(' enhanced_auto_away_enabled : %s' % structure.enhanced_auto_away_enabled) self.parent.poly.LOGGER.info(' eta_preconditioning_active : %s' % structure.eta_preconditioning_active) self.parent.poly.LOGGER.info(' house_type : %s' % structure.house_type) self.parent.poly.LOGGER.info(' hvac_safety_shutoff_enabled : %s' % structure.hvac_safety_shutoff_enabled) self.parent.poly.LOGGER.info(' num_thermostats : %s' % structure.num_thermostats) self.parent.poly.LOGGER.info(' measurement_scale : %s' % structure.measurement_scale) self.parent.poly.LOGGER.info(' renovation_date : %s' % structure.renovation_date) self.parent.poly.LOGGER.info(' structure_area : %s' % structure.structure_area) for device in self.napi.devices: self.parent.poly.LOGGER.info(' Device: %s' % device.serial[-14:]) self.parent.poly.LOGGER.info(' Where: %s' % device.where) self.parent.poly.LOGGER.info(' Mode : %s' % device.mode) self.parent.poly.LOGGER.info(' Fan : %s' % device.fan) self.parent.poly.LOGGER.info(' Temp : %0.1fF' % nest_utils.c_to_f(device.temperature)) self.parent.poly.LOGGER.info(' Humidity : %0.1f%%' % device.humidity) self.parent.poly.LOGGER.info(' Away Heat: %0.1fF' % nest_utils.c_to_f(device.away_temperature[0])) self.parent.poly.LOGGER.info(' Away Cool: %0.1fF' % nest_utils.c_to_f(device.away_temperature[1])) self.parent.poly.LOGGER.info(' hvac_ac_state : %s' % device.hvac_ac_state) self.parent.poly.LOGGER.info(' hvac_cool_x2_state : %s' % device.hvac_cool_x2_state) self.parent.poly.LOGGER.info(' hvac_heater_state : %s' % device.hvac_heater_state) self.parent.poly.LOGGER.info(' hvac_aux_heater_state : %s' % device.hvac_aux_heater_state) self.parent.poly.LOGGER.info(' hvac_heat_x2_state : %s' % device.hvac_heat_x2_state) self.parent.poly.LOGGER.info(' hvac_heat_x3_state : %s' % device.hvac_heat_x3_state) self.parent.poly.LOGGER.info(' hvac_alt_heat_state : %s' % device.hvac_alt_heat_state) self.parent.poly.LOGGER.info(' hvac_alt_heat_x2_state: %s' % device.hvac_alt_heat_x2_state) self.parent.poly.LOGGER.info(' hvac_emer_heat_state : %s' % device.hvac_emer_heat_state) self.parent.poly.LOGGER.info(' online : %s' % device.online) self.parent.poly.LOGGER.info(' last_ip : %s' % device.last_ip) self.parent.poly.LOGGER.info(' local_ip : %s' % device.local_ip) self.parent.poly.LOGGER.info(' last_connection : %s' % device.last_connection) self.parent.poly.LOGGER.info(' error_code : %s' % device.error_code) self.parent.poly.LOGGER.info(' battery_level : %s' % device.battery_level) # ISY only allows 14 character limit on nodes, have to strip the serial number down to the last 14 chars. address = device.serial[-14:].lower() lnode = self.parent.get_node(address) if not lnode: self.parent.poly.LOGGER.info("New Thermostat Found.") self.parent.thermostats.append(NestThermostat(self.parent, self.parent.get_node('nestcontrol'), address, device.temperature, structure.name, device.where, manifest)) self.parent.update_config() except requests.exceptions.HTTPError as e: self.LOGGER.error('Nestcontrol _discover Caught exception: %s', e) return True
def data_log(structure, stage, log_dir, max_log_size): if not structure: p = get_parameters() for key,val in p.items(): exec(key + '=val') #get structure structure = get_napi(username, password) if not os.path.isfile(log_dir + 'nest_data.log'): header = 'Thermostat,Sample_Time,T_room,T_target,T_diff,Humidity_inside,Humidity_target,T_outside,H_stat,Fan,Away,Stage, T_setpoint\n' else: header = None log = open(log_dir + 'nest_data.log', 'a') if getSize(log) < max_log_size: # Limit log file size to 100 Mb warning = False if not header == None: log.write(header) Away = structure.away # Time_s = structure.weather.current.datetime.strftime('%Y-%m-%d %H:%M:%S') for device in structure.devices: Thermostat = device.where T_room = nest_utils.c_to_f(device.temperature) if Away: T_target = nest_utils.c_to_f(device.away_temperature[0]) app_log.info('-- Away mode enabled --') print('-- Away mode enabled --') else: T_target = nest_utils.c_to_f(device.target) H_stat = device.hvac_heater_state T_diff = T_room - T_target T_outside = nest_utils.c_to_f(structure.weather.current.temperature) hum_value = device.target_humidity humidity = device.humidity fan = device.fan T_setpoint = calc_setpoint(Thermostat) v_list = [Thermostat,Time_s,T_room,T_target,T_diff,humidity,hum_value,T_outside,H_stat,fan,Away,stage,T_setpoint] line = '' for v in v_list: line = line + str(v) + ',' line = line[:-1] log.write(line + '\n') msg = ('Data successfully written to ' + log.name) else: warning = True msg = ('Data log file ' + log.name + ' is full. Cannot write new data.') log.close() return(msg, warning)
def check_dp(): print "starting" w_url = 'http://api.wunderground.com/api/{}/geolookup/conditions/q/{}/{}.json'.format(args.apikey, args.state, args.city) w_raw = requests.get(w_url) w_cond = w_raw.json().get('current_observation','') w_dp = w_cond.get('dewpoint_f','') for structure in napi.structures: for device in structure.devices: temp = nest_utils.c_to_f(device.temperature) if w_dp >= args.dewpoint: print "temp was %s" % temp device.temperature = nest_utils.f_to_c(args.temp) print "dewpoint is at or above %s deg f, changed temp to %s" % (args.dewpoint, args.temp) elif w_dp < args.dewpoint: print "temp was %s" % temp device.temperature = nest_utils.f_to_c(args.temp + 1) print "dewpoint is below %s deg f, changed temp to %s" % (args.dewpoint, args.temp) else: print "can't determine dewpoint" pass print "finishing. checking again in %d minutes" % args.delay time.sleep(60 * args.delay)
def __init__(self, parent, primary, address, temperature, structurename, location, manifest=None): self.parent = parent self.LOGGER = self.parent.poly.LOGGER self.structurename = structurename self.location = location try: self.LOGGER.info('Initializing New Thermostat') self.napi = nest.Nest(USERNAME, PASSWORD, local_time=True) except requests.exceptions.HTTPError as e: self.LOGGER.error('NestThermostat __init__ Caught exception: %s', e) self.away = False self.online = False self.insidetemp = nest_utils.c_to_f(temperature) try: self.name = 'Nest ' + self.structurename + " " + self.location except TypeError as e: self.LOGGER.error( 'Caught TypeError on structurename or location, which means they don\'t exist. Using Generic name.' ) self.name = 'Nest Thermostat' self.address = address self.LOGGER.info("Adding new Nest Device: %s Current Temp: %i F", self.name, self.insidetemp) super(NestThermostat, self).__init__(parent, address, self.name, primary, manifest) self.update_info()
def lambda_handler(event, context): napi = nest.Nest(username, password) structure = napi.structures[0] if useFutureWeather: outsideTemprature = nest_utils.c_to_f( structure.weather.hourly[2].temperature) else: outsideTemprature = nest_utils.c_to_f( structure.weather.current.temperature) print 'Temperature used: %s' % outsideTemprature humidity = caluculateHumidity(outsideTemprature) for device in napi.devices: device.target_humidity = humidity return
def _setlow(self, **kwargs): inc = False try: try: val = int(kwargs.get('value')) except TypeError: inc = True self._checkconnect() for device in self.napi.devices: if self.address == device.serial[-14:].lower(): if device.mode == 'range': if not inc: device.temperature = (nest_utils.f_to_c(val), device.target[1]) self.LOGGER.info( "Mode is ranged, Setting lower bound to %i F", val) else: val = int( round(nest_utils.c_to_f(device.target[0]) - 1)) self.LOGGER.info( "Mode is ranged, decrementing lower bound to %i F", val) device.temperature = (nest_utils.f_to_c(val), device.target[1]) else: self.LOGGER.info("Setting temperature to %i F.", val) if not inc: device.temperature = nest_utils.f_to_c(val) else: val = int( round(nest_utils.c_to_f(device.target) - 1)) device.temperature = nest_utils.f_to_c(val) self.set_driver('CLISPH', val) except requests.exceptions.HTTPError as e: self.LOGGER.error('NestThermostat _settemp Caught exception: %s', e) return True
def emit_event(self): structure = next(iter(self.nest.structures)) device = next(iter(structure.devices)) weather = structure.weather json_body = [{ "measurement": "nest", "fields": { "indoor_temperature": c_to_f(device.temperature), "indoor_humidity": device.humidity, "target_indoor_temperature": c_to_f(device.target), "outdoor_temperature": c_to_f(weather.current.temperature), "outdoor_humidity": weather.current.humidity, "wind_speed": weather.current.wind.kph, }, "tags": { "wind_direction": weather.current.wind.direction, "mode": device.mode, "fan": device.fan, }, }] self.influx.write_points(json_body)
def calc_setpoint(thermostat): now = datetime.now() seconds = (now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() day = datetime.today().weekday() dev_sched = get_schedule(thermostat) day_sched = [x for x in dev_sched if x[0] == day] sp_first = 0 sp_last = len(day_sched) - 1 for sp in day_sched: # sp_next = None sp_next = day_sched.index(sp) + 1 if sp_next <= sp_last: if seconds >= sp[2] and seconds < day_sched[sp_next][2]: setpoint = sp[3] elif seconds < day_sched[sp_first][2] or seconds >= day_sched[sp_last][2]: setpoint = day_sched[sp_last][3] setpoint = round(nest_utils.c_to_f(setpoint), 0) print("Setpoint: %s" %(setpoint)) return setpoint
def __init__(self, parent, primary, address, temperature, structurename, location, manifest=None): self.parent = parent self.logger = self.parent.poly.logger self.structurename = structurename self.location = location try: self.logger.info('Initializing New Thermostat') self.napi = nest.Nest(USERNAME,PASSWORD, local_time=True) except requests.exceptions.HTTPError as e: self.logger.error('NestThermostat __init__ Caught exception: %s', e) self.away = False self.online = False self.insidetemp = nest_utils.c_to_f(temperature) try: self.name = 'Nest ' + self.structurename + " " + self.location except TypeError as e: self.logger.error('Caught TypeError on structurename or location, which means they don\'t exist. Using Generic name.') self.name = 'Nest Thermostat' self.address = address self.logger.info("Adding new Nest Device: %s Current Temp: %i F", self.name, self.insidetemp) super(NestThermostat, self).__init__(parent, address, self.name, primary, manifest) self.update_info()
def target_humidity(structure): if not structure: # Import credentials import ConfigParser Config = ConfigParser.ConfigParser() Config.read(sys.path[0] + os.sep + '.secrets') username = ConfigSectionMap(Config, 'Credentials')['username'] password = ConfigSectionMap(Config, 'Credentials')['password'] #get structure structure = get_napi(username, password) if structure: for device in structure.devices: temperature = nest_utils.c_to_f(structure.weather.current.temperature) #calculate linear regression of target humidty and round to base 5 integer hum_value = int(5 * round(float(((0.55 * temperature) + 31) - 2.5)/5)) if hum_value > max_hum: hum_value = max_hum if float(hum_value) != device.target_humidity: device._set('device', {'target_humidity': float(hum_value)}) else: hum_value = None return (hum_value)
def get_temp(nest_api): return n_utils.c_to_f(nest_api.devices[0].temperature)
def update_info(self): self.away = False try: self._checkconnect() self.logger.info("First structure update: %s", self.napi.structures[0].away) for structure in self.napi.structures: if self.structurename == structure.name: if structure.away: self.away = True for device in self.napi.devices: if self.address == device.serial[-14:].lower(): self.mode = device.mode if device.fan: self.set_driver('CLIFS', '1') else: self.set_driver('CLIFS', '0') self.online = device.online self.humidity = device.humidity if device.hvac_ac_state: self.state = '2' elif device.hvac_heater_state: self.state = '1' else: self.state = '0' self.insidetemp = int(round(nest_utils.c_to_f(device.temperature))) try: self.outsidetemp = int(round(nest_utils.c_to_f(self.napi.structures[0].weather.current.temperature))) except (TypeError) as e: self.logger.error('NestThermostat update_info Caught an exception: %s', e) self.outsidetemp = 0 if self.mode == 'range': self.targetlow = int(round(nest_utils.c_to_f(device.target[0]))) self.targethigh = int(round(nest_utils.c_to_f(device.target[1]))) self.logger.info("Target Temp is a range between %i F and %i F", self.targetlow, self.targethigh) else: self.targetlow = int(round(nest_utils.c_to_f(device.target))) self.logger.info('Target Temp is %i F', self.targetlow) self.targethigh = self.targetlow # TODO, clean this up into a dictionary or something clever. self.logger.info("Away %s: Mode: %s InsideTemp: %i F OutsideTemp: %i F TargetLow: %i F TargetHigh: %i F", self.away, self.mode, self.insidetemp, self.outsidetemp, self.targetlow, self.targethigh) if self.away: self.set_driver('CLIMD', '13') elif self.mode == 'range': self.set_driver('CLIMD', '3') elif self.mode == 'heat': self.set_driver('CLIMD', '1') elif self.mode == 'cool': self.set_driver('CLIMD', '2') elif self.mode == 'fan': self.set_driver('CLIMD', '6') else: self.set_driver('CLIMD', '0') self.set_driver('ST', int(self.insidetemp)) self.set_driver('CLISPC', self.targethigh) self.set_driver('CLISPH', self.targetlow) self.set_driver('CLIHUM', self.humidity) self.set_driver('CLIHCS', self.state) self.set_driver('GV2', self.outsidetemp) self.set_driver('GV4', self.online) except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e: self.logger.error('NestThermostat update_info Caught exception: %s', e) return
def convert(value): if convert_to_Fahrenheit: converted = nu.c_to_f(value) else: converted = value return converted
def _discover(self, **kwargs): try: manifest = self.parent.config.get('manifest', {}) self.parent.poly.LOGGER.info("Discovering Nest Products...") self.parent.poly.LOGGER.info("User: %s", USERNAME) self.napi = nest.Nest(USERNAME, PASSWORD, local_time=True) for structure in self.napi.structures: self.parent.poly.LOGGER.info('Structure : %s' % structure.name) self.parent.poly.LOGGER.info(' Away : %s' % structure.away) self.parent.poly.LOGGER.info( ' Postal Code : %s' % structure.postal_code) self.parent.poly.LOGGER.info( ' Country : %s' % structure.country_code) self.parent.poly.LOGGER.info( ' dr_reminder_enabled : %s' % structure.dr_reminder_enabled) self.parent.poly.LOGGER.info( ' enhanced_auto_away_enabled : %s' % structure.enhanced_auto_away_enabled) self.parent.poly.LOGGER.info( ' eta_preconditioning_active : %s' % structure.eta_preconditioning_active) self.parent.poly.LOGGER.info( ' house_type : %s' % structure.house_type) self.parent.poly.LOGGER.info( ' hvac_safety_shutoff_enabled : %s' % structure.hvac_safety_shutoff_enabled) self.parent.poly.LOGGER.info( ' num_thermostats : %s' % structure.num_thermostats) self.parent.poly.LOGGER.info( ' measurement_scale : %s' % structure.measurement_scale) self.parent.poly.LOGGER.info( ' renovation_date : %s' % structure.renovation_date) self.parent.poly.LOGGER.info( ' structure_area : %s' % structure.structure_area) for device in self.napi.devices: self.parent.poly.LOGGER.info(' Device: %s' % device.serial[-14:]) self.parent.poly.LOGGER.info(' Where: %s' % device.where) self.parent.poly.LOGGER.info(' Mode : %s' % device.mode) self.parent.poly.LOGGER.info(' Fan : %s' % device.fan) self.parent.poly.LOGGER.info( ' Temp : %0.1fF' % nest_utils.c_to_f(device.temperature)) self.parent.poly.LOGGER.info(' Humidity : %0.1f%%' % device.humidity) self.parent.poly.LOGGER.info( ' Away Heat: %0.1fF' % nest_utils.c_to_f(device.away_temperature[0])) self.parent.poly.LOGGER.info( ' Away Cool: %0.1fF' % nest_utils.c_to_f(device.away_temperature[1])) self.parent.poly.LOGGER.info( ' hvac_ac_state : %s' % device.hvac_ac_state) self.parent.poly.LOGGER.info( ' hvac_cool_x2_state : %s' % device.hvac_cool_x2_state) self.parent.poly.LOGGER.info( ' hvac_heater_state : %s' % device.hvac_heater_state) self.parent.poly.LOGGER.info( ' hvac_aux_heater_state : %s' % device.hvac_aux_heater_state) self.parent.poly.LOGGER.info( ' hvac_heat_x2_state : %s' % device.hvac_heat_x2_state) self.parent.poly.LOGGER.info( ' hvac_heat_x3_state : %s' % device.hvac_heat_x3_state) self.parent.poly.LOGGER.info( ' hvac_alt_heat_state : %s' % device.hvac_alt_heat_state) self.parent.poly.LOGGER.info( ' hvac_alt_heat_x2_state: %s' % device.hvac_alt_heat_x2_state) self.parent.poly.LOGGER.info( ' hvac_emer_heat_state : %s' % device.hvac_emer_heat_state) self.parent.poly.LOGGER.info( ' online : %s' % device.online) self.parent.poly.LOGGER.info( ' last_ip : %s' % device.last_ip) self.parent.poly.LOGGER.info( ' local_ip : %s' % device.local_ip) self.parent.poly.LOGGER.info( ' last_connection : %s' % device.last_connection) self.parent.poly.LOGGER.info( ' error_code : %s' % device.error_code) self.parent.poly.LOGGER.info( ' battery_level : %s' % device.battery_level) # ISY only allows 14 character limit on nodes, have to strip the serial number down to the last 14 chars. address = device.serial[-14:].lower() lnode = self.parent.get_node(address) if not lnode: self.parent.poly.LOGGER.info("New Thermostat Found.") self.parent.thermostats.append( NestThermostat(self.parent, self.parent.get_node('nestcontrol'), address, device.temperature, structure.name, device.where, manifest)) self.parent.update_config() except requests.exceptions.HTTPError as e: self.LOGGER.error('Nestcontrol _discover Caught exception: %s', e) return True
def get_curtemp(device): return nest_utils.c_to_f(device.temperature)
def get_target(nest_api): return n_utils.c_to_f(nest_api.devices[0].target)
def com_nest_c_to_f(temp_data): """ C to F temp conversion """ return nest_utils.c_to_f(temp_data)
def c_to_f(self, temp): return nest_utils.c_to_f(temp)
username = '******' password = '******' napi = nest.Nest(username, password) structure = napi.structures[0] nest = structure.devices[0] # Read device room temp print 'Reading PEP sensors' str_data=urllib2.urlopen("http://10.0.1.11/temp").read() device_temp = float(str_data.split(",")[0]) temp_diff = device_temp - nest.temperature new_nest_target = device_room_target_temp - temp_diff target_diff = new_nest_target - nest.target print 'Current device room temperature : %0.1f' % nest_utils.c_to_f(device_temp) print 'Current Nest temperature: %0.1f' % nest_utils.c_to_f(nest.temperature) print 'Temperature diff: %0.1f' % (temp_diff * 1.8) print 'Current Nest target: %0.1f' % nest_utils.c_to_f(nest.target) print 'Current device room target : %0.1f' % nest_utils.c_to_f(device_room_target_temp) print 'New Nest target: %0.1f' % nest_utils.c_to_f(new_nest_target) print 'Target difference: %0.1f' % (target_diff * 1.8) if abs(target_diff) > min_diff_to_alter_temp: print 'Setting Nest temp to %0.1f in order to achieve %0.1f in device room' % (nest_utils.c_to_f(new_nest_target), nest_utils.c_to_f(device_room_target_temp)) #nest.target = new_nest_target else: print 'Leaving temp unchanged'
def update_info(self): self.away = False try: self._checkconnect() self.LOGGER.info("First structure udpate: %s", self.napi.structures[0].away) for structure in self.napi.structures: if self.structurename == structure.name: if structure.away: self.away = True self.LOGGER.info('Us: %s Them: %s', self.away, structure.away) for device in self.napi.devices: if self.address == device.serial[-14:].lower(): self.mode = device.mode if device.fan: self.set_driver('CLIFS', '7') else: self.set_driver('CLIFS', '8') self.online = device.online self.humidity = device.humidity if device.hvac_ac_state: self.state = '2' elif device.hvac_heater_state: self.state = '1' else: self.state = '0' self.insidetemp = int( round(nest_utils.c_to_f(device.temperature))) self.outsidetemp = int( round( nest_utils.c_to_f(self.napi.structures[0].weather. current.temperature))) if self.mode == 'range': self.targetlow = int( round(nest_utils.c_to_f(device.target[0]))) self.targethigh = int( round(nest_utils.c_to_f(device.target[1]))) self.LOGGER.info( "Target Temp is a range between %i F and %i F", self.targetlow, self.targethigh) else: self.targetlow = int( round(nest_utils.c_to_f(device.target))) self.LOGGER.info('Target Temp is %i F', self.targetlow) self.targethigh = self.targetlow # TODO, clean this up into a dictionary or something clever. self.LOGGER.info( "Away %s: Mode: %s InsideTemp: %i F OutsideTemp: %i F TargetLow: %i F TargetHigh: %i F", self.away, self.mode, self.insidetemp, self.outsidetemp, self.targetlow, self.targethigh) if self.away: self.set_driver('CLIMD', '13') elif self.mode == 'range': self.set_driver('CLIMD', '3') elif self.mode == 'heat': self.set_driver('CLIMD', '1') elif self.mode == 'cool': self.set_driver('CLIMD', '2') elif self.mode == 'fan': self.set_driver('CLIMD', '6') else: self.set_driver('CLIMD', '0') self.set_driver('ST', int(self.insidetemp)) self.set_driver('CLISPC', self.targethigh) self.set_driver('CLISPH', self.targetlow) self.set_driver('CLIHUM', self.humidity) self.set_driver('CLIHCS', self.state) self.set_driver('GV2', self.outsidetemp) self.set_driver('GV4', self.online) except requests.exceptions.HTTPError as e: self.LOGGER.error( 'NestThermostat update_info Caught exception: %s', e) return
def ODR_override(): # Make sure connection with Nest server was established before continuing. Away = structure.away for device in structure.devices: T_name = device.where T_room = nest_utils.c_to_f(device.temperature) if Away: T_target = nest_utils.c_to_f(device.away_temperature[0]) try: app_log.info('-- Away mode enabled --') except: pass print('-- Away mode enabled --') else: T_target = nest_utils.c_to_f(device.target) H_stat = device.hvac_heater_state T_diff = T_room - T_target T_outside = nest_utils.c_to_f(structure.weather.current.temperature) for th in therm_list: if th.name == T_name: t = th t.seth_state(H_stat) # Check if thermostat was calling for recovery in previous loop and sets threashold temp to -0.75F to # maintain boost cycle until call for heat on device is satisfied. if t.active: t.set_thresh_1(-0.75) if float(T_diff) < float(Thresh_Stage_3) and H_stat == True: t.setstage(3) elif float(T_diff) < float(Thresh_Stage_2) and H_stat == True: t.setstage(2) elif float(T_diff) < float(t.thresh_1) and H_stat == True: t.setstage(1) else: t.setstage(0) if t.stage > 0: t.setactive(True) else: t.setactive(False) ## print 'Thermostat : %s' % T_name ## print 'Away Status : %s' % str(Away) ## print 'T_room : %s' % str(T_room) ## print 'T_target : %s' % str(T_target) ## print 'HVAC State : %s' % str(H_stat) ## print 'T_diff : %s' % str(T_diff) ## print 'T_thresh : %s' % str(t.thresh_1) ## print 'Device List : %s' % dev_list ## print '\n' update_status(t) # Write data to log file if option is set if log_data: d_log = data_log(structure, Stage, log_dir, max_log_size) if d_log[1]: try: app_log.warning(d_log[0]) except: pass print d_log[0] if get_target_stage()[0] > 0: rchk = threading.Timer(delay_rechk, main) rchk.start() else: rchk = None if dev_list: Increment_Temp()
def get_target_temp(device): return nest_utils.c_to_f(device.target)