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
61 stars 55 forks source link

Add quarter hour aggregate granularity if the account supports it #29

Closed akoebbe closed 1 year ago

akoebbe commented 1 year ago

This adds support for quarter hour granularity support for utility accounts that indicate it's supported. Example demo.py output from an Evergy account:

start_time      end_time        consumption     provided_cost   start_minus_prev_end    end_minus_prev_end
2023-07-31 00:00:00-05:00       2023-07-31 00:15:00-05:00       0.4008  0.042793416     None    None
2023-07-31 00:15:00-05:00       2023-07-31 00:30:00-05:00       0.216   0.02306232      0:00:00 0:15:00
2023-07-31 00:30:00-05:00       2023-07-31 00:45:00-05:00       0.2796  0.029852892     0:00:00 0:15:00
2023-07-31 00:45:00-05:00       2023-07-31 01:00:00-05:00       0.2388  0.025496676     0:00:00 0:15:00
2023-07-31 01:00:00-05:00       2023-07-31 01:15:00-05:00       0.2388  0.025496676     0:00:00 0:15:00
2023-07-31 01:15:00-05:00       2023-07-31 01:30:00-05:00       0.2754  0.029404458     0:00:00 0:15:00
2023-07-31 01:30:00-05:00       2023-07-31 01:45:00-05:00       0.246   0.02626542      0:00:00 0:15:00
2023-07-31 01:45:00-05:00       2023-07-31 02:00:00-05:00       0.186   0.01985922      0:00:00 0:15:00
2023-07-31 02:00:00-05:00       2023-07-31 02:15:00-05:00       0.2514  0.026841978     0:00:00 0:15:00
2023-07-31 02:15:00-05:00       2023-07-31 02:30:00-05:00       0.2352  0.025112304     0:00:00 0:15:00
2023-07-31 02:30:00-05:00       2023-07-31 02:45:00-05:00       0.1914  0.020435778     0:00:00 0:15:00
2023-07-31 02:45:00-05:00       2023-07-31 03:00:00-05:00       0.2322  0.024791994     0:00:00 0:15:00

It sounds like there may be accounts that report readResolution: "QUARTER_HOUR", but actually do not have that level of granularity. This should be tested with such an account to see if it fails gracefully or needs any change to accommodate.

tronikos commented 1 year ago

I've omitted it on purpose because it doesn't work for me. For example I get:

start_time      end_time        consumption     provided_cost   start_minus_prev_end    end_minus_prev_end
2023-07-31 00:00:00-07:00       2023-07-31 00:15:00-07:00       0.5947  0.266996512     None    None
2023-07-31 01:00:00-07:00       2023-07-31 01:15:00-07:00       0.5299  0.237903904     0:45:00 1:00:00
2023-07-31 02:00:00-07:00       2023-07-31 02:15:00-07:00       0.5649  0.253617504     0:45:00 1:00:00
2023-07-31 03:00:00-07:00       2023-07-31 03:15:00-07:00       0.5434  0.243964864     0:45:00 1:00:00
2023-07-31 04:00:00-07:00       2023-07-31 04:15:00-07:00       0.4808  0.215859968     0:45:00 1:00:00
2023-07-31 05:00:00-07:00       2023-07-31 05:15:00-07:00       0.469   0.21056224      0:45:00 1:00:00
2023-07-31 06:00:00-07:00       2023-07-31 06:15:00-07:00       0.378   0.16970688      0:45:00 1:00:00
2023-07-31 07:00:00-07:00       2023-07-31 07:15:00-07:00       -1.0051 -0.415799819    0:45:00 1:00:00
2023-07-31 08:00:00-07:00       2023-07-31 08:15:00-07:00       -3.0766 -1.272758654    0:45:00 1:00:00
2023-07-31 09:00:00-07:00       2023-07-31 09:15:00-07:00       -4.6547 -1.925602843    0:45:00 1:00:00
2023-07-31 10:00:00-07:00       2023-07-31 10:15:00-07:00       -6.0646 -2.508864374    0:45:00 1:00:00
2023-07-31 11:00:00-07:00       2023-07-31 11:15:00-07:00       -6.2613 -2.590237197    0:45:00 1:00:00
2023-07-31 12:00:00-07:00       2023-07-31 12:15:00-07:00       -5.6326 -2.330150294    0:45:00 1:00:00
2023-07-31 13:00:00-07:00       2023-07-31 13:15:00-07:00       -6.3174 -2.613445206    0:45:00 1:00:00
2023-07-31 14:00:00-07:00       2023-07-31 14:15:00-07:00       -4.2407 -1.754335183    0:45:00 1:00:00
2023-07-31 15:00:00-07:00       2023-07-31 15:15:00-07:00       -2.9141 -1.205534029    0:45:00 1:00:00
2023-07-31 16:00:00-07:00       2023-07-31 16:15:00-07:00       -1.7222 -0.856157286    0:45:00 1:00:00
2023-07-31 17:00:00-07:00       2023-07-31 17:15:00-07:00       -1.1796 -0.586414548    0:45:00 1:00:00
2023-07-31 18:00:00-07:00       2023-07-31 18:15:00-07:00       0.1618  0.08614232      0:45:00 1:00:00
2023-07-31 19:00:00-07:00       2023-07-31 19:15:00-07:00       0.2867  0.15263908      0:45:00 1:00:00
2023-07-31 20:00:00-07:00       2023-07-31 20:15:00-07:00       0.6676  0.35543024      0:45:00 1:00:00
2023-07-31 21:00:00-07:00       2023-07-31 21:15:00-07:00       0.731   0.32818976      0:45:00 1:00:00
2023-07-31 22:00:00-07:00       2023-07-31 22:15:00-07:00       4.2808  1.921907968     0:45:00 1:00:00
2023-07-31 23:00:00-07:00       2023-07-31 23:15:00-07:00       2.5029  1.123701984     0:45:00 1:00:00

Notice start_minus_prev_end is always 45m, end_minus_prev_end is always 1h. For you they are 0 and 15m as expected. The accounts data is similar to yours at https://github.com/tronikos/opower/discussions/18#discussioncomment-6658769 so there doesn't seem to be any indicator to check whether quarter_hour is really supported.

How are you intending to use this? I don't want it to end up in the Home Assistant core integration since it will break me. Home Assistant only seems to provide hour granularity at the energy dashboard anyway.

tronikos commented 1 year ago

I've added a comment that QUARTER_HOUR and the new HALF_HOUR I added earlier today are intentionally omitted. I'm closing this but feel free to change my mind.

akoebbe commented 1 year ago

Sorry this is a delayed response. I was just hoping to have higher resolution on consumption. That's all.

While I would like to see it working for those of us who do have legit data at the quarter hour, if your account response says you have that granularity but the actual data is erroneous, then I wouldn't things breaking for you and others in the same boat.