Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Tesla Wall Connector load sharing protocol

This site may earn commission on affiliate links.
@Nietschy I also have a fronious inverter and smart meter - getting the real time excess current is only half the solution. Have you modified the rest of the code so that the amount of charge actually changes appropriately?

Working through the logic - assuming you are making 5kw of power from the panels and your house is consuming 2kw, then prior to charging you have 3kw of excess. On the first loop the excess mains current means the car charges at 3kw (as desired).
However on the second loop, the AC fed to the mains is now 0 (5kw solar = 2kw house + 3kw car + 0 excess). The Fronius can't distinguish between the house and the car, it simply reports a load = 5kw. If you base the charge current off the excess mains reading, 0 excess causes it to stop charging.

As written, CDragon's code doesn't store the current car current. I modified mine (very inelegantly) so that there is a persistent variable that stores "last_current_to_car", then there is a loop that says "new current to car = last_current_to_car + excess/240".

@CDragon it would be great if you could make this a toggle in the settings or similar, for everyone who has real time load monitoring capabilities as well as real time solar output monitoring.
Hi Gingerbeer, Nietschyl
I also have a Fronius based system (PV inverter + Smartmeter). I have programmed what you want to have in this way.
Set greenEnergyAmpsOffset = 0

and then calculate:
greenEnergyData = SmartMeterReading + self.reportedAmpsActual*HouseVoltage

1st loop the SmarMeterReading is equal to your current energy surplus (Photovoltaic - your house load). The car is allowed to charge with all this surplus. Ex. Phovotoltaic 5kW, house loads 2kW, surplus is 3kW. TWC set to 3kW

2nd loop. Once the car start charging, the surplus decreases as the self.reportedAmpsActual increase. So second loop example (assume TWC has not yet ramped up to 3kW, but instead 1.5kW) Photovoltaic 5kW - house loads 2kW - TWC 1.5kW surplus is 1.5kW add the self.reportedAmpsActual and you get again 3kW. TWC set to 3kW. Is looking good.

3rd loop. Charge ramping done (3kW actual). Example:
SmarMeter reads (Photovoltaik 5kW -house loads 2kW - TWC 3kW) = 0 kW plus TWC current 3kW means Surplus is 3kW. Set TWC to 3kW. All GOOD!

4th loop: Your wife starts the Washingmachine, takes 1kW suddenly. Example
SmarMeter reads (Photovoltaic 5kW - house loads 3 kW - TWC 3kW ) = -1kW plus TWC current 3kW means surplus is 2kW. Set TWC to 2kW. Now we have a dynamic house load algorithm.

Note this works properly if the information from smarmeter and self.reportedAmpsActual are not too out of phase. I could not find in the TWCManager.py the position where the greenEnergyData sample rate is defined. QUESTION TO EXPERTS: Does it poll it every 2s? 10s 60s? I have no idea. Our Smarmeter info gets updated once every 2s (I am using Modbus TCP, I do not like json API), so this *could* be read every 2 s as well, but whether it makes sense depence of how often the TWC commands the slaves with a current value (4s?)
 
greenEnergyData = SmartMeterReading + self.reportedAmpsActual*HouseVoltage
Instead of using "self.reportedAmpsActual" I had to use "total_amps_actual_all_twcs()" since python would not find this self.* variable. I had yesterday a quick run and its working :)

Now only missing to shorten the update time of that reading, as I mentioned I could not find a way to decrease this time.
 
@Juanmax - to be gentle to the electronics in the car, and to avoid some Tesla server getting triggered for very frequent API calls I would keep the frequency at the 1-2 minute interval it currently is.

If it runs for 8 hrs /day in sunlight and there is a minute when you use a bit of grid power because you turned the oven on, that’s a trivial bit of inaccuracy in the grand scheme of things.
 
@Juanmax - to be gentle to the electronics in the car, and to avoid some Tesla server getting triggered for very frequent API calls I would keep the frequency at the 1-2 minute interval it currently is.

If it runs for 8 hrs /day in sunlight and there is a minute when you use a bit of grid power because you turned the oven on, that’s a trivial bit of inaccuracy in the grand scheme of things.
Hi, I am curently using the TWC to charge the BMW i3 from my wife. My model 3 I charge at work (for free). The BWM accepts anything from 5 A up to 32 A so it allows to make a nice photovoltaic matching curve. I did it earlier with a Phoenix controller using a Raspi and commanding it via ethernet, but I sold this parts and went the 2xTWC solution.

I have added the token for my 3, but I will remove it , since it constantly asking where the car is at what is it doing, which has almost no use for me.

So, where can I increase the rate of checking ? ;)
 
Anyone have an issue with the scheduler?
Two issues I’ve experienced:
I set schedule charge 11pm to 7am, weekdays, track green energy weekend and I get the following occur:

1.5-2hrs charging when car is connected, regardless of time.

Schedule working but still operates on weekends when it isn’t meant to.

anyone experiencing the same?

Only code change was getting the net energy from my Enphase envoy to link for green energy. This part works fine
 
Hi All,

Thanks to all contributing to this project. I'm about to get it up and running but have a different situation to most. I have 2 phases into my property. Phase1 has all the solar, Powerwall2 and house loads. The Powerwall2 doesn't have visibility/awareness of this second phase.

I recently had a HPWC installed and opted to have it installed on Phase2. Main reason was so it never pulled power from the Powerwall2.

What needs to be modified in the script to just utilise the power that the Powerwall2 is seeing being exported? This value will not change when the charging load comes on. The export on Phase1 offsets the import on Phase2 as far as usage/billing goes.

Thanks!
 
Basically I'm saying stop/start charge commands are useless for most purposes as they are implemented in firmware 4.5.3.
The reason cars respond badly seems to be that stop/start simply turn the relays in the TWC off or on but do not send any CAN message to the car telling it to stop or start (I reached those conclusions by looking at the firmware). My 2014 Model S responds to this by trying to use CAN to start the charger again (car ring flickers blue to show CAN communication) and after a bit it enters perma-error state unless DIP 2 is down which disables all CAN communication. Conceivably, Model 3 or X don't respond badly which is how this escaped quality control? If anyone has a 3 or X or a newer S, please test and let me know.

Thanks for all your work CDragon.

I've been playing around with the Stop/Start charging commands on a 2019 Model 3 (2019.36.2.2 186de86) using a TWC FW 4.5.3. (Extended version 4.5.3.2, (S)TSN: A19D0029819 (manufactured between Feb 12th and Feb 25th 2019, TWCID 9819)

It appears to exhibit identical behaviour.

The start charge command works o.k. (Assuming the car is not in unrecoverable error condition where it requires unplugging)

The stop charge command works (by opening the relay) and the car reports:
Unable to charge - Check power source / Check external charging equipment.
Unable to charge - Unplug and try again.
The only way to recover is to physically unplug the Type 2 cable from the vehicle.

It's a little disappointing. I've wanted to turn the charging on and off according to electricity price and demand on the grid. I might try the Tesla API, but it would have been better to do it at the single EVSE/TWC so it doesn't effect charging my vehicle at other sites such as public charging stations.
 
Hi All,

Thanks to all contributing to this project. I'm about to get it up and running but have a different situation to most. I have 2 phases into my property. Phase1 has all the solar, Powerwall2 and house loads. The Powerwall2 doesn't have visibility/awareness of this second phase.

I recently had a HPWC installed and opted to have it installed on Phase2. Main reason was so it never pulled power from the Powerwall2.

What needs to be modified in the script to just utilise the power that the Powerwall2 is seeing being exported? This value will not change when the charging load comes on. The export on Phase1 offsets the import on Phase2 as far as usage/billing goes.

Thanks!

For anyone interested, I got this working....

**************************ORIGINAL CODE ******************************

# supplement with allowable grid usage to make up to 6A if needed and powerwall is full enough

if(maxAmpsToDivideAmongSlaves < 6 and maxAmpsToDivideAmongSlaves + maxGridUsageFor6ACharge >= 6 and batteryPercent >= powerwallBatteryMinPercentageForGridShare):

if(debugLevel >= 4):

print(time_now() + ': Adding ' + str(6 - maxAmpsToDivideAmongSlaves) + 'A from grid to charge at 6A', '\n')

maxAmpsToDivideAmongSlaves = 6


# limit to solar production plus grid allowance

if(maxAmpsToDivideAmongSlaves > solarAmps + maxGridUsageFor6ACharge):

maxAmpsToDivideAmongSlaves = solarAmps + maxGridUsageFor6ACharge


****************************************************************


Need to remove the “solarAmps” value and replace with “gridExportAmps



*****************************UPDATED CODE ***************************


# supplement with allowable grid usage to make up to 6A if needed and powerwall is full enough

if(maxAmpsToDivideAmongSlaves < 6 and maxAmpsToDivideAmongSlaves + maxGridUsageFor6ACharge >= 6 and batteryPercent >= powerwallBatteryMinPercentageForGridShare):

if(debugLevel >= 4):

print(time_now() + ': Adding ' + str(6 - maxAmpsToDivideAmongSlaves) + 'A from grid to charge at 6A', '\n')

maxAmpsToDivideAmongSlaves = 6


# limit to solar production plus grid allowance

if(maxAmpsToDivideAmongSlaves > gridExportAmps + maxGridUsageFor6ACharge):

maxAmpsToDivideAmongSlaves = gridExportAmps + maxGridUsageFor6ACharge
 
I was all excited about this project, only now that it's winter my solar system went from a max of 32 kWh's a day when the system was new in Sept. to as little as just a few. It's peak solar time right now and I am getting 300 watts from the roof. Less than the Xmas lights are taking.

Perhaps I can teach myself to program again in the modern world while I wait for the return of solar production.
 
I installed 2 TWC's and control them with the standard TWC manager script from cdragon.
Our solar inverter is not connected yet and I just set Non-scheduled power: 8A to test the system.
I'm only charging with one car at the moment but I get a weird status message.
The first TWC is shown twice and the second is not visible.
They both work and respond to the fake master.

This is how it looks if I charge with the first TWC:
Schermafbeelding 2020-01-07 om 20.36.55.png

And this if I charge with the second TWC:
Schermafbeelding 2020-01-07 om 21.37.00.png


Like I said they work both alone but I could not try with two cars connected yet.

Has anyone experienced a similar problem? Or any idea why this happens?
 
Great work done here!
I've just installed a TWC to power our -14 Model S P85 and -20 Model 3 LR.
We have a fairly new house with low power draw, thus having 3x20A main fuses installed. This is well enough for the house and our Cars, but sometimes the peak draw would be too high.
I control most of the house using Hass.io including Cameras, Locks, Multimedia, HVAC, Hot Water, Floor heating, lights but also track our current draw and am able to align peak draw based on electricity spot price.
I've already set up an automation that can start charging and based on total draw also stop charging (Tesla API), but of course I'd like to be able to throttle the charging current instead of just stopping it. That's how I found you.
So, is there anyone of you using the work done here to just set the maximum current using rs485? Perfect for my system would be to set up a Wemos D1 mini using with a shield if that exists and ESP Home integration to Hass.io. My problem is I can't program, at all.
 
I installed 2 TWC's and control them with the standard TWC manager script from cdragon.

Has anyone experienced a similar problem? Or any idea why this happens?

I have the exact same setup as you and was having the same issue, I fixed chaging HTML/index.php contents (- old, + new). I found the solution elsewhere but I can not find it now...


// Display info about each TWC being managed.
- for($i = 0; $i < $status[$statusIdx]; $i++) {
- $subStatus = explode('~', $status[$statusIdx + 1]);

+ for($i = 1; $i <= $status[$statusIdx]; $i++) {
+ $subStatus = explode('~', $status[$statusIdx + $i]);

$twcModelMaxAmps = $subStatus[1];
- print("<strong>TWC " . $subStatus[0] . ':</strong> ');
+ print("</p><strong>TWC " . $subStatus[0] . ':</strong> ');
if($subStatus[2] < 1.0) {
/*if($subStatus[4] == 0) {
// I was hoping state 0 meant no car is plugged in, but
 
Well, it looks like the place I found the solution was really in this thread. I forked GITHUB and placed the change there:
Multiple TWC show error fixed by juamiso · Pull Request #17 · cdragon/TWCManager

New Wall Connector load sharing protocol
QUOTE="marlan99, post: 3177798, member: 62418"]since i have two Tesla Wall Connector installed i found a bug in the code which is responsible to display the TWC on the website (index.php):

i changed three lines (342,343,345) in the code and now it displays the correct values when more than one TWC is connected.
sorry for the pictures. was not able to copy&paste as text right now[/QUOTE]
 
I have just finished implementing the protocol in .NET. I'll happily post the code once a few kinks are ironed out. I'm using a TCP/RS485 converter.

I have two TWCs both in slave mode. My cars are a model 3 and model X - european UK.

I've found that if you send controlcode 05 and max amps, it starts charging at that current. All futher heartbeats with different amps are ignored. I then changed controlcode to 09 for subsequent updates and it immediately works.

I can't set amps less than 6 on either charger.

But the most important thing, and problem, is I cannot stop the charging at all. Sending control code 00 does nothing.

So - i think this means i need to install a physical contactor PER CAR so i can break the power connection completely. I had this before, and found that after a short delay once power is restored the cars start charging again. Its a shame because i will of course lose connection and be unable to establish if a car is connected or not.

This is designed to be a solar responsive system so i need to have reasonably rapid control. Currently once charging starts i cannot stop it, and the minimum charge with 2 cars connected is 12 amps which is too much!

Does anyone have any suggestions on how the protocol can stop charging? I've tried the obvious - sending 0 amps, different control codes.
 
Does anyone have any suggestions on how the protocol can stop charging? I've tried the obvious - sending 0 amps, different control codes.

I can tell you how to stop charging.... the only problem is you won't be able to restart charging on your Model 3 (not sure about the X) until you unplug and re-plug your Type 2 connector.

Try:

Potentially useful commands in firmware 4.5.3 are:
  • Remember, these commands won't work in TWCs containing firmware with a lower number than 4.5.3. 4.5.3 was included in TWCs manufactured around March 2018 and later.
  • FC B1 SS SS RR RR
    • Tell TWCID RR RR to start charging. SS SS is the fake master TWCID.
  • FC B2 SS SS RR RR
    • Tell TWCID RR RR to stop charging. SS SS is the fake master TWCID.
    • Stop charge command is seriously bugged in that it will cause a plugged-in Tesla to show a red ring around its charge port as soon as you send the command. Car will refuse to charge again until you send start charge command and then physically re-plug the car.
    • If you set DIP switch 2 in the TWC to the down position, it turns off CAN communication to the car and start/stop charge actually work correctly except if you stop and start charging more than once, the car will randomly decide the charger is bad and refuse to charge again until you re-plug the car. The car may also decide to limit itself to 30A charging and that change is permanent unless you raise amps using the car UI.
    • Basically I'm saying stop/start charge commands are useless for most purposes as they are implemented in firmware 4.5.3.
    • The reason cars respond badly seems to be that stop/start simply turn the relays in the TWC off or on but do not send any CAN message to the car telling it to stop or start (I reached those conclusions by looking at the firmware). My 2014 Model S responds to this by trying to use CAN to start the charger again (car ring flickers blue to show CAN communication) and after a bit it enters perma-error state unless DIP 2 is down which disables all CAN communication. Conceivably, Model 3 or X don't respond badly which is how this escaped quality control? If anyone has a 3 or X or a newer S, please test and let me know.

On my Model 3, stopping charge with FC B2 SS SS RR RR will display the following errors:
Unable to charge - Check power source / Check external charging equipment.
Unable to charge - Unplug and try again.

So - i think this means i need to install a physical contactor PER CAR so i can break the power connection completely

Another bug with the Model 3 is if the car goes to sleep, if you reapply power via your contactor, the car will not wake up and resume charging. You will need to wake it up via another method. Tesla is aware of this issue, and have promised a fix Q1 this year. Stay tuned.

At the moment, I understand the only way to reliably start and stop charging is to issue commands via the Web API.
 
That makes sense. I see the SAME behaviour with my model X (Late 2018 model).

With 2 teslas and 2 TWCs, it's not quite simple to match one to the other - the ID numbers of the TWCs seem a bit random. I do have the Tesla API working nicely already, I pull of SOC, Location, etc - so I can tell if it's at home and therefore control it.

Messes it all up if a friend in a Tesla visits! What a shame we can't control it properly with the TWC.

I'm thinking my preferred solution might be using contractors, and then issuing a wake-up using the API rather than stop/start charging commands.
 
I have TWCManager working with my Australian Tesla Wall charger and Model 3. I have modified the code to supply a minimum 6A when tracking solar excess (6am - 6pm) so it doesn't continually switch on and off when production/excess is low, this works well and saves the contacts from too much switching. I've done a few other mods to suit my solar set-up. I also have an external switch to change the TWC from 3Ph to single phase if required, (gives better fine adjustments on single phase) but have to change the TWC config code if I want to track solar excess depending on the phases. Pretty agricultural code tweaks, but it is functioning.

This is getting data from a Fronius smart meter on a 19kW 3 Phase system and only charging with excess Watts over any other loads.

There is however, a random problem that occurs on single phase when I've set Min Amps per TWC to over 16, in that sometimes the car wont "break through" 16 Amps and it "loops" over a few seconds between offering and charging from 0A and up to whatever the current >16A available is, and as soon as it tries >16A returns to 0A. Sometimes it resolves itself after a few loops. If it's stuck in the loop, various "fixes" I've tried are hit and miss and you need to be watching to catch it. Doesn't seem as common after a morning wake up to charge, but go driving and come home and plug in and more often than not it happens again. Frustrating, so unless I'm watching closely, I leave it set at 16A when on single phase.

Any Gurus out there got any idea what's happening?
 
Last edited:
Just an FYI for everyone. There is a new generation 3 wall connector available. It looks like it still has an rs485 connection, but the manual mentions load sharing via WiFi connection.

Installing a Wall Connector
The product listing also mentions "Wi-Fi connectivity enables over-the-air firmware updates and remote service if necessary."

I don't really see the need to upgrade since our current wall connectors are already load-balanced and can receive firmware updates when a car is plugged in.

The manual does say "Wall Connector is equipped with Wi-Fi to communicate with local site routers, vehicles, mobile devices, other Wall Connectors, and other Tesla products." Hopefully a hardware upgrade won't be required to get the WCs to communicate with Powerwalls. That could be done via software.