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.
I've published an update on github to fix some bugs with the car API and improve the speed of waking the car, especially when the car is set to max power saving.

Green energy check and car API commands are now handled on a background thread with a 60 second timeout instead of 10 second timeout.

I changed EU TWCs from 16A to 17A due to Nietschy's findings.

I updated the installation manual to include temperature tests with my TWC charging at 40A in 90F air temperature. Basically, I think running a Pi in the TWC should be safe up to the hottest air temperatures with 40A charging.

Corrected date of manufacture in 'Get (S)TSN (serial number)' debug menu. I now believe that A means Jan 1st, B means Jan 15th, C means Jan 29th, and each letter adds 14 days to the date.

See github commit notes for more changes.
 
  • Like
Reactions: widodh
Hi CDragon,

i now had twice the problem that charging was not stopped after set the limit to 0 A.
Will check with the newest version on github.

Anyway, is there a preferred way to upgrade the source from git?
I am not really familiar with its behaviour.
Do you have any hint what commands to execute for updating the code on my raspi and maybe keep the changed configurations regarding max Ampere overall and max Ampere per device etc.?
 
  • Helpful
Reactions: pilotSteve
To integrate the latest version with any changes you might have made to your local version, run the following commands:

Code:
cd ~/TWC
cp /var/www/html/* HTML
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git stash
git pull
git stash pop

Most people won't see any errors, but if you see errors like:
Code:
CONFLICT (content): Merge conflict in TWCManager.py
CONFLICT (content): Merge conflict in HTML/index.php

it means you must manually edit the files with merge conflicts (TWCManager.py and HTML/index.php). Merge conflicts occur on any line of code that was changed in your local file and in the git repository. git doesn't know whether to use your version of the line or the git repository version. Usually you want to manually edit the line to contain parts of both changes.

Open each file mentioned in a CONFLICT line in a text editor. Search for <<<<<<< and you might find something like this:

Code:
<<<<<<< Updated upstream
    global debugLevel, carApiLastErrorTime, newGitVariable, \
=======
    global debugLevel, carApiLastErrorTime, newLocalVariable, \
>>>>>>> Stashed changes

In this case, I've added newLocalVariable to my local code (the line between ======= and >>>>>>> Stashed changes), but git also has a new variable added on the same line called newGitVariable (between <<<<<<< Updated upstream and =======). I want to keep both new variables, so I can edit the above code to look like this:

Code:
    global debugLevel, carApiLastErrorTime, newGitVariable, newLocalVariable, \

After you've eliminated all merge conflicts, run these commands:
Code:
git stash drop
cp TWC/HTML/* /var/www/html

Is there a way to proof if the stored key is working?

If you can stop and start charging using the TWCManager web ui and the car actually stops and starts charging, then the car API is working. You can also watch TWCManager's output on the pi to look for any errors. Also, when you enter the user/password in the web ui it will tell you if the user/password is wrong (this was added in the July 8th git commit).
 
Last edited:
  • Helpful
Reactions: brkaus
Corrections/clarifications:

Code:
git config --global user.email "[email protected]"
git config --global user.name "Your Name"

only needs to be run once and can be skipped next time you want to pull the latest git version. Obviously, replace the email and name with your email and name. I'm not sure if that info is shared with the github server unless you do something like try to push changes back to the repository but you can use fake info if you want. Mostly the info is displayed if you show a local history of who changed what in the git history.

In the last two commands:

Code:
git stash drop

is only needed if there were merge conflicts.

Whether or not there were conflicts, the last command you run should be:

Code:
cp HTML/* /var/www/html
 
Last edited:
Great thank you for your help. Works fine.

One other thing.
Sometimes it will not stop charging when i set the TWCManager to "Do not charge". It was working last three times but not today.
In my garage. Have no mobile connection but WLAN and the car is always reachable with the app when i use it.
Maybe some timing issues when the car does not response fast enough?
 
Sometimes it will not stop charging when i set the TWCManager to "Do not charge". It was working last three times but not today.
In my garage. Have no mobile connection but WLAN and the car is always reachable with the app when i use it.
Maybe some timing issues when the car does not response fast enough?

Please send me a log of TWCManager's output as follows:
  • Hold Ctrl, then press A
  • Release Ctrl and A
  • Type the following (including the leading colon):
Code:
:hardcopy -h log.txt
  • Private message me the log.txt file which will be located in ~/ or ~/TWC
If the time of the error has already scrolled off the top of the log, you can increase the length of the log for next time as follows:
  • Hold Ctrl, then press A
  • Release Ctrl and A
  • Type the following (including the leading colon):
Code:
:scrollback 10000
 
could not find any option to send you a PM.
i am working on a Mac so not sure if the following textfile is what you were asking for?


09:29:18: Web query: 'b'getStatus'', id 54339, time 1532935758, type 2

09:29:20: Web query: 'b'getStatus'', id 56569, time 1532935760, type 2

09:29:21: Web query: 'b'getStatus'', id 46315, time 1532935761, type 2

09:29:26: Web query: 'b'setNonScheduledAmps=10'', id 0, time 1532935766, type 2

09:29:26: Web query: 'b'setScheduledAmps=-1\nstartTime=00:00\nendTime=00:00\ndays=127'', id 0, time 1532935766, type 2

09:29:26: Web query: 'b'setResumeTrackGreenEnergyTime=-1:00'', id 0, time 1532935766, type 2

09:29:26: Web query: 'b'getStatus'', id 5526, time 1532935766, type 2

09:29:26: SHB 0256: 09 00.00/20.00A 0000 0000 M: 09 00.00/10.00A 0000 0000

09:29:28: SHB 0256: 09 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:29:28: Web query: 'b'getStatus'', id 49694, time 1532935768, type 2

09:29:40: SHB 0256: 00 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:30:00: Web query: 'b'getStatus'', id 63732, time 1532935800, type 2

09:30:31: SHB 0256: 03 00.00/06.00A 0000 0000 M: 09 00.00/10.00A 0000 0000

09:30:33: SHB 0256: 09 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:30:45: SHB 0256: 00 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:31:42: SHB 0256: 03 00.00/06.00A 0000 0000 M: 09 00.00/10.00A 0000 0000

09:31:44: SHB 0256: 03 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:31:46: SHB 0256: 00 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:32:26: SHB 0256: 08 00.00/10.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:32:31: Web query: 'b'setNonScheduledAmps=6.0'', id 0, time 1532935951, type 2

09:32:31: Web query: 'b'getStatus'', id 43504, time 1532935951, type 2

09:32:32: SHB 0256: 08 00.00/10.00A 0000 0000 M: 09 00.00/06.00A 0000 0000

09:32:34: SHB 0256: 09 00.00/06.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:32:34: SHB 0256: 09 01.65/06.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:32:38: SHB 0256: 09 05.10/06.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:32:46: SHB 0256: 01 05.38/06.00A 0000 0000 M: 00 00.00/00.00A 0000 0000

09:35:50: Web query: 'b'setNonScheduledAmps=0.0'', id 0, time 1532936150, type 2

09:35:50: Web query: 'b'getStatus'', id 10679, time 1532936150, type 2

09:35:51: SHB 0256: 01 05.42/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000

09:35:53: SHB 0256: 09 05.42/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000

09:36:11: Web query: 'b'getStatus'', id 57359, time 1532936171, type 2

09:36:13: Web query: 'b'getStatus'', id 6652, time 1532936173, type 2

09:40:50: Web query: 'b'getStatus'', id 50711, time 1532936450, type 2
 
I just published an update on github that fixes some things:
  • Only check for car API vehicles to be at home if more than one vehicle is registered in the car API.
  • New onlyChargeMultiCarsAtHome config parameter lets you disable checking if vehicles are at home even when there are multiple vehicles.
  • Consider a car to be at home when within 2 miles of home location rather than 2000 feet.
  • Changes above were added when I noticed my car wasn't charging because GPS had frozen thinking car was located elsewhere. This bug has been present the last couple months and has been reported by a number of people to affect older car models.
  • Fixed a case where web interface did not report a TWC being offered power but not taking it because it was unplugged or finished charging.
  • Divide available amps over number of TWCs currently charging rather than number of TWCs on the network. Ie two TWCs sharing 80A will no longer limit both cars to 40A unless both cars are drawing power at the same time.
  • Fixed an error escaping C0 and DB characters in sent messages that was created in the port from Perl to Python.
Does something like this exist with dynamic load balancing? Like a Maxem does?
I would like to use a TWC instead of my current set up (Keba P20 + SDM630 Modbus meter + Rpi for load balancing).
I need dynamic load balancing or else I burn my house fuses ;) (only 3x25A incoming here).

TWCManager can charge based on the amount of 'green energy' available at any particular time. You could replace the green energy concept with a max power value you want your house to use minus how much power the rest of your house is using. You just need to modify TWCManager's Python code to query total house power which it sounds like you already have a way of doing.
 
Last edited:
  • Helpful
  • Love
Reactions: spottyq and brkaus
I just published an update on github that fixes some things:
  • Only check for car API vehicles to be at home if more than one vehicle is registered in the car API.
  • New onlyChargeMultiCarsAtHome config parameter lets you disable checking if vehicles are at home even when there are multiple vehicles.
  • Consider a car to be at home when within 2 miles of home location rather than 2000 feet.
  • Changes above were added when I noticed my car wasn't charging because GPS had frozen thinking car was located elsewhere. This bug has been present the last couple months and has been reported by a number of people to affect older car models.
  • Fixed a case where web interface did not report a TWC being offered power but not taking it because it was unplugged or finished charging.
  • Divide available amps over number of TWCs currently charging rather than number of TWCs on the network. Ie two TWCs sharing 80A will no longer limit both cars to 40A unless both cars are drawing power at the same time.
  • Fixed an error escaping C0 and DB characters in sent messages that was created in the port from Perl to Python.


TWCManager can charge based on the amount of 'green energy' available at any particular time. You could replace the green energy concept with a max power value you want your house to use minus how much power the rest of your house is using. You just need to modify TWCManager's Python code to query total house power which it sounds like you already have a way of doing.
I am not a user of this at this time, but it seems determining whether the car is home seems to be a challenge. Have you considered checking whether the car is on local WiFi? You could do it by MAC address if Tesla supports RARP packets, alternatively reserve a constant DHCP IP per car and check using IP. Just a thought, keep up the good work.
 
Last edited:
Hey cdragon

I updated to the latest version and i think you switch the output on the TWC line.

Before when the plug was not connected there was the message „no power available“ or something similar and when the plug was in the car but not charging the message „Finished charging, unplugged, or waking up. (6A available)“

Now it is the other way round.

Was this changed output planned like this?
 
I am not a user of this at this time, but it seems determining whether the car is home seems to be a challenge. Have you considered checking whether the car is on local WiFi? You could do it by MAC address if Tesla supports RARP packets, alternatively reserve a constant DHCP IP per car and check using IP. Just a thought, keep up the good work.

Definitely a good idea.

Unfortunately I don't have time to work on that (anyone want to help?). I've got hold of firmware from a TWC with serial number starting with A18F which means it was made between Mar 12th and Mar 25th 2018. Firmware version has increased from 4.4.D to 4.5.3 and decompile shows it supports 11 new commands! I've already found commands that seem to be intended to stop and start charge, but weirdly it sends a Tesla into red-ring error mode so it won't charge again unless you re-plug it. However, it works to stop and start a fake car charging, and it works with a Tesla if you set the TWC's DIP switch to legacy mode (meaning CAN communication with car is disabled). I've got a lot more exploring and testing to do so I'll be focused on that for the time being.

Note that someone with a TWC serial starting with A18D (made in Feb 2018) said their firmware was still 4.4.D so the firmware update likely began with March 2018 TWCs. It doesn't look like older TWCs are getting the new firmware through the car update process, at least not yet. I've flashed the new firmware to my main test TWC dated Apr 23rd to May 6th 2017. I hope the fact stop/start charge doesn't work with Tesla in CAN mode doesn't mean there was some hardware update in March 2018 to make it work properly.

Before when the plug was not connected there was the message „no power available“ or something similar and when the plug was in the car but not charging the message „Finished charging, unplugged, or waking up. (6A available)“ . Now it is the other way round.
Was this changed output planned like this?

That was an intended fix. Previously, if a car was plugged in but not using any power, it would sometimes say 'No power available' even if the TWC was offering the car 6A or more. Now it says 'Finished charging, unplugged, or waking up. (6A available)'. If that fix broke something else, let me know. It should only say 'No power available' if the TWC is set to refuse charging a car.

Please see the git commit notes to see what changes were intentional.
 
Last edited:
Nothing broken here. I just used the different text messages to check if the TWC is plugged in a car for my home automation screen. It will show a car when plugged in or just the connector when no car is connected with the TWC
 

Attachments

  • DF4D54BA-EC1B-41C9-BE10-8C304BA47403.jpeg
    DF4D54BA-EC1B-41C9-BE10-8C304BA47403.jpeg
    76.7 KB · Views: 121
Nothing broken here. I just used the different text messages to check if the TWC is plugged in a car for my home automation screen. It will show a car when plugged in or just the connector when no car is connected with the TWC

As far as I've been able to tell, there is nothing in the RS485 protocol to indicate a difference between car finished charging and car unplugged. That's why the message reads "Finished charging, unplugged, or waking up." rather than distinguishing between those three states. The only thing TWCManager can reliably report is when a car is charging.
 
  • Like
Reactions: marlan99
I'm looking for a way to interrupt charging when I receive a (temperature dependent) 12V signal. (See here for the complete story.) Unfortunately, I have the older HPWC model, without communication capabilities. I tested the command above (setting the frequency to 315000 kHz since I'm in North America) and it does open the port when it's closed, but it does not interrupt the charge.

Please move this question to this thread.