Ejemplo n.º 1
0
def copy(settings):
    # Fetch readings from GoodWe
    date = datetime.strptime(settings.date, "%Y-%m-%d")
    gw = gw_api.GoodWeApi(settings.gw_station_id, settings.gw_account, settings.gw_password)
    data = gw.getDayReadings(date)

    if settings.pvo_system_id and settings.pvo_api_key:
        if settings.darksky_api_key:
            ds = ds_api.DarkSkyApi(settings.darksky_api_key)
            temperatures = ds.get_temperature_for_day(data['latitude'], data['longitude'], date)
        elif settings.openweather_api_key:
            ow = ow_api.OpenWeatherApi(settings.openweather_api_key)
            temperatures = ow.get_temperature_for_day(data['latitude'], data['longitude'], date)
        else:
            temperatures = None

        # Submit readings to PVOutput
        pvo = pvo_api.PVOutputApi(settings.pvo_system_id, settings.pvo_api_key)
        pvo.add_day(data['entries'], temperatures)
    else:
        for entry in data['entries']:
            logging.info("{}: {:6.0f} W {:6.2f} kWh".format(
                entry['dt'],
                entry['pgrid_w'],
                entry['eday_kwh'],
            ))
        logging.warning("Missing PVO id and/or key")
Ejemplo n.º 2
0
def get_temperature(settings, latitude, longitude):
    if settings.darksky_api_key:
        ds = ds_api.DarkSkyApi(settings.darksky_api_key)
        return ds.get_temperature(latitude, longitude)
    elif settings.openweather_api_key:
        ow = ow_api.OpenWeatherApi(settings.openweather_api_key)
        return ow.get_temperature(latitude, longitude)
    return None
Ejemplo n.º 3
0
def run_once(args):
    global last_eday_kwh

    # Check if we only want to run during daylight
    if args.city:
        a = Astral()
        sun = a[args.city].sun(local=True)
        now = datetime.time(datetime.now())
        if now < sun['dawn'].time() or now > sun['dusk'].time():
            logging.debug("Skipped upload as it's night")
            return

    # Fetch the last reading from GoodWe
    gw = gw_api.GoodWeApi(args.gw_station_id, args.gw_account,
                          args.gw_password)
    data = gw.getCurrentReadings()

    # Check if we want to abort when offline
    if args.skip_offline:
        if data['status'] == 'Offline':
            logging.debug("Skipped upload as the inverter is offline")
            return

    # Append reading to CSV file
    if args.csv:
        if data['status'] == 'Offline':
            logging.debug("Don't append offline data to CSV file")
        else:
            locale.setlocale(locale.LC_ALL, locale.getlocale())
            csv = gw_csv.GoodWeCSV(args.csv)
            csv.append(data)

    # Submit reading to PVOutput, if they differ from the previous set
    eday_kwh = data['eday_kwh']
    if data['pgrid_w'] == 0 and abs(eday_kwh - last_eday_kwh) < 0.001:
        logging.debug("Ignore unchanged reading")
    else:
        last_eday_kwh = eday_kwh

    if args.darksky_api_key:
        ds = ds_api.DarkSkyApi(args.darksky_api_key)
        data['temperature'] = ds.get_temperature(data['latitude'],
                                                 data['longitude'])

    voltage = data['grid_voltage']
    if args.pv_voltage:
        voltage = data['pv_voltage']

    pvo = pvo_api.PVOutputApi(args.pvo_system_id, args.pvo_api_key)
    pvo.add_status(data['pgrid_w'], last_eday_kwh, data.get('temperature'),
                   voltage)
Ejemplo n.º 4
0
def copy(args):
    # Fetch readings from GoodWe
    date = datetime.strptime(args.date, "%Y-%m-%d")

    gw = gw_api.GoodWeApi(args.gw_station_id, args.gw_account, args.gw_password)
    data = gw.getDayReadings(date)

    if args.darksky_api_key:
        ds = ds_api.DarkSkyApi(args.darksky_api_key)
        temperatures = ds.get_temperature_for_day(data['latitude'], data['longitude'], date)
    else:
        temperatures = None

    # Submit readings to PVOutput
    pvo = pvo_api.PVOutputApi(args.pvo_system_id, args.pvo_api_key)
    pvo.add_day(data['entries'], temperatures)
Ejemplo n.º 5
0
def get_temperature(settings, latitude, longitude):
    if settings.netatmo_username and settings.netatmo_password and settings.netatmo_client_id and settings.netatmo_client_secret:
        netatmo = netatmo_api.NetatmoApi(
            settings.netatmo_username,
            settings.netatmo_password,
            settings.netatmo_client_id,
            settings.netatmo_client_secret,
        )
        netatmo.authorize()
        if settings.netatmo_device_id:
            return netatmo.get_device_temperature(settings.netatmo_device_id)
        else:
            return netatmo.get_location_temperature(latitude, longitude)
    elif settings.darksky_api_key:
        ds = ds_api.DarkSkyApi(settings.darksky_api_key)
        return ds.get_temperature(latitude, longitude)
    return None
Ejemplo n.º 6
0
def copy(settings):
    # Confirm that MQTT config is not used for historic data
    if settings.mqtt_host:
        logging.error(
            "Bad configuration options. MQTT cannot be used for backfilling historic data. Remove MQTT options from configuration and specify Goodwe (SEMS Portal details)."
        )
        sys.exit(1)

    # Fetch readings from GoodWe
    date = datetime.strptime(settings.date, "%Y-%m-%d")
    goodwe = gw_api.GoodWeApi(settings.gw_station_id, settings.gw_account,
                              settings.gw_password)
    data = goodwe.getDayReadings(date)

    if settings.pvo_system_id and settings.pvo_api_key:
        if settings.darksky_api_key:
            ds = ds_api.DarkSkyApi(settings.darksky_api_key)
            temperatures = ds.get_temperature_for_day(data['latitude'],
                                                      data['longitude'], date)
        elif settings.openweather_api_key:
            ow = ow_api.OpenWeatherApi(settings.openweather_api_key)
            temperatures = ow.get_temperature_for_day(data['latitude'],
                                                      data['longitude'], date)
        else:
            temperatures = None

        # Submit readings to PVOutput
        pvo = pvo_api.PVOutputApi(settings.telegram_token,
                                  settings.telegram_chatid,
                                  settings.pvo_system_id, settings.pvo_api_key)
        pvo.add_day(data['entries'], temperatures)
    else:
        for entry in data['entries']:
            logging.info("{}: {:6.0f} W {:6.2f} kWh".format(
                entry['dt'],
                entry['pgrid_w'],
                entry['eday_kwh'],
            ))
        logging.warning("Missing PVO id and/or key")