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

The important missing control for Tesla Powerwalls

This site may earn commission on affiliate links.
I’ve had Powerwalls for four years now. As my thread title suggests, from experience, Powerwalls lack one very important, if not essential control; the ability to fill it to a given capacity. I’m pretty sure I’m not alone in the view given that many owners use the popular cheap but short off-peak tariffs which we have in the U.K.
I‘m fortunate in as much as from late spring to late autumn , I have sufficient solar capacity to keep mine filled up. I know that in the depths of winter I will need to fill up most nights from the grid. In the these two scenarios they perform pretty much on the money. Others probably struggle throughout the year.

However, late autumn and early spring have always been a nightmare. I had hoped that major changes to the Tesla app which included adding tariffs and reducing the operating modes to just self-powered and time based control would resolve the problems. But it didn’t. I’ve just switched to time based control for the winter and I’m stuck in the same annoying rut that happens every year!

Recently we in the U.K. have had the usual dull wet days and bright sunny days. Apart from being unusually warm. Autumn has been what it always is and the daylight hours get shorter.

In Time based control, Powerwalls depend upon their AI to work out how much of their power came from solar, how much they discharged and how much they need from the grid. That works reasonably in stable weather conditions. It fails abysmally when a few sunny days are followed by a dull day or two and vice versa. Furthermore, the AI has no idea that even if there is some sun coming, I want my Powerwalls topped up from the grid because I’ll be charging two EV’s from solar tomorrow.

Here’s the annoying part; on two separate occasions last week there was little solar, the first night PW’s were at about 50% at bedtime and one car was empty. I set my reserve to 47% knowing full well that I would have to wake myself up before 2.30am to check what was happening. I did and sure enough, the car had charged but the Powerwalls had only topped up to 62%. I did what I always do and upped the reserve to 75% as I knew that the following day would roughly produce enough to finish the job, which it did. Two days later, same thing. Set a higher reserve at bedtime, get up in the middle of the night to up the reserve again to ensure that they are full enough for the day.

I won’t set a final reserve at bedtime because then I’ll be buying peak rate power and I shouldn’t need to. No matter how good the AI is, it will never be better than me because it can never have my overview of my needs. The answer is simple; an optional slider control to set a charge level exactly the same as my Model 3. Why on on earth was that ever omitted? Perhaps it’s a USA thing. It’s obvious to me and I would get a good night’s sleep!
Does anyone else want a charge control added?
 
Last edited:
I really REALLY need to get around to building an API program for my PowerWalls so I can get charging / discharge and spill-over to EVs working before Summer gets here ... I've exported a couple of kWh today by accident because SolCast prediction was that I wasn't going to get any useful solar - so I charged to 100% last night

SolCast04.gif


Top is the 7AM today latest estimate (for today) ... and below is the 6PM actual ... exported 4.5kWh before I looked out the window and saw the unexpected sunshine and manually got the car charging and added half-a-dozen more kWh to the car

I'm competent to do the programming, just don't have the time for the learning-curve and umpteen "that didn't work" etc.

Brainwave ... I'll get ChatGPT to write it for me ... and it did!

Me: Can you write me a program to access the tesla powerwall api?

ChatGPT:

Yes, I can provide you with an example Python program that can access the Tesla Powerwall API. However, please note that accessing the API requires authentication and you will need to obtain an access token before you can use it.

Here is a sample program that retrieves the current state of charge and energy meter data from the Tesla Powerwall API using the requests library in Python:

Example removed - you can get ChatGPT to write your own!

Note that you will need to replace YOUR_ACCESS_TOKEN_HERE with your actual access token obtained from Tesla. Also, depending on your specific use case, you may need to modify the code to retrieve different data or perform different actions using the API.

That is verbatim ... Scary beyond belief! and I can't see anything wrong with the code. So I went back and gave it some more specific requirements ... happy days :)

This was not an original idea ... its based on a YouTube I saw yesterday by Tom Scott - <SpolierAlerr> its even more scary

 
  • Like
Reactions: Vostok
Holy krap… You are effin kidding me?!

'Fraid not ... Tom's video explains the point at which it completely ran out of road ...

... I've been augmenting what it originally generated (an example without me having been specific) with some more specific things.

"Write a program using the Tesla Powerwall API to change the state-of charge to 50%"​

Yeah, I know ... it was late!

Unfortunately, changing the state of charge on a Tesla Powerwall is not something that can be done directly through the API. The Powerwall API is read-only and only provides information about the current state of the Powerwall and its associated components.

I read that as everything was read-only ... bit of a heart stopping moment, even though I was sure that wasn't the case ... so I asked:

"What settings can I change with the tesla powerwall api?"​

The Tesla Powerwall API provides access to a range of information and settings related to the Powerwall and its associated components. Some of the settings that can be accessed and changed through the API include:
  1. Powerwall Status: Retrieve current system status including power flow, battery charge level, and grid connection status.
  2. Energy Meter Data: Retrieve real-time and historical data on energy usage, production, and net energy flow.
  3. Operational Modes: Change the operational mode of the Powerwall, such as Backup, Time-Based Control, or Self-Powered mode.
  4. Battery Settings: Retrieve or change battery settings, such as reserve percentage, storm watch mode, or maximum power output.
  5. Site Settings: Retrieve or change site-level settings, such as grid code compliance, grid services participation, or Time of Use rates.
  6. Solar Settings: Retrieve or change settings related to solar energy production and storage, such as export limits or solar offset limits.
  7. Notifications: Configure and receive notifications for various system events, such as power outages, low battery warnings, or grid connection status changes.
Please note that changing some of these settings may require special permissions or hardware configurations, and may affect the performance and safety of the Powerwall system. It is important to exercise caution and consult the official documentation and support resources provided by Tesla when making any changes to the Powerwall settings through the API.

Well that was a useful read 'coz I didn't know of some of those ...

So ... that would be the "backup reserve" I should be changing, not the "state-of-charge" Doh!

If I'd written an actual program to attempt that I have no idea how much time I would have wasted trying to figure out what "Error 768421" was ...

So:

"Please write me a program using the tesla powerwall api to change backup reserve to 50%"​

Note that I had started to feel uncomfortable getting all this good stuff from my NBF so started adding "Please" to requests :)

And it duly wrote a program to do that - which of course wasn't specifically what I needed, but had all the right coding elements for checking Reserve, spelt correctly (I'm not good at that!) and so on. A get-you-started leg-up like I have never known before.

"Dear NBF ChatGPT - Can you do my day job please?"​

I'll let you know how I get on with that ... once I've got my place in the Caribbean and settled in :)
 
As a separate point:

I am also wanting to get the Cars to charge (via my "personally crafted" Ah!Hem! code). So I need the API for the Car too. No doubt ChatGPT could give me a leg up to, but I stumbled over the fact that TeslaFi appears to now offer that. I've not looked closely, so may be mistaken, but it appears that I can just use an HTTP REST API to TeslaFi (for a limited set of API functions). I figure that would be a lot easier to code than building the complete shebang that will talk direct to Tesla's Servers.

The TeslaFi API enables a json output feed to access the last data points TeslaFi received from the Tesla API and control your vehicle.
To enable API access click on Generate below to create an API Token.

COMMANDS:

Enable and disable specific commands allowed to be called using your TeslaFi API Token below:

Adding &wake=X after a command will send a wake command and then pause for X seconds before sending the command if the vehicle is sleeping. Usually 10-15 seconds is enough time for the vehicle to wake up. Maximum time is 60 seconds.

At a glance it looks to be all the things covered in the TeslaFi scheduler - Start/Stop Charge/Climate/Seat/Steering Heater, Charge Limit/AMPs/Sentry Mode, Lock/Unlock doors, Start Sleep (so can PUSH that as soon as actions are completed) and a couple of others

command=wake
command=auto_conditioning_start - turn Climate on
command=seat_heater&heater=0&level=3 - (0=Driver seat, 3=High)

There's a log of last 1,000 commands - which I am guessing would be handy for debugging, and could save me having to build that too
 
Hehehe ...

"Can you write a program to access the TeslaFi API?"​

Yes, I can help you write a program to access the TeslaFi API. The TeslaFi API provides a way to interact with your Tesla vehicle data, including charging and driving history, battery level, and more. To get started, you will need to create a TeslaFi account and obtain an API key, which can be found in your account settings.

Here is a sample Python program ...

etc. etc. etc.
 
And it duly wrote a program to do that - which of course wasn't specifically what I needed, but had all the right coding elements for checking Reserve, spelt correctly (I'm not good at that!) and so on. A get-you-started leg-up like I have never known before.

That’s all a bit… unsettling.

Does ChatGPT know the difference between the Powerwall API, which is an API that communicates directly with the Powerwall on the local network, and the Tesla API, which offers API commands to products attached to your Tesla account, which of course also includes Powerwall. Those 2 APIs are different, and the feature set is different. There are things you can do to your Powerwall on the Powerwall API that you cannot do via the Tesla API.

Also there are nuances some people have discovered with the Tesla API, like that some commands require a very specific User-Agent to be passed for the command to work. One example is the command to retrieve historical charging data for your vehicles. Pass the wrong User-Agent, and you get a 404 error.
 
  • Like
Reactions: WannabeOwner
Does ChatGPT know the difference between ...

I need to charge for this service ...

"Do you know the difference between the PowerWall API and the Tesla API?"​

Yes, the Powerwall API and the Tesla API are two different APIs that are provided by Tesla, and they serve different purposes.

The Powerwall API is used to interact with Tesla's home energy products, specifically the Powerwall and Powerpack. It provides access to real-time and historical system data, including energy production and consumption, battery charge status, and other system settings. The Powerwall API allows developers and customers to build custom software applications or integrations that can automate and control various aspects of their Powerwall system.

On the other hand, the Tesla API is used to interact with Tesla's electric vehicles, such as the Model S, Model X, Model 3, and Model Y. It provides access to various data points related to the vehicle, including battery level, charging status, location, and vehicle controls such as door locks and climate control. The Tesla API allows developers and customers to build custom software applications or integrations that can monitor or control various aspects of the vehicle remotely.

While both APIs are provided by Tesla, they serve different purposes and provide access to different sets of data. It is important to carefully review the official documentation and support resources for each API to ensure that you are using the correct API for your needs, and to ensure that you are using the API in a safe and secure manner.

which of course also includes Powerwall.

Well ...

"Can you access a PowerWall through the Tesla API?"​

No, the Powerwall cannot be accessed through the Tesla API. The Tesla API is specifically designed to interact with Tesla's electric vehicles, such as the Model S, Model X, Model 3, and Model Y. The Powerwall, on the other hand, is a home energy product that is designed to store and manage energy in a household or commercial setting.

To interact with the Powerwall, you would need to use the Powerwall API, which is a separate API provided by Tesla specifically for the Powerwall and Powerpack products. The Powerwall API provides access to real-time and historical system data, including energy production and consumption, battery charge status, and other system settings. You can use the Powerwall API to build custom software applications or integrations that can automate and control various aspects of your Powerwall system.

It is important to note that the Tesla API and the Powerwall API are two separate APIs that serve different purposes and provide access to different sets of data. It is recommended to carefully review the official documentation and support resources for each API to ensure that you are using the correct API for your needs, and to ensure that you are using the API in a safe and secure manner.

I'm figuring its far more likely that you are right on that one :)

there are nuances some people have discovered with the Tesla API

That type of knowledge-needed snag is why I would be much happier piggybacking using the TeslaFi API rather than Tesla API direct ... I figure TEslaFi will have already figured out those sorts of things (and new ones that arise in the future)

However, I tried it today and got 500-type errors, didn't have time to try further
 
Ask ChatGPT to write up the instructions for you

I'm on a blooming roll here ...

"can you write some instructions for Syncena's charge-tesla on github?"​

Sure, I can provide some instructions for using Syncena's charge-tesla script on GitHub.

charge-tesla is a Python script that can be used to automatically charge your Tesla vehicle during off-peak hours, when electricity rates are typically lower. Here are the steps to use this script:

  1. Download the charge-tesla script from the GitHub repository: GitHub - Syncena/charge-tesla: Simple program to control Powerwall standby reserve, and stop Tesla cars charge at a set time
  2. Install the required dependencies. The script requires the teslajson and pytz libraries to be installed. You can use pip to install these libraries by running the following command in your terminal:
Code:
pip install teslajson pytz

  1. Obtain your Tesla API access token. You can get your access token by logging in to your Tesla account on the Tesla website, going to the "Account" section, and generating a new access token.
  2. Open the charge-tesla.py file in a text editor and update the configuration variables at the top of the file. Set the API_URL variable to https://owner-api.teslamotors.com and the API_VERSION variable to 1. Set the TESLA_EMAIL and TESLA_PASSWORD variables to your Tesla account email and password, respectively. Set the TESLA_VEHICLE_ID variable to the ID of the vehicle you want to charge, which can be found in the Tesla mobile app or on the Tesla website. Set the CHARGE_LIMIT variable to the percentage of charge you want the vehicle to reach during off-peak hours. Set the OFF_PEAK_START and OFF_PEAK_END variables to the start and end times of your off-peak period in your local time zone.
  3. Save the charge-tesla.py file.
  4. Run the charge-tesla.py script using the following command:
Code:
python charge-tesla.py

The script will automatically connect to your Tesla account, check the current time, and determine whether it is within the off-peak period. If it is within the off-peak period, the script will set the charging limit of your vehicle to the specified percentage, and if necessary, start charging the vehicle. If it is not within the off-peak period, the script will set the charging limit to 90% to prevent overcharging during peak hours.

Note that this script is provided as-is and may require modifications to work with your specific setup. It is recommended to carefully review the script and test it in a safe and controlled environment before using it in production.

I'll let @scdoubleu comment, but I reckon this is substantially wrong! Trouble is plenty of it is appropriate, and I don't know if the rest is

... but as an example of what @scdoubleu MIGHT write ... I guess its a good starting point :)
 
I'm figuring its far more likely that you are right on that one :)

As impressive as that reads, it is actually wrong as you have picked up 😄. The Tesla API can access Powerwall data and set a range of parameters for it, it is not limited to Tesla vehicles despite ChatGPT’s insistence.

The two APIs are like a Venn Diagram. For example, you can stop and restart a Powerwall through the Powerwall API, but you can’t do that through the Tesla API. Conversely, you can extract historical Powerwall power data (solar production, house and grid use, battery state of charge etc.) through the Tesla API, but not through the Powerwall API - despite ChatGPT saying that you can do the latter through the Powerwall API. And there are some things you can do with both - like report current state of charge.

ChatGPT also tells you to check “the official documentation” for the APIs - which is difficult, since Tesla does not provide any official documentation for them.

And to me that is the problem with this type of AI at present. It can produce very authoritatively sounding text that is incorrect. It reads like what someone who knows a reasonable amount on a topic would write, but it misses important information that an expert would include, or would not include because they know it is wrong. It reminds me of the adage “a little knowledge is a dangerous thing”.

How is someone who is not knowledgeable about a question they have asked going to judge whether the answer is right or not? What higher authority do they appeal to, to check or verify the answer?

What about if ChatGPT does that with something important? What happens when people are misled with AI misinformation?

This is getting off-topic 😄 but like Tom Scott, I am wondering where all this might lead 🤔
 
I'm on a blooming roll here ...

"can you write some instructions for Syncena's charge-tesla on github?"​



I'll let @scdoubleu comment, but I reckon this is substantially wrong! Trouble is plenty of it is appropriate, and I don't know if the rest is

... but as an example of what @scdoubleu MIGHT write ... I guess its a good starting point :)

Yeah, it's some way off the mark, which is a shame as it seemed to be doing pretty well up to that point. I'd say it's picked up the installation instructions of some other similar-but-different utility.

Glad I'm retired though - a few more iterations and younger software engineers might have a whole new set of reasons to be nervous.
 
  • Like
Reactions: WannabeOwner
Yeah, it's some way off the mark

"can you write some instructions for Syncena's charge-tesla on github?"

I did [deliberately] give it some fairly precise clues ... but with no disrespect intended yours isn't a billion-user API ... and the fact that it figured out anything I find pretty scary ... I agree, some of the replace "THIS with your LOGIN DETAILS" is most definitely the normal way for these types of libraries, and I found it refreshing that yours didn't do that but asks a question if the token has run out and then stores the result. Much better :) so not much surprise that ChatGPT just went with "normal form". Easy (for you) to edit what it wrote into some more accurate content - plus you'd wind up with something that IS representative of commonly used formats for similar material - bonus!

I see it as a drafting tool - "My Prof needs a 10,000 word essay by tomorrow morning and I haven't done any work yet - Help!"

I've used it to write a DOC for a presentation, and then fleshed out the content with real-and-accurate material - but the structure of its DOC and some paragraphs it choose to included I hadn't thought of / considered, and was very happy to steal ... saved me a fair bit of work.

We have real concerns with our staff using it ... giving it some real, and therefore company-confidential, data to assist it to write some "good stuff" will be causing that material to be stored on a server gawd-known-where and seen by gawd-knows-whom ... as a company we have a policy that all cloud products we use must be restricted to storage on servers hosted in UK only, but then we casually use something like JIRA for "a small project" without a second thought ... and I can envisage a JIRA Ticket being raised which has company-confidential, or client-confidential, information in it and at what point would the person creating the ticket think of that? And, worse, we are using the freebie version of JIRA 'coz its only used by a couple of people ... absolutely no idea where that is hosted, and whom by ... (yeah, I'm not having a a brand new thought and the issue is already under consideration ... but)
 
two things I'd like
  1. To force the car to charge from the grid and not drain the PW to its reserve limit and then continue from the grid
  2. To switch from grid to PW when the TBC limit is reached at 530am
I assume there's no way to do this except manually unless I have a degree in computer science... which I do not.
 
two things I'd like
  1. To force the car to charge from the grid and not drain the PW to its reserve limit and then continue from the grid
  2. To switch from grid to PW when the TBC limit is reached at 530am
I assume there's no way to do this except manually unless I have a degree in computer science... which I do not.

Well it’s certainly possible to do that using the Tesla API. You don’t need a degree in computer science (I don’t have one) but you do need to be reasonably experienced in coding (self-taught or schooled) and know how to use the various third party tools hosted on GitHub.

To do (1) just set the PW2 reserve limit to be its current SoC immediately prior to the car commencing charging. The PW2 will stop discharging and all house consumption will be from the grid.

And then to do (2) simply reset the PW2 reserve level back at 5:30am to whatever your normally have it set to. PW2 will recommence discharging if it needs to.