tronikos / opower

A Python library for getting historical and forecasted usage/cost from utilities that use opower.com such as PG&E
Apache License 2.0
53 stars 49 forks source link

15m granularity electric data via green button #43

Closed raylu closed 10 months ago

raylu commented 10 months ago

at the bottom right, PG&E has this button image which shows this interface image which lets you download a zip file of gas and electric data. the gas is still 24h granularity but the electric is the raw 15m data off the smart meter rather than 1h aggregations

I was able to pull the data with just the basic headers

async with aiohttp.ClientSession() as session:
    client = opower.Opower(session, 'pge', username, password)
    await client.async_login()
    await client.async_login()

    (customer,) = await client._async_get_customers()
    customer_uuid = customer['uuid']
    url = f'https://pge.opower.com/ei/edge/apis/DataBrowser-v1/cws/utilities/pge/customers/{customer_uuid}/usage_export/download?format=csv&startDate=2023-08-01&endDate=2023-09-01'
    async with session.get(url, headers=client._get_headers(), raise_for_status=True) as resp:
        zip = await resp.read()
    with open('data.zip', 'wb') as f:
        f.write(zip)

if you wanna get fancier you can pull the data straight out using zipfile: https://github.com/raylu/power/blob/main/get_data.py it also seems to support at least 24 concurrent queries (my code pulls 2010-10 to now, one month at a time)

tronikos commented 10 months ago

See https://github.com/tronikos/opower/blob/0a7066022a62c3d6abe4c1453c1adc24e1030fde/src/opower/opower.py#L52 and https://github.com/tronikos/opower/pull/29#issuecomment-1668930656

For me, PG&E reports hourly data even though it advertises it supports QUARTER_HOUR. When I download the data with the green button it seems they just divide my hourly usage by 4 and assign 1/4 to each quarter. When calling the API the library already uses with QUARTER_HOUR I get data only for the first quarter of each hour.

Do you get accurate data?

I've omitted it on purpose to avoid any issues to accounts like mine. The Home Assistant energy dashboard only supports hourly data anyway.

raylu commented 10 months ago

oof, I hadn't even considered the possibility that the data was bogus. although this is a different method (downloading the zip rather than requesting usage from /reads) and I get correct times (every 15 minutes instead of only the first 15 minutes of each hour), the usage is indeed always the same 4 numbers in every hour (0.04, 0.04, 0.04, 0.04, 0.10, 0.10, 0.10, 0.10, 0.05, 0.05, 0.05, 0.05, 0.28, 0.28, 0.28, 0.28)