magico13 / PyEmVue

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

Lower resolution than 1 hour chart usage is returning 400 #41

Closed zactuscactus closed 1 year ago

zactuscactus commented 1 year ago

Hello,

I am getting a HTTPError: 400 Client Error: Bad Request for url when trying to collect 1 minute or 1 second data. The request works fine for 1Hour or greater. In the past, I was able to collect 1S data, but it seems like it hasn't been collecting that for a few months.

This is the command I am running: usage_over_time_min, start_time_min = vue.get_chart_usage(devices[0].channels[chidx], time_now-datetime.timedelta(days=int(2)), time_now-datetime.timedelta(days=int(1)), scale='1Min', unit='KilowattHours')

And just swapping out 1Min to 1H or 1D works great. I have tried 1S, 1MIN, 1M, 1Min and it consistently returns the error shown below

HTTPError: 400 Client Error: Bad Request for url: https://api.emporiaenergy.com/AppAPI?apiMethod=getChartUsage&deviceGid=92157&channel=1,2,3&start=2022-11-19T16:00:00Z&end=2022-11-20T16:00:00Z&scale=1Min&energyUnit=KilowattHours

image

Any thoughts?

magico13 commented 1 year ago

There was a change a while back where they don't let you get such a large amount of detailed data. Try grabbing less than a day's worth at a time. I'll do a quick test as well.

zactuscactus commented 1 year ago

Thanks for the suggestion. I just tried that using the last 50 mins and that still doesn't work:

usage_over_time_min, start_time_min = vue.get_chart_usage(devices[0].channels[chidx], time_now-datetime.timedelta(hours=1), time_now-datetime.timedelta(minutes=10), scale='1Min', unit='KilowattHours')

produces:

400 Client Error: Bad Request for url: https://api.emporiaenergy.com/AppAPI?apiMethod=getChartUsage&deviceGid=92157&channel=1,2,3&start=2022-11-21T15:00:00Z&end=2022-11-21T15:50:00Z&scale=1Min&energyUnit=KilowattHours

magico13 commented 1 year ago

The scale has to be all capitalized. '1MIN' or '1S' otherwise you will get a 400. I use the Scale enum everywhere myself but I should probably throw an upper into that method to account for manual strings.

I can't get seconds-level data from more than a few hours ago, like only 3 hours or so. Minute data I am getting back correctly from over a day ago.

zactuscactus commented 1 year ago

I can confirm that it must be capital. Also, it seems I can only retrieve up to 14 hours of data in a single call currently. Thanks for the fast support.