magico13 / PyEmVue

Python Library for the Emporia Vue Energy Monitor
MIT License
185 stars 36 forks source link

Requesting 1S does not work on chart_usage #18

Closed ryknuth closed 3 years ago

ryknuth commented 3 years ago

Am I not allowed to get chart_usage on a 1S scale?

Failure message: Exception has occurred: HTTPError 400 Client Error: Bad Request for url: https://api.emporiaenergy.com/AppAPI?apiMethod=getChartUsage&deviceGid=10366&channel=5&start=2021-05-25T04:23:15.941815Z&end=2021-06-01T04:23:15.941859Z&scale=1S&energyUnit=KilowattHours

Fails: usage_over_time, start_time = vue.get_chart_usage(devices[3].channels[4], datetime.datetime.utcnow()-datetime.timedelta(days=7), datetime.datetime.utcnow(), scale=Scale.SECOND.value, unit=Unit.KWH.value) usage_over_time, start_time = vue.get_chart_usage(devices[3].channels[4], datetime.datetime.utcnow()-datetime.timedelta(days=7), datetime.datetime.utcnow(), scale=Scale.MINUTE.value, unit=Unit.KWH.value)

Succeeds: usage_over_time, start_time = vue.get_chart_usage(devices[3].channels[4], datetime.datetime.utcnow()-datetime.timedelta(days=7), datetime.datetime.utcnow(), scale=Scale.MINUTES_15.value, unit=Unit.KWH.value)

usage_over_time, start_time = vue.get_chart_usage(devices[3].channels[4], datetime.datetime.utcnow()-datetime.timedelta(days=7), datetime.datetime.utcnow(), scale=Scale.HOUR.value, unit=Unit.KWH.value)

usage_over_time, start_time = vue.get_chart_usage(devices[3].channels[4], datetime.datetime.utcnow()-datetime.timedelta(days=7), datetime.datetime.utcnow(), scale=Scale.DAY.value, unit=Unit.KWH.value)

magico13 commented 3 years ago

Hi, I believe it is just that the timescale you're trying to get data over is too large. If you change the seconds request to instead be over the last hour instead of the last week it should return without issues. When you do a day or more against the raw API it returns a 400 with the body {"message":"getChartUsage requested too many buckets"}

ryknuth commented 3 years ago

Thank you! I got it to work now.

Did I miss this in the documentation? Should it be added a stipulation?