magico13 / PyEmVue

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

How to get In/out to grid kWh #51

Open rupesh97 opened 1 year ago

rupesh97 commented 1 year ago

First, thank you for creating this API. I have had great success with it. Among other things, I am using get_chart_usage() to fetch daily energy usage for various circuits.

For the main panel, I can retrieve the net energy flow for the day. We have solar, so power flows in both directions and this number can be positive or negative. However, I'd like to separately query "In from Grid" and "Out to Grid" kWh (what I'm getting is essentially a difference of the two). This should be possible since the Emporia UI shows those numbers separately for durations >= DAY, but I can't figure out how to do that with this API.

magico13 commented 1 year ago

I don't have solar so those don't come up for me but I believe you can get them from the get_device_list_usage endpoint, which is the one that maps to the data you see on the homepage of the Emporia app.

If you use a call like device_usage_dict = vue.get_device_list_usage(deviceGids=device_gids, instant=None, scale=Scale.DAY.value, unit=Unit.KWH.value) then there should be two channels on the main device, one for the To Grid and one for the From Grid. See this example for how to iterate through the object you get back from that call https://github.com/magico13/PyEmVue#typical-example---getting-recent-usage

Note that if you just want the daily data you can get on the main page of the app, that call will get the data for every device and channel in just one call, rather than making separate calls to the get_chart_usage endpoint. The get_chart_usage endpoint is good if you want data over a time range since it unsurprisingly corresponds to the "Graphs" page in the app.

rupesh97 commented 1 year ago

Thanks a ton Mike for leading me down the right path. I'm finding Emporia's internals quite confusing, with terms like "channel" overloaded to mean different things depending on the context.

As you point out, get_device_list_usage and get_chart_usage are purpose built calls to solve their own respective problems in Emporia's UI. I am able to get what I need from the former (but not latter) as channels MainsFromGrid and MainsToGrid. The fact that get_chart_usage doesn't return these measurements is consistent with the fact that you can't plot them over time in the Emporia UI.

PS: I am cognizant of the high query rate concerns that you may be alluding to. I am building a simple command line tool that I intend to query once/month to reconcile my utility bill with Emporia's measurements, so it shouldn't put any non trivial load on their servers.

Thanks again