emcniece / bchydro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Data points

Dreded opened this issue · comments

Thanks for making this!

so I see this can access all of the Datapoints for the current month just wondering how datapoints are supposed to be retrieved.

await bch.refresh(hourly=True)
for each in bch.usage.electricity:
    print(each)

that works but I am sure its not the intended way... and it may be a lack of sleep but I cannot decipher the intended way.

You got it! If we look at https://github.com/emcniece/bchydro/blob/master/bchydro/types.py#L86 there's a definition of usage:

class BCHydroDailyUsage:
    def __init__(
        self,
        electricity: List[BCHydroDailyElectricity],

Electricity is a list of BCHydroDailyElectricity objects. We can see the electricity details on https://github.com/emcniece/bchydro/blob/master/bchydro/types.py#L30 - they have cost and consumption properties that might be of interest.

So if you want to iterate and only print cost:

await bch.refresh(hourly=True)
for each in bch.usage.electricity:
    print(each.cost)

ahh so no way to print between a range of dates without iterating through and finding those dates first?

Not that is exposed through this package, yet. But what you could play with is these 2 lines: https://github.com/emcniece/bchydro/blob/master/bchydro/api.py#L217-L218

Changing StartDateTime and EndDateTime should let you scope a time. I'm not sure exactly how it behaves and whether data is available for the current day, so please do report your findings should you experiment!

We can set the StartDateTime and EndDateTime as desired without issue however it requires that DateRange be set to custom to query prior to the current billing period. Setting that means we don't get cost reported.

Additionally, the time in start/end datetimes is ignored, it'll always be for the entire day.

https://github.com/benpye/bchydro/tree/custom-date-range is how I've changed it currently - but with the DateRange caveat we might want a different API. Maybe something like get_usage_for_range?

Sure, get_usage_for_range sounds reasonable. It's been a while since I've looked at this, get_usage() accepts start and end params, and your branch clearly works with that. Is there any reason we can't just keep "DateRange": "custom", and give the start and end dates -1d defaults?

e: oh I see, setting "DateRange": "custom", removes cost reporting. Are the costs only gone for the current day? Are the costs present for the previous day with custom?

I don't know if anyone depends on it, but it means we don't get cost reported.

Quick reply! I edited my comment:

Are the costs only gone for the current day? Are the costs present for the previous day with custom?

I don't see the cost for any of the data points unfortunately :(

Ah, damn. Cost reporting is one of (if not the) biggest request from the Home Assistant community, so it's high priority. I imagine it would be possible to perform some estimation by extracting billing rates and past usage from the account data, but it could get tricky recalculating BCH's tiered billing rules. I wonder if the billing tiers are also contained in the API responses...