コード例 #1
0
def update_from_weather(cycle_id, cycle_durations, station_number, api_key):
    """
    Check the current weather conditions.  Update status if a weather event should stop
    the cycle.
    """

    # Get current weather
    weather = read_weather(station_number, api_key)
    
    # Turn off if too windy
    if wind_speed(weather) > 10:
        update_status("Canceled: Wind")
        logging.info("Skipping Cycle: %s Too Windy: %s MPH", cycle_id, wind_speed(weather))
        return [0 for unused in cycle_durations]
    
    # Turn off if humidity is too high
    if humidity(weather) > 90:
        update_status("Canceled: Humidity")
        logging.info("Skipping Cycle: %s Humidity too high: %s", cycle_id, humidity(weather))
        return [0 for unused in cycle_durations]

    # Reduce if rainfall in last 24 hours
    if current_rain(weather) > 0:
        update_status("Canceled: Rain")
        logging.info("Skipping Cycle: %s 3 hour rainfall: %s", cycle_id, current_rain(weather))
        return [0 for unused in cycle_durations]    
    
    return cycle_durations
コード例 #2
0
ファイル: recorder.py プロジェクト: bobhelander/house
def record_data(nest_user, nest_password, weather_station):
    """
    Collect the data and send it to the database
    """

    weather = read_weather(weather_station)
    nest = Nest(nest_user, nest_password)
    nest.login()
    nest.read_status()

    irrigation_state = sprinkler_state()
    alarm_zones = get_zone_state()

    data = {
        "entryDate": datetime.now(),
        "irrigation_zone1": irrigation_state["zone1"],
        "irrigation_zone2": irrigation_state["zone2"],
        "irrigation_zone3": irrigation_state["zone3"],
        "irrigation_zone4": irrigation_state["zone4"],
        "alarm_zone1": alarm_zones["zone1"],
        "alarm_zone2": alarm_zones["zone2"],
        "alarm_zone3": alarm_zones["zone3"],
        "alarm_zone4": alarm_zones["zone4"],
        "alarm_zone5": alarm_zones["zone5"],
        "alarm_zone6": alarm_zones["zone6"],
        "alarm_zone7": alarm_zones["zone7"],
        "alarm_zone8": alarm_zones["zone8"],
        "alarm_zone9": alarm_zones["zone9"],
        "outside_temp": temperature(weather),
        "outside_humidity": humidity(weather),
        "rainfall": current_rain(weather),
        "wind_speed": wind_speed(weather),
    }

    data.update(nest.history_states())
    update_history(data)
コード例 #3
0
ファイル: rest_service.py プロジェクト: bobhelander/house
 def GET(self):
     weather = external.read_weather(station_number=SETTINGS.get("weather", "station"),
                                     api_key=SETTINGS.get("weather", "api_key"))
     rainfall = external.current_rain(weather)
     return json.dumps({"3h": rainfall})