tomhollander / PowerwallCompanion

Windows UWP app for monitoring your Tesla Powerwall 2 battery
9 stars 7 forks source link

Retrieve daily 5-minute data for a specified date #8

Closed peppersass closed 9 months ago

peppersass commented 2 years ago

It would be great if PowerWall Companion could download the 5-minute data for any specified date. Does the server support this? If so, and you don't want to implement that enhancement, can you tell me the format for specifying a date to the server? With that I think I can modify the "yesterday" code to do retrieval for a specified date, which would be more useful to me.

I figure the server must support retrieval for any date because the Tesla app can do it. But the app makes it difficult because you have to swipe from today's Energy chart/data all the way back to the desired date (which is even harder to do in the latest version) Also, the data downloaded by the Testa app rounds kilowatts to one decimal point instead of reporting watts to one decimal point, as PowerWall Companion does for Today and Yesterday data. I think this may be why the totals in a program I wrote to analyze the downloaded data by TOU don't match the totals reported by the Tesla app.

BTW, the monthly data I can get from Powerwall Companion's Year download is the only way I've been able to get a complete picture of how energy has been routed by the Gateway each month. Thanks! I'm curious, though, whether these totals are available on a daily basis. The Tesla app reports some, but not all of them on a daily basis.

tomhollander commented 2 years ago

Yeah I think this is doable. The calendar_history endpoint didn't exist at the time I built this feature, but it does now so I'll see if I can support detailed downloads for an arbitrary date.

peppersass commented 2 years ago

Thanks! Not to make it more complicated, but some people might need weekly, monthly or yearly data starting from a specified date. Would the calendar_history endpoint make that possible as well?

tomhollander commented 2 years ago

I think so... the endpoints aren't documented so it can be a bit finicky, but will see what I can do.

peppersass commented 2 years ago

Tom, any luck with endpoints?

peppersass commented 2 years ago

Hi Tom. Still would like to have the ability to download data for/from a specified date, but I've implemented a workaround to make it somewhat easier to archive my daily historical data for later processing. This is done by running Powerwall Companion each day with the Windows Task Scheduler.

I added condition-driven to the constructor in the Home screen that downloads yesterday's data and terminates the app. The condition isn't as clean as I'd like it to be. I found that passing command-line arguments to a UWP app is complicated and difficult to debug, so I conditioned the auto-download/terminate on existence of a flag file in Local storage. The data files are downloaded to Local storage, too.

Two downsides to this approach: 1) If for some reason the scheduled task doesn't run for more than 24 hours, say if the computer is turned off, then there's no way for Powerwall Companion to recover the missed daily data. However, I can fill in the missing data with the Tesla app (the app I wrote to process the data recognizes the different file formats of downloads by Powerwall Companion and the Tesla app.) 2), the flag file and downloaded files get erased when the app is redeployed. I'd have preferred to locate the flag file and data files elsewhere in the file system but, again, UWP makes that difficult to do and there was just so much time I was willing to spend on the project.

tomhollander commented 9 months ago

The app now supports historical views and downloads.