def predict(self, date_to_predict=None): """ Return likelyhood that home has at least one human in it between 0-100 """ running = None try: if date_to_predict is None: date_to_predict = get_current_datetime() hour = HourOfDayResource.hour(date_to_predict) weekday = date_to_predict.date().weekday() running = self.predictor.predict("device_running", [ FakeFeatureColumn("day_of_week", weekday), FakeFeatureColumn("hour_of_day", hour) ]) except Exception: 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) finally: return running
def poll(self): while True: try: t = get_current_datetime(utc=True) self.set_value("current_power", get_solar_radiation(self.lat, self.lon, t)) except Exception as ex: print("error getting solar insolation: {}".format(ex)) yield from asyncio.sleep(MINS(3))
def get_standard_forecast(self, forecast_date=None): if forecast_date is None: forecast_date = get_current_datetime() fc = hourly(self.key, forecast_date, self.lat, self.lon) fc_standard = {} fc_standard["forecast_high"] = fc["main"]["temp_max"] fc_standard["forecast_low"] = fc["main"]["temp_min"] fc_standard["forecast_cloud_cover"] = fc['clouds']['all'] fc_standard['forecast_conditions'] = fc["weather"][0]["main"]
def predict_solar(self, t=None): if t is None: t = get_current_datetime() weather = gr("weather") forecast = weather.get_standard_forecast(t) cloud_cover = forecast["forecast_cloud_cover"] solar_insolation = gr("SolarInsolation") radiation_forecast = solar_insolation.get_solar_radiation( t.astimezone(pytz.utc)) return self.solar_predictor.predict(replace_features=[ ReplaceFeatureColumn("solar_insolation", radiation_forecast), ReplaceFeatureColumn("weather", forecast) ])
def predict_occupancy(self, date_to_predict=None): """ Return likelyhood that home has at least one human in it between 0-100""" try: if date_to_predict is None: date_to_predict = get_current_datetime() hour = HourOfDayResource.hour(date_to_predict) hour_of_week_fl = FakeFeatureColumn( "day_of_week", float64(date_to_predict.date().weekday())) hour_of_day_fl = FakeFeatureColumn("hour_of_day", hour) occupancy = self.predictors.predict( replace_features=[hour_of_day_fl, hour_of_week_fl], convert_func=lstm_convert_dataset) print("predicted occupancy: {}".format(round(occupancy, 2))) return occupancy except ValueError: print("Failed to predict. Model probably not trained yet") 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) except Exception: print("failed to predict occupancy") 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)
def predict_temperature(self, t=None): if t is None: t = get_current_datetime() weather = gr("weather") forecast = weather.get_forecast(t) cloud_cover = forecast['forecast_cloud_cover'] weather_temperature = forecast['forecast_high'] solar_insolation = gr("SolarInsolation") radiation_forecast = solar_insolation.get_solar_radiation( t.astimezone(pytz.utc)) solar_power_prediction = self.predict_solar(t) return self.solar_predictor.predict(replace_features=[ ReplaceFeatureColumn("solar_insolation", radiation_forecast), ReplaceFeatureColumn("weather_cloud_cover", cloud_cover), ReplaceFeatureColumn("weather_temperature", weather_temperature), ReplaceFeatureColumn("solar_power", solar_power_prediction) ])
def get_forecast(self, forecast_date=None): if forecast_date is None: forecast_date = get_current_datetime() return hourly(self.key, forecast_date, self.lat, self.lon)
def forecast(key, lat, lon): now = get_current_datetime() day_tomorrow = (now + timedelta(days=1)) return hourly(key, day_tomorrow, lat, lon)
def do_process(self): print("ecobee processing: ") print("time: {}".format(get_current_datetime())) current_program = self.ecobee_service.current_program predict_time = (datetime.now() + timedelta(minutes=60)) occupancy_prediction_60 = None op = self.occupancy_predictor if self.occupancy_predictor is not None: occupancy_prediction_60 = yield from run_thread( op.predict_occupancy, predict_time) if occupancy_prediction_60 is None: return is_night_time = self.night_time_resource.getValue("night_time") can_run = self.can_run() max_room_temp_delta = 40 temp_min, temp_max = yield from run_thread( self.ecobee_service.get_sensor_min_max, max_capability_filter="occupancy", max_capability_filter_value="true") print("min: {} max: {}".format(temp_min, temp_max)) print("max temp delta: {}".format(max_room_temp_delta)) print(f"current delta: {temp_max - temp_min}") print("current_program: {}".format(current_program)) print("occupancy: {}".format(self.ecobee_service.global_occupancy)) print("occupancy prediction: {}".format(self.occupancy_prediction)) print("occupancy 60min prediction: {} at {}".format( round(occupancy_prediction_60, 2), predict_time)) print("current running power: {}".format( round(self.device_manager.running_power, 2))) print("can run: {}".format(can_run)) print("is running: {}".format(self.running())) print("fan mode: {}".format(self.ecobee_service.fan_mode)) # get the typical home setpoints if current_program == Programs.home: self.setpoint_cool = self.ecobee_service.temperature_setpoint_cool self.setpoint_heat = self.ecobee_service.temperature_setpoint_heat """ if someone is home""" if self.ecobee_service.global_occupancy: if (not can_run and not is_night_time and current_program != Programs.hold and current_program != "overbudget"): print("we really shouldn't be running hvac right now.") print("remaining capacity is only {}".format( self.device_manager.remaining_power_capacity)) print("our total usage is estimated: {}".format( self.device_manager.running_power)) yield from run_thread( self.ecobee_service.set_hold, self.ecobee_service.temperature_setpoint_cool + 0.5, self.ecobee_service.temperature_setpoint_heat, custom_program_name="overbudget") elif can_run and current_program == "overbudget": yield from run_thread(self.ecobee_service.resume_program, resume_all=False) print("ecobee: resuming program") elif current_program == Programs.away: yield from run_thread(self.ecobee_service.set_program, Programs.home) print("ecobee: set program 'home'") if ( temp_max is not None and temp_min is not None and temp_max - temp_min > max_room_temp_delta): print("setting circulation program") yield from run_thread(self.ecobee_service.set_hold, fan_mode="on") elif (self.ecobee_service.fan_mode == "on"): yield from run_thread(self.ecobee_service.set_hold, fan_mode="auto") # if no one is home AND no one is usually home elif (not self.ecobee_service.global_occupancy and self.occupancy_prediction is False and current_program != Programs.away and current_program != Programs.hold): yield from run_thread(self.ecobee_service.set_program, Programs.away) print("ecobee: set program 'away'") # Is someone going to be home in the next 60 mins? elif (not self.ecobee_service.global_occupancy and occupancy_prediction_60 is not None and occupancy_prediction_60 >= 0.70 and current_program == Programs.away): yield from run_thread(self.ecobee_service.set_program, Programs.home) print("ecobee: set program to 'Home'") """else: print("ecobee: resuming program") self.ecobee_service.resume_program() """ current_program = self.ecobee_service.current_program # see if we need to modify the 'home' program according to # who is present if ((self.setpoint_cool and self.setpoint_heat) and (current_program == Programs.home)): heat_mod, cool_mod = self.get_user_modifier() sp_cool = self.ecobee_service.temperature_setpoint_cool sp_heat = self.ecobee_service.temperature_setpoint_heat if heat_mod or cool_mod: if (self.setpoint_cool + cool_mod != sp_cool or self.setpoint_heat + heat_mod != sp_heat): yield from run_thread(self.ecobee_service.set_hold, self.setpoint_cool + cool_mod, self.setpoint_heat + heat_mod)