def get_future_set_temp(self): thermostat_response = self.ecobee_service.request_thermostats( selection=peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_program=True, include_events=True) ) thermostat = thermostat_response.thermostat_list[0] therm_time = datetime.strptime(thermostat.thermostat_time, '%Y-%m-%d %H:%M:%S') future_time = therm_time + timedelta(hours=1) day_of_week = future_time.weekday() time_of_day = math.floor((future_time.hour * 60 + future_time.minute) / 30) future_climate = thermostat.program.schedule[day_of_week][time_of_day] future_temp = [c.heat_temp / 10.0 for c in thermostat.program.climates if c.climate_ref == future_climate ][0] logger.debug('future temp based on schedule: %s', future_temp) current_event = [e for e in thermostat.events if e.running] if current_event: ce = current_event[0] end_event = datetime.strptime('{} {}'.format(ce.end_date, ce.end_time), '%Y-%m-%d %H:%M:%S') if end_event > future_time: future_temp = ce.heat_hold_temp / 10.0 logger.debug('Using Override Temp: %s', future_temp) return future_temp
def sensors(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_sensors=True) ) sensors = thermostat_response.thermostat_list[0].remote_sensors return sensors
def get_cur_inside_humidity(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_runtime=True) ) humidity = thermostat_response.thermostat_list[0].runtime.actual_humidity return float(humidity)
def get_cur_inside_temp(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_runtime=True) ) inside_temp = thermostat_response.thermostat_list[0].runtime.actual_temperature / 10.0 des_inside_temp = thermostat_response.thermostat_list[0].runtime.desired_heat / 10.0 return float(inside_temp), float(des_inside_temp)
def set_hold(self, cool_temperature=None, heat_temperature=None, custom_program_name=None, fan_mode=None): """ Sets the hold temperature setpoint(s). Either cool_temperature or heat_temperature must be set. Default cool_temperature or heat_temperature is the current temperature setpoint if None. If custom_program_name is set the program name along with the setpoint settings will be saved. """ if not cool_temperature: cool_temperature = self.temperature_setpoint_cool if not heat_temperature: heat_temperature = self.temperature_setpoint_heat if custom_program_name: self._custom_program_map[custom_program_name] = ( cool_temperature, heat_temperature) print("custom program map: \n{}".format(self._custom_program_map)) # temperature should be in Celcius. convert to F and multiply by 10 cool_temperature = int(c_to_f(cool_temperature) * 10) heat_temperature = int(c_to_f(heat_temperature) * 10) reg_val = ecobee.SelectionType.REGISTERED.value params = {"holdType": "nextTransition", "coolHoldTemp": cool_temperature, "heatHoldTemp": heat_temperature} if fan_mode is not None: params["fan"] = fan_mode response = self.service.update_thermostats( ecobee.Selection(selection_type=reg_val, selection_match=''), functions=[ecobee.Function( type="setHold", params=params)]) if response.status.code != 0: raise Exception('Failure while executing set_hold:\n{0}'.format( response.pretty_format()))
def occupied(self): thermostat_response = self.ecobee_service.request_thermostats( selection=peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_sensors=True, include_program=True, include_events=True) ) if thermostat_response.thermostat_list[0].program.current_climate_ref in ['home', 'sleep']: return True for sensor in thermostat_response.thermostat_list[0].remote_sensors: caps = [a.value == 'true' for a in sensor.capability if a.type == 'occupancy'] if any(caps): return True for event in thermostat_response.thermostat_list[0].events: if event.running and (event.heat_hold_temp > 640 or event.cool_hold_temp < 760): return True return False
def store_backlight_settings(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_settings=True) ) bl_settings: peb.Settings = thermostat_response.thermostat_list[0].settings new_bl_settings = peb.Settings() backlight_keys = [k for k in new_bl_settings.attribute_name_map.keys() if 'backlight' in k and k.lower() == k] different = False for k in backlight_keys: set = getattr(bl_settings, k) if set != getattr(self._backlight_off, k): different = True setattr(new_bl_settings, k, set) if not different: logger.debug('not saving, backlight already off') else: logger.debug('saving backlight settings') self.backlight_settings = new_bl_settings self.persist_to_shelf()
def update(self): print("ecobee: update()") response = None try: reg_val = ecobee.SelectionType.REGISTERED.value response = self.service.request_thermostats( ecobee.Selection(selection_type=reg_val, selection_match='', include_device=True, include_runtime=True, include_sensors=True, include_program=True, include_extended_runtime=True, include_events=True, include_weather=False)) except ecobee.exceptions.EcobeeApiException as e: print("error: EcobeeApiException") if e.status_code == 14: self.refresh_tokens() return elif e.status_code == 16: self.auth() self.refresh_tokens() except Exception: print("error getting thermostats") exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_tb(exc_traceback, limit=6, file=sys.stdout) traceback.print_exception(exc_type, exc_value, exc_traceback, limit=6, file=sys.stdout) return if (response.thermostat_list is None or not len(response.thermostat_list)): raise Exception("No thermostats found") thermostat = None for dev in response.thermostat_list: if dev.name == self.thermostat_name: thermostat = dev break # we only support one thermostat... if not thermostat: print("ecobee: I can't find thermostate {}".format( self.thermostat_name)) return self.thermostat = thermostat self._temperature = f_to_c( thermostat.runtime.actual_temperature / 10.0) self._humidity = thermostat.runtime.actual_humidity self._setpoint_cool = round( f_to_c(thermostat.runtime.desired_cool / 10.0), 1) self._setpoint_heat = round( f_to_c(thermostat.runtime.desired_heat / 10.0), 1) self._running_program = thermostat.program.current_climate_ref # running program may not be accurate if there is a running hold event # with a hold_climate_ref for event in thermostat.events: if event.running and event.type == 'hold': self._running_program = event.hold_climate_ref # finally, a hold might be a custom program, let's check custom_program = self.is_custom_program(self._setpoint_cool, self._setpoint_heat) if custom_program: self._running_program = custom_program self._global_occupancy = self.get_occupancy() return thermostat
def get_fan_min_on_time(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_settings=True) ) return thermostat_response.thermostat_list[0].settings.fan_min_on_time
def get_cur_hvac_mode(self): thermostat_response = self.ecobee_service.request_thermostats( peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', include_equipment_status=True) ) return thermostat_response.thermostat_list[0].equipment_status
def _selection(self, **kwargs): return peb.Selection(selection_type=peb.SelectionType.REGISTERED.value, selection_match='', **kwargs)