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 wonder how the TWC will react to something else issuing CAN commands and whether it would through it's internal state out. It'd be a lot of work to have to act as both devices and selectively pass certain messages back and forward (i.e. when you want to stop charging, send the car a 'zero current' message but at the same time send the TWC a 'car wants to stop charging' message). Anyway my first step is to get the RS485 piece working and control start and stop via the API and then look into CAN later if there's any motivation left.

I've been thinking of similar things about if I need the SWCAN comms.

Initially there has been a 'bug?' in the STOP_CHARGING (0xFCB2) command and as some people here had reported the TWC was able to suspend and restart charging, I was interested in how it did it - hence I started eaves dropping on the SWCAN comms.

The car was also not waking up via the charge port after it went to sleep (i.e. if you reapplied power to the contactor using START_CHARGING 0xFCB1). This has recently been fixed in 2020.24.6.x, but I need to test how it reacts with the TWC's START CHARGING command (Maybe this weekend).

I'm hoping this is all resolved and we only need RS-485 to turn on and off the charging.

My other motivation is I've signed up with AmberElectric as my electricity retailer. They pass through the wholesale price of electricity, so I can parse a JSON file and make a real time decision on when to charge my car based on the current 30 minute price of power. I can set a threshold and say I only want to charge when the price is under this threshold.

But it's not quite that easy. If my car is flat and the price is always above the threshold, then I'm stuck. Sometimes the price also goes negative and I get paid to charge the car. Therefore I want to keep a reserve in the battery for these opportunities.

I've worked out I can get the SoC via the SWCAN port, so I can have different decision making based on the state of charge. (I know I can do this via API, but I find it more logical to do it via the charging port. I can leave the car set to charge to 90% when I'm out on public chargers and have my TWC terminate the charge based on the reported SoC)

Hence, I'm wondering if I want to tap into the Pilot/SWCAN line for reading the SoC. I would never drive the line.

There is also a complication with the SWCAN line sharing the Pilot line. Under J1772/IEC61851-1 the car will switch in different resistor values to signal 'Vehicle Detected', 'Ready/Charging' etc. If you have the transceiver connected to the Pilot when the charge port is first plugged in, it will interfere. A Tesla will switch in (with a relay) the SWCAN Transceiver after a certain sequence:
New Tesla charger board - Page 3 - openinverter forum
 
Last edited:
@WinterDragoness have you got a firmware dump from a TWC v4.5.3 that you can share, save me going through all the same work you already did to get it, but also allow others to skim over it?

Initially there has been a 'bug?' in the STOP_CHARGING (0xFCB2) command and as some people here had reported the TWC was able to suspend and restart charging, I was interested in how it did it - hence I started eaves dropping on the SWCAN comms.

The car was also not waking up via the charge port after it went to sleep (i.e. if you reapplied power to the contactor using START_CHARGING 0xFCB1). This has recently been fixed in 2020.24.6.x, but I need to test how it reacts with the TWC's START CHARGING command (Maybe this weekend).

I'm hoping this is all resolved and we only need RS-485 to turn on and off the charging.

@Craig 128 I recently updated to 2020.28.6 and tried the FCB2 and FCB1 commands to stop/start charging. The car did stop charging when it was sent, but after a couple of times stop/starting, the car shows the red T logo of death and required re-plugging.

Will have to try it again and properly log the data.

I also recently got a second TWC so that I could set them up in loadsharing configuration, interestingly, when the primary had the rotary dial set to position 1 (6A), the primary and secondary refused to charge any car. The car reported that there was not enough available current to charge on either of the TWCs, and they both showed a red indicator light. The heartbeat changed to [FB E0 MM MM SS SS 2 1 0 0 0 0 0 0 0 8D] and was only able to break out of this condition by powering down and adjusting the dial. I haven't tried any other settings on the dial except for 6A and 32A though. Will test it on other settings.

One thing I want to try now is setting the HB to [FB E0 MM MM SS SS 2 1 0 0 0 0 0 0 0 8D] on a TWC that is connected to the manager software to see if it will make the TWC stop charging. But when the HB is set to 00 00 again, if it recovers without requiring the car to be re-plugged or the TWC being reset.

I too would love to be able to have this just be fully controlled external to the Tesla API
 
  • Like
Reactions: Craig 128
Thanks shreddyb for testing the FCB2 and FCB1 commands. Disappointing to hear no change.

The heartbeat changed to [FB E0 MM MM SS SS 2 1 0 0 0 0 0 0 0 8D] and was only able to break out of this condition by powering down and adjusting the dial. I haven't tried any other settings on the dial except for 6A and 32A though. Will test it on other settings.

According to the source from WinterDragoness:

Master Heartbeat:
# Byte 1 is a command:
# 00 Make no changes
# 02 Error
# Byte 2 appears to act as a bitmap where each set bit causes the
# slave TWC to enter a different error state. First 8 digits below
# show which bits are set and these values were tested on a Protocol
# 2 TWC:
# 0000 0001 = Middle LED blinks 3 times red, top LED solid green.
# Manual says this code means 'Incorrect rotary switch
# setting.'
# 0000 0010 = Middle LED blinks 5 times red, top LED solid green.
# Manual says this code means 'More than three Wall
# Connectors are set to Slave.'
# 0000 0100 = Middle LED blinks 6 times red, top LED solid green.
# Manual says this code means 'The networked Wall
# Connectors have different maximum current
# capabilities.'
# 0000 1000 = No effect
# 0001 0000 = No effect
# 0010 0000 = No effect
# 0100 0000 = No effect
# 1000 0000 = No effect

So what you are seeing makes sense.
 
Last edited:
I searched the thread, but only found one mention of the sense energy monitor.

I've got TWCManager running and monitoring my SolarEdge inverters. Ideally I'd like to charge off of excess solar power only.

sense.com allows me to see current usage from the home as well as solar produced. I'd like to take the output of current solar generation minus current energy usage and pass that value to the greenEnergyData.

I'm REALLY hoping someone has already done this and can let me know what is needed in my TWCManager.py.

I barely know enough to be dangerous, so it will probably take me days to figure this out on my own. I'd really like to avoid that if someone has done it already.

I did find this post with some details around the sense API, so you can pull the data.
API for current generation and usage
 
I searched the thread, but only found one mention of the sense energy monitor.

I've got TWCManager running and monitoring my SolarEdge inverters. Ideally I'd like to charge off of excess solar power only.

sense.com allows me to see current usage from the home as well as solar produced. I'd like to take the output of current solar generation minus current energy usage and pass that value to the greenEnergyData.

I'm REALLY hoping someone has already done this and can let me know what is needed in my TWCManager.py.

I barely know enough to be dangerous, so it will probably take me days to figure this out on my own. I'd really like to avoid that if someone has done it already.

I did find this post with some details around the sense API, so you can pull the data.
API for current generation and usage
Can you login on there portal too see the state?
 
Can someone help me out with a problem.

TWCmanager is running, late in the day (sun going down) it says I have like 8amps available to charge and I have set the min charge at 12amps.

I was under the impression that when solar stopped producing atleast 12 amps power it would cut off the charger to keep me from pulling from the grid. Instead what is happening is it continues to charge at 12amps. until (I think) solar is at zero production then it cuts off the 12amps.

Did i mess up on a setting or is this normal. How do I set my cutoff (stop charging and wait until next day or I override) at 12amps.

Thanks,
 
Can someone help me out with a problem.

TWCmanager is running, late in the day (sun going down) it says I have like 8amps available to charge and I have set the min charge at 12amps.

I was under the impression that when solar stopped producing atleast 12 amps power it would cut off the charger to keep me from pulling from the grid. Instead what is happening is it continues to charge at 12amps. until (I think) solar is at zero production then it cuts off the 12amps.

Did i mess up on a setting or is this normal. How do I set my cutoff (stop charging and wait until next day or I override) at 12amps.

Thanks,
Sometimes mine gets "stuck" on an amp setting. Rebooting or cycling power on the Pi resolves this for me. (My Pi is on a wifi power outlet with a timer to cycle once a day at 5am, and so I can also remotely cycle the power if necessary)
 
the "6 amp charge" bug i think is in the HTML where the car is "finished charging, unplugged, or waking up" and allows 6 amps, even though the GreenEnergy says 0 is available. Mine pulls every minute, so it turns off within a minute. I'm not to worried, but have confirmed there is a bug. I think those functions were all put together for some reason. May need a deeper dive.

So the 6amp charge plug for me starts for a min, then stops for a min, then starts for a min......... And this is a never ending cycle.

RIght now at dark I plug in the car and it starts charging at 6amps for a min. Then shuts off for a min then starts again.
 
Had it running for a day or so.....Now I have a blinking red (4 times) in the middle and top green on out at the charger.

Looking at the logs i see alot of.

15:53:44: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:53:54: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:53:54: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:53:55: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:53:56: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:05: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:15: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:25: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:25: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:26: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:27: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:37: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:47: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:57: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:57: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:58: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:54:59: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:55:09: 80.00 amp slave TWC 7340 is ready to link. Sign: AC
15:55:19: 80.00 amp slave TWC 7340 is ready to link. Sign: AC

rebooted everything tried a few things still don't any more then above and says no power avaible. I thought my RS485 took a crap (it wasn't a cheap one) but it seems to be sending and receiving messages. How can i find out if that is the problem?
 
I know I seem to be talking to myself here...... But I'm also getting this problem late in the day. it want's to keep charging even though there is clearly not enough solar being produced. You can see it stopping and starting the charging even though I have it set to 10amp min and it sees that solar is well below that right now. I'm not sure why it even starts charging in the first place.


15:38:41: Solar generating 1805W so limit car charging to:
7.40A + -4.14A = 3.26A. Charge when above 10A (minAmpsPerTWC).
15:39:04: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:39:10: Car API start charge result: success
15:39:20: SHB 0151: 09 01.03/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:39:22: SHB 0151: 09 06.37/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:39:45: SHB 7340: 00 00.00/00.00A 0000 0000 M: 09 00.00/10.00A 0000 0000
15:39:48: Solar generating 1848W so limit car charging to:
7.58A + -3.95A = 3.63A. Charge when above 10A (minAmpsPerTWC).
15:40:04: Car API stop charge result: success
15:40:05: SHB 0151: 09 00.00/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:40:44: Solar generating 1817W so limit car charging to:
7.51A + -26.28A = -18.77A. Charge when above 10A (minAmpsPerTWC).
15:41:05: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:41:11: Car API start charge result: success
15:41:25: SHB 0151: 09 06.19/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:41:52: Solar generating 1774W so limit car charging to:
7.35A + -26.94A = -19.59A. Charge when above 10A (minAmpsPerTWC).
15:41:59: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:42:06: Vehicle 61631814974150387 is done charging or already trying to charge. Stop asking to start charging.
15:42:06: Car API start charge result: success
15:42:49: Solar generating 1753W so limit car charging to:
7.25A + -26.71A = -19.46A. Charge when above 10A (minAmpsPerTWC).
15:43:08: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:43:14: Vehicle 61631814974150387 is done charging or already trying to charge. Stop asking to start charging.
15:43:14: Car API start charge result: success
15:43:56: Solar generating 1728W so limit car charging to:
7.16A + -26.37A = -19.21A. Charge when above 10A (minAmpsPerTWC).
15:44:03: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:44:10: Vehicle 61631814974150387 is done charging or already trying to charge. Stop asking to start charging.
15:44:10: Car API start charge result: success
15:44:51: Solar generating 1700W so limit car charging to:
6.97A + -4.38A = 2.60A. Charge when above 10A (minAmpsPerTWC).
15:45:17: Car API stop charge result: success
15:45:18: SHB 0151: 09 00.00/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:45:54: Solar generating 1648W so limit car charging to:
6.74A + -3.61A = 3.13A. Charge when above 10A (minAmpsPerTWC).
15:46:04: Vehicle 53323323908499712 is done charging or already trying to charge. Stop asking to start charging.
15:46:11: Car API start charge result: success
15:46:23: SHB 0151: 09 01.03/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
15:46:25: SHB 0151: 09 06.37/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
 
@Nietschy
I am trying to scrape the data from an API and I was successfully able to grab the total power generated. But I have issues when I tried to edit the check_green_energy function.

The variable 'pv' holds the value of total power being generated(Its been checked by executing separately). However, when I tried to put the same code in function check_green energy of TWCManager.py, the web interface still says Power Available for all TWCs: NONE.

Am I missing out anything? Could you please help me with this?
 

Attachments

  • code_for_checkgreen.txt
    4.1 KB · Views: 74
Hi Everyone,
I am python noob.
I was trying to edit the check_green_energy() function to track the solar power available. I was successful in scraping the data from the API. I fed the value to the 'solarW' as well. Unfortunately, the TWCManager webpage is not reading the power. It says, The Power Available at all TWCs: None.
I have 3 phase charger installed and I hope all the parameters in the TWCManager.py are set correctly(Please see the attached code).

Also, I tried inputting a random number of 12A to the variable maxAmpsToDivideAmongSlaves in check_green_energy() function just to verify, Even then it says NONE.
Is there anything else, that I am missing out? Or should change anything in index.php?

Thank you in advance.
Addy


Terminal Output:

Tx@00:18:50: C0 FB E0 77 77 61 50 09 00 00 00 00 00 00 00 00 88 C0
Tx@00:18:51: C0 FB E0 77 77 61 50 09 00 00 00 00 00 00 00 00 88 C0
Rx@00:18:51: (FC) FD E0 61 50 77 77 09 02 58 00 00 00 00 00 00 E2
desiredAmpsOffered reduced from 0 to 0 with 1 cars charging.
desiredAmpsOffered reduced to 0 from 0 because maxAmpsToDivideAmongSlaves 0 / numCarsCharging 1 < minAmpsToOffer 6
set_last_amps_offered(TWCID=61 50, desiredAmpsOffered=0)
00:18:51: SHB 6150: 09 00.00/06.00A 0000 0000 M: 09 00.00/00.00A 0000 0000
 

Attachments

  • TWCManager.txt
    180.2 KB · Views: 83
What is the status on your ESP32 board? This is my next step (I've ported most of the TWC code to C to eventually use on an ESP32 target)
I've finally had some time to work on my ESP32 project and it's now "working" (i put that in quotes because there is heaps of work left to do). I haven't merged the repositories for the hardware and software yet, once i figure out how to do that i will. You can find my code at

jnicolson/twc-controller

A few things I should mention - i'm not a programmer! I'm a lowly Application Support person with a fancy title. There might be some code that makes people cringe - i welcome feedback! The configuration code needs a lot of work. Right now it reads a json file from SPIFFS called config.json but there's no way to configure it - have to generate it manually and upload it to SPIFFS. The intention is to have a captive portal for initial configuration and then a web interface for post initial configuration changes. The web side of things also needs a lot of work, it's really just the bones right now.

There is an issue when the car is first plugged in that the current isn't being offered so that car thinks the TWC is unpowered. Basically i have to plug it in then quickly send an MQTT message with a starting current, provided i do this in time it will charge correct.

Input is all via MQTT right now. The MQTT endpoints are in the code but i need to document them, but basically a current in full amps is written to twc/availableCurrent. Unfortunately I don't currently have the actual charging current returning to MQTT, thats next on the list.

I'll try to update the readme with some more information later today.

Also, picture attached of it installed - ignore the wires going down out of frame, they are serial (TX, RX and Ground) for debugging.
 

Attachments

  • PXL_20201218_231900879.jpg
    PXL_20201218_231900879.jpg
    569.7 KB · Views: 280
  • Like
Reactions: Craig 128
Hi All,

Just got this working for Scheduled Power timing, as we now also have a Polestar which has no scheduling (yet). amazing instructions and enjoyed this little Pi build projects! However, couple of issues:

1. I can never get the car not to charge. Ideally, I want to to charge at full 32A at the scheduled power time, but other used of that, it is charging at 6amp.
I have set nonScheduledAmpsMax=0, what else am I missing?

2. I am looking to start charge schedule at 0030-0430, only whole hours. Anyone done a fork to introduce half hours? if not, may have to have a go myself :)

Thanks
 
Hi All,

Just wanted to share something that I've been working on for a while now.

It's a modularized fork of cdragon's excellent TWCManager, with the ability to add modules for various different systems rather than having to fork the code each time for custom implementations

Some of the benefits of the fork:
  • A policy-based approach to charging (Green/Scheduled/Non-Scheduled) allowing charging behaviour to be overridden in config, and to be able to read values from modules to make charging decisions.
  • Consumption and charger load offset, so you only charge using the delta between generation and consumption during track green energy, excluding the charger load from the equation (if it is metered alongside household consumption).
  • A lot of development around the ability to work with stored energy systems such as Powerwalls, implementing things like latching and flex current to avoid rapid transitions on/off charge for these systems.
  • A new web interface which, while it is a work in progress, is more user friendly (being AJAX based). In the short future there will be support for debug functionality in the new web interface and the old IPC interface will go.
  • The ability to read per-phase voltage and VINs from the TWC, so you can identify which vehicles are/were charging (if your firmware allows for it).
  • Integration with MQTT and HomeAssistant (in both directions, input and output)
  • A very early RESTful API interface that will expand in usefulness
Importantly, it is nearing a stable platform now after a lot of work to re-engineer it into a more modular form which should help with creative uses. Feel free to give it a try if you're interested.

ngardiner/TWCManager

Thanks for this, installed your developer branch of v1.2.1, this has given ability to schedule at half hours, and stop charge using the TWC to legacy. Amazing work, thanks so much!

Any chance there is a fix for the new Tesla auth procedure as of january 29?
My token will expire in about a month and then I will not be able to use this project for charge stop/start.
Document the new auth system · Issue #260 · timdorr/tesla-api

This might be the reason TMPDB abow can't start/stop.

//L

see above, tried a different fork and it can stop charging via another method.
 
My API key link looks like this:
http://192.168.1.2:1080/api/2/power/now

The output of the file lokks like this:
{"serial":"smartpi12345","name":"House","lat":52.3667,"lng":9.7167,"time":"2020-06-18 17:18:25","softwareversion":"","ipaddress":"192.168.1.2","datasets":[{"time":"2020-06-18 17:18:24","phases":[{"phase":2,"name":"phase 2","values":[{"type":"power","unity":"W","info":"","data":-425.00882}]}]}]}
Hello magic7music,
seems your API is "Volkszähler". So there is a simple read format available to get the Power from a channel:
Returns: "4132.7 W"

You have to replace the "11111111-2222-3333-4444-555555555555" by your own channel ID getting from here:
i.png


If you anybody find a solution to TWCmanager can use this method above: Please tell me! (linux novice)