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

Using Fleet API to Control My Powerwall Reserve Percentage

This site may earn commission on affiliate links.
I've been using the Owner API to control when my Powerwall is charged from the grid, using Python scripts based on TeslaPy running on a RPi. This API is being turned off this year so I will need to move to using the new Fleet API.

I'm hoping that some of the app developers and script writers here can give me some advice. Although in theory I have the technical skills I'm not interested in developing an app for general users, I just want to automate setting the backup reserve percentage and operation modes via a Python script. Access to the Fleet API seems to entail registering as a third-party developer including having an app development project, a website etc. Now I could jump through those hoops, but as just an owner controlling one Powerwall is that necessary? Is that what Tesla expect the more technically savvy owners to do?

How do I set myself up so that when pricing tiers come into force it is obvious that I should continue to have free access for my one use?

I can't be the only person here running scripts, using TeslaPy or using the Owner API and changing over. How are you looking to do that?
 
Last edited:
  • Like
Reactions: Joerg
I went through this process for the Netzero app, so I can offer some perspective and a possible path forward.

The Fleet API is definitely geared towards businesses/developers. The sign up process has this:
To onboard your app, it must be requested under a legal business entity. We may contact your business to verify details.
From my experience, Tesla won't contact you and the approval process is instant, but that may change in the future. And this makes it clear they're not trying to support tech-savvy owner use cases.

Regarding Owner API shutdown: I contacted the Tesla engineering team in early Jan about when the Owner API will be shut down and they responded it will take "at least a few months". So this is not imminent (as you noted in the other thread, it's the Vehicle APIs that are being shut down now), but probably a good time to start planning for alternatives.

One possible alternative: using a third-party app to access APIs. I'm about to ship a web version of Netzero (and Netzero on iOS/Android already uses the Fleet API), so it would be pretty easy for me to enable these APIs for offline use. If that's something folks are interested in, let me know.
 
Last edited:
  • Like
Reactions: xWren and BGbreeder
Interesting, what's Netzero? I tried to find it on the iPhone App Store, is it an email app?

I am with you, xWren. I enjoyed having my own Python app that I have been able to tweak over the years controlling my cars. I see that others are moving to the new API as I have had to sign my Stats, TezLab, TeslaScope, and other apps into the new API. Not sure if Tesla means to screw hobbyists or not, but saying you need a business associated with the API's usage is off-putting.

Yesterday my own app stopped working on the original API with just a comment about Come check out our new way of logging in. I hear it's just those of us that are trying to access our vehicles and Solar Tesla Users are still able to use the unofficial API.

Hopefully one of the developers who has been thru it will do a write up on what they found was required, but the Tesla page was useless to me as I am a Python user and don't have experience with the direct URL calls and Tesla provided no Python demo apps. There appears to be a dearth of communication from the old guard of API documenters, so perhaps they feel their time is over now that there is an official version out there. Guess there won't be migration of TeslaPy to the new API.
 
Interesting, what's Netzero? I tried to find it on the iPhone App Store, is it an email app?
Oops, I added a link to my previous post: https://www.netzeroapp.io/

Hopefully one of the developers who has been thru it will do a write up on what they found was required, but the Tesla page was useless to me as I am a Python user and don't have experience with the direct URL calls and Tesla provided no Python demo apps. There appears to be a dearth of communication from the old guard of API documenters, so perhaps they feel their time is over now that there is an official version out there. Guess there won't be migration of TeslaPy to the new API.
I think you just have to give it some time, this is all very new. Here's a start from the Powerwall-Dashboard developer:

But it's also the case that Fleet API is not as easy to set up for hobbyists, so there will probably be fewer efforts like these.
 
  • Like
Reactions: israndy
Thanks for your input @offandonagain . I do have a tech business I could register with, however I don't have a website any more nor do I have an oAuth provider, and both seem to be necessary aspects of gaining permission and getting FleetAPI working. Have I understood correctly? Just how many hoops are there other than having a legitimate business?

Historically I have the skills to set this all up, I just start wondering if it would be easier to ditch the PW and buy a GivEnergy battery instead, that does offer the user control I need. Ironically the only thing it doesn't have is the ability to buffer data while offline, so internet outages lead to gaps in data collection, but that could be an easier problem to solve (while also getting all my house data into one local place).

One possible alternative: using a third-party app to access APIs. I'm about to ship a web version of Netzero (and Netzero on iOS/Android already uses the Fleet API), so it would be pretty easy for me to enable these APIs for offline use. If that's something folks are interested in, let me know.
I'm not sure what you mean by "enable these APIs for offline use" tell me more. If it gives me a way as a tech savvy owner to continue to make scheduled settings changes to my Powerwall then yes!

My other way forward is to encourage one of you dashboard app creators into adding a scheduled setting change facility 😄.
Nothing fancy, just the ability to set mode and backup reserve percentage at set times. Possible?
 
Last edited:
Thanks for your input @offandonagain . I do have a tech business I could register with, however I don't have a website any more nor do I have an oAuth provider, and both seem to be necessary aspects of gaining permission and getting FleetAPI working. Have I understood correctly? Just how many hoops are there other than having a legitimate business?
You need a business and a website, no OAuth provider. There are a few steps needed to get everything set up (you need to generate a key and host it on your website, register your account, etc.) but that's a one-time process and there are Python scripts that help with that. Also feel free to DM me for help.

I'm not sure what you mean by "enable these APIs for offline use" tell me more. If it gives me a way as a tech savvy owner to continue to make scheduled settings changes to my Powerwall then yes!
You would sign in to Netzero on web and then get the option to download your API tokens. Once you have the tokens, you can use Fleet API any way you choose: curl, Python scripts, etc. Fleet API can control settings such as backup reserve, operational mode (TBC/self-powered), grid charging, export everything, etc.

My other way forward is to encourage one of you dashboard app creators into adding a scheduled setting change facility 😄.
Nothing fancy, just the ability to set mode and backup reserve percentage at set times. Possible?
It's definitely possible, I think the challenge is that it's a power-user feature and needs to be done safely to prevent less savvy users from interfering with Tesla's algorithms and their system's performance.
 
Looks like ChargeHQ is already using the energy component of the FleetAPI.
Screenshot 2024-01-25 12.09.27.png


I would certainly like better manual controls for charging and discharging my Powerwall. The OwnerAPI is reasonable for charging on command, but you need to use the TBC workaround for discharging which isn't reliable.

@offandonagain have you considered a Home Assistant integration for your app? You certainly seem to have the API (local and cloud) aspects understood and Home Assistant would be a good platform for advanced controls.
 
Last edited:
I created a Third-party developer account with Tesla yesterday, but my attempts to request access for app credentials using valid business details got the immediate error "Unable to Onboard, Contact your account manager....". I suspect my current lack of a web page is the issue, I have a domain but it doesn't have an SSL certificate (I assume that is what "domains must be registered with a certificate authority" means) or point at actual storage I can access just a parking slot at GoDaddy. Now I'm researching free hosting, all I want is a tiny certified space that can hold the key, so far everywhere wants to help build me a website while taking my life details for sales exploitation etc. (and possibly not give the simple ftp access I want for access to the key). I remember the days when your ISP gave you some space...

I will continue to attempt to achieve what Tesla have made necessary for Fleet API use, meanwhile your help is appreciated @offandonagain and it's good to have at least the possibility of an alternative.
You would sign in to Netzero on web and then get the option to download your API tokens. Once you have the tokens, you can use Fleet API any way you choose: curl, Python scripts, etc. Fleet API can control settings such as backup reserve, operational mode (TBC/self-powered), grid charging, export everything, etc.
That sounds ideal for all us tech-savvy currently Owner API using owners that don't actually want to publish an app just set some settings, and very generous too. Do the tokens have a life, or is it until there is some problem and Tesla make everyone reset them? Let me know if this is how you go, and if you want a tester.

All I want is to be able to set the backup reserve percentage (and mode) while I'm sleeping.
It's definitely possible, I think the challenge is that it's a power-user feature and needs to be done safely to prevent less savvy users from interfering with Tesla's algorithms and their system's performance.
Oh yes, some users can get in a mess with anything! I understand, monitoring is harmless, setting a parameter less so, and the current situation of having to write scripts and set scheduled jobs going under Linux etc. does act as a 'do you really want to do this' filter. BTW that approach was easier for me than trying to work out what Home Assistant is and how I could use it to achieve the control I wanted on an old RPi2, that is also running as a in house only webserver managing my room thermostats (DIY replacement after the proprietary Heatmiser network device died in a thunderstorm).

It would be so much simpler if the PW was controllable locally, or Tesla offered a simple facility in self-powered mode (that worked during internet outages) for the owner to set a period for the battery to charge from the grid.
 
That sounds ideal for all us tech-savvy currently Owner API using owners that don't actually want to publish an app just set some settings, and very generous too. Do the tokens have a life, or is it until there is some problem and Tesla make everyone reset them? Let me know if this is how you go, and if you want a tester.

It's similar to how Owner API works: tokens expire after 8h, but you can refresh them on your own. If you want to give this a try, sign in here (use a desktop browser): Netzero.

Under the user menu, there's a Developer Access page. DM me for questions or comments.
 
  • Helpful
  • Like
Reactions: BGbreeder and xWren
@offandonagain Looks like the OwnerAPI has stopped control of energy products as of today ;-(
I think Tesla actually pushed a bad update because it broke some Fleet API endpoints as well. I let them know and they're looking at it, I'll post an update once I hear back.

Any opportunity for Netzero to allow control?
See the post above if you want to give this a try.
 
Nice, I have managed to download the API_TOKEN_FILE from your developer link and access my energy end points using your script and the FleetAPI.

I had to modify your script as my vehicles also came out of your scope and productlist, so my powerwall gateway was item [2].

mark@penguin:~/netzero$ ./fleet-api.sh
Tesla base url: https://fleet-api.prd.na.vn.cloud.tesla.com
Tesla energy site id: null
{
"response": null,
"error": "not_found",
"error_description": ""
}

This worked:


$ curl --header 'Content-Type: application/json' --header "Authorization: Bearer $TESLA_API_TOKEN" 'https://fleet-api.prd.na.vn.cloud.tesla.com/api/1/products'
{"response":[{"id"; XXXXXX


$ curl --header 'Content-Type: application/json' --header "Authorization: Bearer $TESLA_API_TOKEN" 'https://fleet-api.prd.na.vn.cloud.tesla.com/api/1/products' | jq -r .response[2].energy_site_id
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14253 100 14253 0 0 13731 0 0:00:01 0:00:01 --:--:-- 13744
YYYYYYYYYYYYY


$ curl --header 'Content-Type: application/json' --header "Authorization: Bearer $TESLA_API_TOKEN" 'https://fleet-api.prd.na.vn.cloud.tesla.com/api/1/energy_sites/YYYYYY/site_info'
{"response":{"id":"XXXXXXXXXX","site_name":"Gateway","backup_reserve_percent":10,"default_real_mode":"autonomous","installation_date":"2022-03-21T17:15:23+10:00","user_settings":{"go_off_grid_test_banner_enabled":false,"storm_mode_enabled":true,"powerwall_onboarding_settings_set":true,"powerwall_tesla_electric_interested_in":false,"vpp_tour_enabled":true,"sync_grid_alert_enabled":true,"breaker_alert_enabled":false},"components":{"solar":true,"solar_type":"pv_panel","battery":true,"grid":true,"backup":true,"gateway":"teg","load_meter":true,"tou_capable":true,"storm_mode_capable":true,"flex_energy_request_capable":false,"car_charging_data_supported":false,"off_grid_vehicle_charging_reserve_supported":false,"vehicle_charging_performance_view_enabled":false,"vehicle_charging_solar_offset_view_enabled":false,"battery_solar_offset_view_enabled":true,"solar_value_enabled":true,"energy_value_header":"Energy Value","energy_value_subheader":"Estimated Value","energy_service_self_scheduling_enabled":true,"show_grid_import_battery_source_cards":true,"set_islanding_mode_enabled":true,"wifi_commissioning_enabled":true,"backup_time_remaining_enabled":true,"battery_type":"ac_powerwall","configurable":true,"grid_services_enabled":false,"wall_connectors":[{"device_id":"YYYY","din":"XXXXXX","is_active":true},{"device_id":"YYYY","din":"CCCCCC","is_active":true}],"disallow_charge_from_grid_with_solar_installed":true,"customer_preferred_export_rule":"pv_only","net_meter_mode":"battery_ok","system_alerts_enabled":true},"version":"23.44.0 eb113390","battery_count":3,"tou_settings":{"optimization_strategy":"economics","schedule":[{"target":"off_peak","week_days":[1,0],"start_seconds":0,"end_seconds":3600},{"target":"peak","week_days":[1,0],"start_seconds":3600,"end_seconds":0}]},"nameplate_power":16500,"nameplate_energy":40500,"installation_time_zone":"Australia/Brisbane","max_site_meter_power_ac":1000000000,"min_site_meter_power_ac":-1000000000,"geolocation":{"latitude":-XXXX,"longitude":YYYYY,"source":"Site Address Preference"},"address":{"address_line1":"ZZZZZ","city":"XXXX","zip":"4567","country":"AU"},"vpp_backup_reserve_percent":10}}
 
I think Tesla actually pushed a bad update because it broke some Fleet API endpoints as well. I let them know and they're looking at it, I'll post an update once I hear back.
The Home Assistant integration was breaking all over the place, and many users thought it was the end with FleetAPI, but no, it was a simple X-Tesla-User-Agent string that needed to be updated and we are back online with the OwnerAPI, but it will be good to switch to the supported FleetAPI as soon as possible.
 
  • Like
Reactions: Paul Smedley
Been hastily updating my code to work with fleet, thanks to @offandonagain for the netzero info! Got to the point where I can set reserve/mode again via the fleet api, but one snag I've got is getting a refreshed token. The Python example referenced from netzero (tesla-solar-download/tools/fleet-api.sh at main · zigam/tesla-solar-download) give me an access denied when I try to run 'fleet-api.sh --refresh'. Anyone else managed to get the refresh token working? Not sure what I'm missing
 
Last edited:
The Home Assistant integration was breaking all over the place, and many users thought it was the end with FleetAPI, but no, it was a simple X-Tesla-User-Agent string that needed to be updated and we are back online with the OwnerAPI, but it will be good to switch to the supported FleetAPI as soon as possible.

What did you need to update? I created a small app for my powerwall and it stopped working. Thanks
 
I had to modify your script as my vehicles also came out of your scope and productlist, so my powerwall gateway was item [2].
Good catch, I fixed the script to grab the first valid energy_site_id.

Added the following the the curl in the refresh, in case anyone else is banging their head against a wall:

curl --tlsv1.2 --tls-max 1.2
Thanks, haven't seen this issue before (probably caused by openssl version oddities), but I added it to the script just to be safe.
 
  • Like
Reactions: mst360 and xWren