@he1957 Sorry, I don't have info on the API but it seems that some people either have official info or are hacking it. Googling "Powerwall API" turns up this page
Powerwall 2 API ? | Tesla
I don't think that you need any additional connections to the Powerwall to accomplish the features that you are talking about. As you point out the Powerwall already automatically handles all the conditions except generator integration. A generator with an automatic transfer switch also provides fully automatic backup power. So we just have to make these two systems play nicely with each other. My thinking is that no modification to the Powerwall operation is necessary. All I am proposing is that we let generator take the place of the grid but only when the Powewall is about to die. So the generator transfer switch has to be between the Powerwall Backup Gateway and the grid. When the generator turns on, the Powerwall will just think that the grid came back up. However, we probably need to disconnect the solar panel grid interactive inverter whenever the generator is connected because we can imagine bad things happening if the grid interactive inverter tries to push power to the generator.
Normally, the generator would come on as soon as the grid goes down. We don't want that because solar and the Powerwall are our preferred sources of power. The generator and its transfer switch have their own controller which senses the grid going down and powers up the generator and disconnects the grid and connects the generator. Generator controllers typically also exercise the generators once a week without disconnecting the grid. Therefore, it would be best leave the generator controller functioning as undisturbed as possible. We do have to modify the generator operation to suppress the generator when power is available from the Powerwall.
@shs1 who started this thread said that his Kohler generator has an input that does just that.
So my idea is to build a third controller which I will call the "custom controller". The custom controller reads the state of charge (SoC) from the Powerwall. When the SoC gets to 10% the custom controller energizes two relays (contactors). One relay disconnects the solar panel grid interactive inverter and the other relay allows the generator controller to fire up the generator. (The generator controller already knows that there is no power from the grid.) Once the generator is powered up and switched in the Powerwall will thinks that the grid is back up and start taking power from its grid connection. The custom controller could let the generator run until the Powerwall was up to 90% which would give the generator the longest possible duty cycle. I would set my custom controller to turn the generator off when the Powerwall reached 50% because there is a chance that the sun has come out and the solar panels will be able to take over supplying power and charging the Powerwall and we would rather get our power from the solar panels than the generator if we can. The problem is that we disconnected the solar panels to run the generator so the only way to give the solar a chance to take over is to turn the generator off and reconnect the solar.
The bottom line is that the generator kicks in only when the batteries are about to die. When the batteries get back to 50% we let the batteries take over supplying power again. This setup lets the Powerwall and the generator cycle back and forth for as long as necessary until either the grid or solar can supply power and keep the Powerwall charged. It also utilizes the generator as efficiently as possible because the generator is charging the Powerwall which means that it doesn't have to run continuously.
There are three small downsides:
Downside 1: We don't get any benefit from solar while the custom controller is calling for the generator. This probably isn't too much of a loss because if the sun was shining the Powerwall probably would not have dropped to 10% in the first place. With the ample power that the generator can supply the Powerwall will charge from 10% to 50% in about an hour so that will be the on time of the generator. That will also be the time that we will go without the benefit of solar. And that will also be the time that we wait before checking to see if the solar has kicked in.
If the grid comes back on line while the custom controller is calling for the generator, the generator controller will shut down the generator and connect the grid regardless of what the custom controller input to the generator controller says to do. If we did nothing else, the custom controller would keep the solar disconnected until the battery gets up to 50%. That wouldn't be so bad. However, it would be easy to add a circuit to our custom controller to detect if the grid comes back on line and shut down the custom controller's "generator cycle". That would patch the solar back in without having to wait for the battery to reach 50%.
Downside 2: The generator will not be available to supplement solar and the Powerwall with peak power the way that the grid normally does. However the only way to do that would be to run the generator continuously while the grid was down which we don't want to do anyway. What we do want is for the generator to run as little as possible but when it is running we want it to be delivering close to its full rated output because that is where it is most efficient. We should size the generator at 50% to 100% higher in power than the Powerwall's maximum charge rate. The generator is primarily working as a battery charger but it also has to power the building at the same time that it is charging the battery.
Downside 3: We have to think in terms of living within a power budget whenever the grid is down. That budget is basically whatever the Powerwall can provide assuming no grid, no solar and no generator. If any of those other power source happen to be available, then we can exceed the budget but there is no guarantee that any of them will be available. It would be possible to add a manual override switch that forced the generator on. You would throw that switch when you knew that you needed more power than the Powerwall plus solar could provide. I would make that switch a three way switch with a position that prevented the generator from ever turning on. That would be be a good thing to have if you needed to ration fuel for the generator. (The generator controller will ignore the custom controller as long as the grid is up so the manual override switch will only take effect when the grid is down.)