-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple local Tesla Energy Gateways (Powerwall/Inverters) using the server for local or cloud access #119
Comments
The first step was to solve the ability to query two Tesla Energy Gateways on a LAN by using variations in NAT: #128 (comment) The second is to get the pypowerwall proxy server to be able to handle multiple gateways. I am working on this, but it's not done yet: Draft PR Essentially the proxy server needs to compartmentalize each inverter into its own separate proxy server and then route each request from the virtual IPs configured in the scripts above. That simply requires a ton of refactoring and modularization. |
@Nexarian 🙇 The draft looks good! Thanks for kicking that off and for the much needed refactoring. I'll put my additional comments in the PR. |
@jasonacox Still not quite finished! I've been going through it line-by-line, doing my best to preserve functionality while increasing modularity and maintainability. I also haven't actually tested this yet, because this refactor is so invasive I can't really do that until I'm finished. The main points in the PR are:
A few things things I'm still not sure yet is how to handle:
However, we could conceivably move this to JSON or YAML as well, but that's likely to break many things. Thanks for your support on this, it's taking me forever to get this honed in! Several late nights of coding so far! Also: I understand that a massive refactor like this is a big pill to swallow. I'm happy to "part out" the finished version into more digestible chunks so we migrate the server to the final result slowly, while I continue to test the full version on my own systems. |
Thanks @Nexarian - I haven't seen anything otherwise, but please keep these project design principles in mind:
Note on your suggested refactoring - for the most part I think these make it more readable, just to be clear.
We should target MVP so that each incremental is still a working proxy, backward compatible, but could slowly walk toward the final outcome. What is in scope for MVP? I'm having some difficulty thinking what would be broken out unless you are thinking about deeper refactoring. |
For me, at least, the MVP is the proxy can handle two simultaneous calls (using the virtual IPs above) to retrieve internal TEG/string data in such a way that two sets of string data/internal TEG data can show up on the Powerwall dashboard. Each inverter has its own TEG rather than a standalone Gateway like most Powerwall setups have. Why Tesla chose that route, I'm not sure, but it's what makes my situation harder. As you mentioned the other way to do this might be to simply have two containers that report into InfluxDB, or to multiplex them with my earlier solution that alternates static routes. My solution is certainly "fancier" and thus may violate simplicity over cleverness. Still, I don't think it unreasonable to say the system should support querying multiple TEGs simultaneously without fancy Docker manipulation (which might ALSO be a violation of that principle). MVP is As to the config, I will write it such a way that a simple "one TEG" setup will work, but it will also read multiple as well. Similar to how a black & white TV can read a color signal :) I am actually not planning on changing the API other than supporting multiple TEGs. |
As to how to part it out, I think there are multiple phases:
In no step would the API or functionality change, except for the expansion in the last one. |
Yes, I agree with you. There are several in the community that have multiple gateways (very larger systems) so this enhancement would work for them as well. The complexity concern is more related to the code readability than the functions. I think your proposal is very reasonable. |
The server.py refactor now works on my Raspberry PI; at least, it does for local access. I decided against using a config file given the way that environmental variables are used. You can simply do this:
I will continue testing. Feel free to check it out now! |
I love that approach @Nexarian - I was worried about the config file as well. |
Alright, I've made some progress on getting this to work on Powerwall-Dashboard, and... It's a bit trippy. See jasonacox/Powerwall-Dashboard#573 First, my crazy network script makes routing changes to Because I'm flipping on Getting Telegraf to connect to multiple TEGs was trivial though. Finally, as you mentioned earlier, we need to think about how to make the dashboard look good with multiple inverters. I thought it was a matter of doing something like this, but it's not. Looks like there are both InfluxDB queries and Grafana queries to change before that'll work correctly. |
It does seem like the keys are overwriting each other, yes, though all I know for sure is I simply see one set of 4 strings. Is there a script that builds the dashboard? Editing each of the charts looks to be very tedious. |
Each one is hand crafted inside the Grafana UI, I'm afraid to say. BUT I would only use dashboard.json, you can ignore the rest. |
My question was more about this: https://github.com/jasonacox/Powerwall-Dashboard/blob/main/influxdb/influxdb.sql Where did this come from? Also, the strings 1-11 queries confuse me, are there some Tesla systems that have 6 strings? (E & F?) Also: Inverters 1-6? Does this need to change to support multiple TEGs or should I leave it alone? |
Also a work of art.. I mean, hand crafted by me and the community. :)
Yes, Powerwall 3 have 6 strings (A-F). Over time, the community has expanded this to accomodate several different configurations (which I don't have) like 3 Phase services and Powerwall 3's.
If we want one InfluxDB for all the TEGs, then yes. It would need to have CQs set up for each. Basically copy each row and duplicate it for each TEG but with the related suffix on the SELECT data elements (e.g. site_instant_power would be site_instant_power_pw2, site_instant_power_pw3, etc). Those would project into (SELECT INTO) things like home, home_pw2, home_pw3, etc. We would then create dashboard panels that use those new elements. Yes, tedious. And someone nice may want to write a script that builds this all and we would love that person. 😀 However, I also have another idea, which may be more complex on the proxy side but easier on the user side. We could have the proxy do these aggregation, essentially sum up all the TEG values into a combined output for at least these key APIs used by the dashboard:
Some would need to be augmented (.e.g strings and alerts) to somehow identify the separate TEGs. This would likely require some logic change in the proxy, or perhaps we just add another endpoint (e.g. port 9675) that is the sum of all the TEGs. |
I've created #133 as a separate issue to resolve this. I think, given how complex these queries are, we DO need to generate them. Even modifying this file to handle my 2x inverter setup feels super tedious and error prone. I may need to solve that before I continue here; though I don't think it'll be hard. Something like Jinja2 makes short work of most templating problems. As to modifying the proxy to have some endpoints that aggregate and some endpoints that report metrics per TEG -- Yes, we need that. My Powerwall Dashboard "works" -- But many graphs and values are empty or zero, and the animation is not correct either, and that's because of this tension. The Tesla public app/API effectively does the aggregation for us, but we can't rely on that in TEDAPI local mode. |
Agree on all of that. Thanks @Nexarian . Also, I would love to see a screenshot of your dashboard, even current state. 🙏 |
The waves in the graph are my heat pump kicking in. It's cold here! |
That's awesome! Thanks @Nexarian ... and keep warm! ;-) |
I'm referencing this line:
TODO: Add support for multiple Powerwalls
As I have two side-by-side (SxS) Tesla 7.6 kw inverters, this feature is a must for me if I'm going to monitor my system using Powerwall dashboard, especially important is TEDAPI mode and a facility to alternate network routes to interleave data from the two.
This issue is to track development. I intend to tackle this myself.
The text was updated successfully, but these errors were encountered: