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

Automated back up mode with python and rest

This site may earn commission on affiliate links.
You would be proud of me Darwin I used windows scripting and python turn on and off back up mode :) now I can control when full solar charges battery . In need to do a larger write up but here is code and pics : I do think I have to many schedules define since shoulders Define off peak.

Python :
I found a python API as well. This actually worked a lot better, just made few tweaks on the username / password. etc, and then added these as schedule tasks in windows machine to run at 9am and 9pm.

Python :
I found a python API as well. This actually worked a lot better, just made few tweaks on the username / password. etc, and then added these as schedule tasks in windows machine to run at 9am and 9pm.

piersdd/tesla-powerwall-json-py

Then my fork :
My mods are located here:
CodePile | Easily Share Piles of Code

did you know you could use teg controller and make rest calls to it game changing ::
vloschiavo/powerwall2
 
  • Like
Reactions: sorka and Darwin
DD1EE15E-3AFD-46A1-AFC4-09EDB0E19C5A.png
 
Small bug in first script not getting new tokens updated here :


Its not really a repo, just a single python script:
CodePile | Easily Share Piles of Code

Just run like python filename.py and let it rip.
You do need to change parameters like data, gateway, password, email etc. to your own.
Use your installer password , your email, your gateway IP, most likely your token would be expired it and has to grab a new one.
Cheers , if you need help let me know
 
I'm set to get my system installed next week. I was hoping to use a script to allow the powerwall to charge from the grid (force storm mode....I think that what its called) and then discharge during high rate times for my personal use. Is this what this script permits?
 
I'm set to get my system installed next week. I was hoping to use a script to allow the powerwall to charge from the grid (force storm mode....I think that what its called) and then discharge during high rate times for my personal use. Is this what this script permits?
Unfortunately storm watch mode can't be set through the API - it has to be initiated by the server. If they allowed that loophole, they wouldn't be able to guarantee that the Powerwalls are mostly charged from solar, so I doubt it'll be available any time soon.
 
I'm set to get my system installed next week. I was hoping to use a script to allow the powerwall to charge from the grid (force storm mode....I think that what its called) and then discharge during high rate times for my personal use. Is this what this script permits?

It's pretty well established that Tesla won't configure the PWs to charge from the grid in the US and gives customers no way to force this (API or otherwise), and most utilities won't approve it to be used this way. A couple people on these forums seem pretty confident they can convice Tesla to configure their PWs/Gateway to charge from the grid, but I haven't seen anybody post in regard to "actually" having accomplished this in the US.

Also, in terms of stormwatch, Tesla totally controls when your system will go into stormwatch mode and in turn then when it could charge from the grid on a very limited basis. You can only choose to allow that to happen (On) or not to happen (off) should Tesla trigger a stormwatch condition for your area, which are pretty rare - i.e. only during severe conditions where power his likely to be lost due to major weather situations or other disaster scenarios.

I believe Tesla is forced to limit and totally control grid charging like this in the US due to agreements with regulators and utilities that were required for Tesla to actually be allowed to move forward with installing Powerwalls at scale, and to maintain various required product licenses and certifications that are required to sell PWs in the US for grid connected systems. Even if a given utility says they support grid charging, Tesla may not be able to allow that due to product certification requirements (just a guess here) that limit what has those products operate on the grid in the US. Clearly Tesla otherwise supports charging from the grid because it's possible in other countries.
 
Last edited:
I wonder if we could use the solution mentioned here:

hackerschoice/thc-tesla-powerwall2-hack

Let's flip the reading of the GRID CT Clamp in the PW-UI. Lets assume the CT Clamp reading is +1kW (e.g. that the house is drawing +1kW from the grid). After flipping the reading the GW received -1kW and believes that the energy is being exported to the grid. The PW immediately goes into charging mode and starts charging the PW. This causes more power to be drawn from the grid (say +2kW). The CT Clamp reports this to the GW as -2kW (remember, it's flipped) and the PW ramps up charging...and draws even more power from the grid..and so on and so on...until it's charging at full load of +5kW. All this happenes within microseconds.
 
It's pretty well established that Tesla won't configure the PWs to charge from the grid in the US and gives customers no way to force this (API or otherwise), and most utilities won't approve it to be used this way. A couple people on these forums seem pretty confident they can convice Tesla to configure their PWs/Gateway to charge from the grid, but I haven't seen anybody post in regard to "actually" having accomplished this in the US.

You can make it charge from the grid by changing it's settings, I tried it and it works, but it's by no means a clean answer. Put your powerwall into backup mode, then go into the configuration wizard, delete the solar array, and switch the solar solar CT's to "Site" or "None". Voila, it'll charge to 100% from the grid since it thinks it's a non-solar.
 
You can make it charge from the grid by changing it's settings, I tried it and it works, but it's by no means a clean answer. Put your powerwall into backup mode, then go into the configuration wizard, delete the solar array, and switch the solar solar CT's to "Site" or "None". Voila, it'll charge to 100% from the grid since it thinks it's a non-solar.

Understood. I haven't done that specifically myself, I have played with physically moving the solar CT clamp to another circuit and was able to experiment with forcing grid charging - but what I did was not automatable in any practical sense. Well, I have lots of home-built home automation in place and actually probably could if I felt I had the need. Oddly before the system was installed, and right afterwards I had a burning desire to do all sorts of configurations that "weren't" allowed. In reality, after seeing the system in usage most of this turned out to be very edge situations that I normally wouldn't want in place anyway. Just a little more control over schedules and mode changes, and reserve levels would be much appreciated. Given my utility plans, there is no value in grid charging since I have more than enough solar (except emergency situations which are kind of handled). Also, at least in my case I actually got a visit from my utility when I did that for multiple days while my PV inverter was out.

During that time I was able to force charging overnight this way and still avoid Peak house load usage with the PW running the house during my utility peak periods - but my utility actually noticed and paid me a visit to see what was going on. Luckily just prior to that unexpected visit I had happened to move the CT clamp back to the solar live circuit since Tesla was coming out to fix the broken inverter - and because of the inverter situation that had just been fixed the previous day the Utility guy said "ok" and that'd they just monitor things for a while and come back if they saw a recurrence of the "weird" behavior of my system. They were not visiting because of the inverter outage which they were already aware of because I called and tried to get off the solar plan during my solar outage (which they wouldn't do!), and they said they could help in no way.

Are the changes you made via the wizard configurable via an API? Cool if possible. If not possible, my point pretty much still stands for all practical purposes, and probably in terms of not voiding warranties on this very expensive equipment, and causing a situation with the utility. I'm guessing Tesla can see this has occurred unless we isolate our Gateways & PWs from the internet/Tesla. So again, not practical in my opinion if only for risk and warranty reasons, and losing future updates which hopefully will occur in the future to allow for better configurations & schedules within the realm of what the PWs can mostly already do.

One other note, I also played with isolating the Gateway from internet access while I was trying to resolve what appeared to be some issues I was having with IP conflicts on my home network, and after resolving my immediate issue, I got distracted with life, and inadvertently left the gateway isolated. After a few days I received an email from Tesla saying that my Gateway/PWs had not connected to Tesla for a while, and for continued support I needed to follow some instructions, and/or contact them to resolve the situation if the instructions didn't work. While they didn't say anything about voiding warranty and such, the email was kind of worded in a way that made me nervous in regard to this expensive investment I had just made and in terms of their ability to flag and notice anomalies with my system out of all the the many systems I'm sure they've installed.
 
Last edited:
You can make it charge from the grid by changing it's settings, I tried it and it works, but it's by no means a clean answer. Put your powerwall into backup mode, then go into the configuration wizard, delete the solar array, and switch the solar solar CT's to "Site" or "None". Voila, it'll charge to 100% from the grid since it thinks it's a non-solar.
In this scenario, then

(1) Powerwalls charge off-peak from grid, and discharge during partial peak and full peak
(2) All solar is net metered back to PG&E
(3) Your app will not be able to show you how much you generated from your panels, however your inverter or NGOM will show it but that's a manual process of going to those devices to read the data.

Is that what you noticed as well when you did this? How long did you let it run like this?

PG&E will see that you're net metering all solar generated, and they will see consistent spikes of 5kw per PW as each one start charging from the grid at the off-peak hours.
 
I only tried this a few times, because I'm pretty sure that Tesla sees any config changes and doing them daily might be suspicious.

Yes, if the PW is full, you will net-meter power back into PG&E from solar. Your app also doesn't show you power from the panels during this time, this is correct, it's included in the grid power or discarded, based on CT settings. When I did try it, I charged it from about 20% to about 80% so it had enough power to soak up my solar - never metered back into the grid. If I can avoid sending a single watt to PG&E, I'm happy :)

Also, the PW never charges at 5kW from the grid, it seems to top out at 3.4kW, which makes sense since this would be a charge rate of 0.25C which seems like a reasonable default for battery health, and it's a nice round number that an engineer might type in.
 
  • Like
Reactions: zanary
I would be careful with the solar configuration for the Powerwall. In particular, I would make sure to test that the Powerwalls still do the frequency shifting to curtail solar production during a grid outage when the SoC is high. I'd be worried about possible issues during power outages if the don't.
 
Im installing a 11.3KW system from Tesla with 2 PW units next week. I dont expect my solar will cover my usage by any means as I use up to 18 kWh per hour in the summer months during peak times for up to 3-4 hours. My average hourly use is 8-10 kWh when I'm not charging my car or running my 4 AC units heavily. I was hoping to allow the solar to cover partially during the day and use the PW to cover the peak energy on the evening hours and possibly the AM. I pay realtime market energy prices through a company called Griddy and I have seen prices peak as high as $9 per kWh (yes $9 dollars) for a few hours on days in the summer when the grid in Texas was being overburdened, Most of the time my rate if $.07 per kWh . (huge difference). I was hoping to be able to charge the PW units from the grid when needed when rates are low. Any suggestions on how I might set this up?
 
Im installing a 11.3KW system from Tesla with 2 PW units next week. I dont expect my solar will cover my usage by any means as I use up to 18 kWh per hour in the summer months during peak times for up to 3-4 hours. My average hourly use is 8-10 kWh when I'm not charging my car or running my 4 AC units heavily. I was hoping to allow the solar to cover partially during the day and use the PW to cover the peak energy on the evening hours and possibly the AM. I pay realtime market energy prices through a company called Griddy and I have seen prices peak as high as $9 per kWh (yes $9 dollars) for a few hours on days in the summer when the grid in Texas was being overburdened, Most of the time my rate if $.07 per kWh . (huge difference). I was hoping to be able to charge the PW units from the grid when needed when rates are low. Any suggestions on how I might set this up?

Purchase a different product other than tesla powerwalls, which do not allow charging from the grid unless put in stormwatch mode by tesla?

Not trying to be funny, it just doesnt sound like tesla powerwalls are the solution you need since they dont do what you want, by design, from tesla, if you have solar.
 
Not a bad question. Unfortunately there isn’t an alternative product I could find.
Fair enough...

One thing I would caution you of, however, as someone who has been a tesla customer in one form or another since 2015, is buy whatever you plan on buying from tesla on what it does "now" and think that anything else they add is "extra". I would highly recommend NOT buying a tesla product "because it will do XXX in the future".

You have to be able to enjoy the product for what it is now, and be happy that they added something, not upset that you were waiting on some feature or other that they havent introduced yet.

What I mean in your specific situation is, there is talk here on these boards of the fact that tesla has this limit on charging due to making the product (PW2) compatible with both the federal tax credit and the california SGIP requirements of charging from renewable energy. There is talk that this is a 5 year limit, and some think that tesla might change something in 5 years, or allow owners to remove / change the limits at that time.

if you go forward with your purchase (likely) its best to not expect them to change this limit, or, to be able to work around their imposed limits... so you if you go forward, it should be with the expectation that you will never get a solution that allows you to do rate arbitrage in the way you want. That would be my advice anyway, for what its worth (which is very little, lol).

Anyway, good luck!
 
  • Like
Reactions: bmah
Wow so much conversation :
This script just ensures full charge of solar during non peak hours by making use of back up mode . In back up mode battery reserve is pegged at hundred percent so if there is a period of time say your non peak cheaper hours you just want the powerwall to be in charge mode these scripts let you do that .

we have 2 peaks 5am to 9am so we need to be in charge mode beteeen 9am and 5pm. And discharge from 5pm to 9pm.

I have a smaller solar system so using out of box time based modes only use excess solar which is not enough charge .

i modified scripts a little bit to also commit and restart as suggested by :
More info :

Change the Powerwall mode and Reserve Percentage · Issue #18 · vloschiavo/powerwall2
 
I'm set to get my system installed next week. I was hoping to use a script to allow the powerwall to charge from the grid (force storm mode....I think that what its called) and then discharge during high rate times for my personal use. Is this what this script permits?[/
w so much conversation :
This script just ensures full charge of solar during non peak hours by making use of back up mode . In back up mode battery reserve is pegged at hundred percent so if there is a period of time say your non peak cheaper hours you just want the powerwall to be in charge mode these scripts let you do that .

we have 2 peaks 5am to 9am so we need to be in charge mode beteeen 9am and 5pm. And discharge from 5pm to 9pm.

I have a smaller solar system so using out of box time based modes only use excess solar which is not enough charge .

i modified scripts a little bit to also commit and restart as suggested by :
More info :

Change the Powerwall mode and Reserve Percentage · Issue #18 · vloschiavo/powerwall2