Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

410 error on get_battery_data #145

Open
doubledrat opened this issue Oct 6, 2023 · 15 comments
Open

410 error on get_battery_data #145

doubledrat opened this issue Oct 6, 2023 · 15 comments

Comments

@doubledrat
Copy link

doubledrat commented Oct 6, 2023

Get battery data Started failing last night with the following error -

requests.exceptions.HTTPError: 410 Client Error: https://powergate.prd.sn.tesla.services:443/api/powerwalls/idremoved/fullstatus => Gone for url: https://owner-api.teslamotors.com/api/1/powerwalls/myidremoved

@doubledrat doubledrat changed the title 410 error on get_battery_status 410 error on get_battery_data Oct 6, 2023
@yanschneider
Copy link

For me as well. It seems that the teslamotors api is no longer available under the given URL.

@DaveTBlake
Copy link

DaveTBlake commented Oct 6, 2023

Same here, my script using get_battery_data failed last night. Looks like the endpoints starting api/1/powerwalls/ no longer work :(

However I have had success getting the Powerwall data I want by swapping to use api/1/energy_sites/{site_id}/site_info, followed by api/1/energy_sites/{site_id}/live_status, calling the first is necessary for the second API call to return fully populated data. These endpoints are in endpoints.json as "SITE_CONFIG" and "SITE_DATA" respectively, and to access them I have added routines to the battery class in _init_.py as follows

    def get_site_info(self):
        """ Retrieve current site/battery information """
        self.update(self.api('SITE_CONFIG')['response'])
        return self

    def get_site_data(self):
        """ Retrieve current site/battery live status """
        self.update(self.api('SITE_DATA')['response'])
        return self

@JuhaSeppa
Copy link

JuhaSeppa commented Oct 6, 2023

I've been fetching Tesla Powerwall power timeseries data, which stopped working via the api/1/powerwalls/ path. I was able to retrieve the same data from the 'CALENDAR_HISTORY_DATA' api endpoint with kind='power' and date_end='time in isoformat' arguments to get the data I wanted.

@mquilling0
Copy link

I am having the same issue but for setting operation mode - any workaround for this?

battery.set_operation("self_consumption")

410 Client Error: https://powergate.prd.sn.tesla.services:443/api/powerwalls/{xxxx}/operation => Gone for url: https://owner-api.teslamotors.com/api/1/powerwalls/{yyyy}/operation

@j4mie
Copy link

j4mie commented Oct 6, 2023

@mquilling0 it looks like this works:

battery.api("OPERATION_MODE", default_real_mode="self_consumption")

There seem to be two endpoints for changing operation mode. set_operation uses the one named BATTERY_OPERATION_MODE in the endpoints.json file, which points at api/1/powerwalls/{battery_id}/operation. This is the one that no longer works. OPERATION_MODE, on the other hand, uses api/1/energy_sites/{site_id}/operation, which does still work. Presumably set_operation needs to be changed to use this endpoint.

@JuhaSeppa
Copy link

I am having the same issue but for setting operation mode - any workaround for this?

battery.set_operation("self_consumption")

410 Client Error: https://powergate.prd.sn.tesla.services:443/api/powerwalls/{xxxx}/operation => Gone for url: https://owner-api.teslamotors.com/api/1/powerwalls/{yyyy}/operation

Depending on what you want to achieve, you might be able to realise the desired functionality by keeping the operation mode unchanged and just manipulating the backup reserve percentage.
I’ve implemented charge (backup = 100%), standby (backup = current charge level from the local API) and self consumption (backup = whatever percentage you want to keep in reserve for a power cut) this way while keeping mode as autonomous. Overnight cheap electricity is configured to the Powerwall and I use these operations only when I want to achieve something else.

@mquilling0
Copy link

thank you @j4mie that worked!

@mquilling0
Copy link

@JuhaSeppa i have a very specific need that neither mode can achieve alone

export from sun up to 9am
charge from 9am to 4pm
export from 4pm to 8pm but dont drop below 65% (we rarely use the grid but this is the only time we might - which gives us the ability to be awake and limit usage during an outage)
use battery overnight (but turn off any appliance if % drops below 10% - rarely happens)

i can achieve this exact profile and rarely use any grid energy + maximize my energy export credit. our yearly bill is negative.

using time based control it does all kinds of dumb stuff and pulls a few kW/day from the grid.

@HeraldCoupe
Copy link

I presume at some point TeslaPy will be updated to reflect the change that Tesla have implemented.
Any ideas as to when?
Thanks to the developers, TeslaPy is a life-saver!

@yanschneider
Copy link

battery.api("OPERATION_MODE", default_real_mode="self_consumption")

still gives me the 410 error unfortunately.

tesla = teslapy.Tesla(email_address)
battery_list = tesla.battery_list()
battery = battery_list[0]
battery.api("OPERATION_MODE", default_real_mode="self_consumption")
#battery.set_operation('self_consumption')
battery.set_backup_reserve_percent(10)

@tdorssers
Copy link
Owner

I don't own a powerwall, so I cannot test it, but commit 50bdbfb should fix this, based on @DaveTBlake's code.

@mquilling0
Copy link

@tdorssers tested and works, thx!

@HeraldCoupe
Copy link

I don't own a powerwall, so I cannot test it, but commit 50bdbfb should fix this, based on @DaveTBlake's code.

Thank you so much, I've also tested it and got it working.

@jasonacox
Copy link

@tdorssers Thank you! This does indeed fix the issue. The schema changed a bit for battery so anyone using this to read battery data will need to a adjust (example).

Test:

# Pull latest TeslaPy - use latest until TeslaPy releases a new PyPI package
pip install -e git+https://github.com/tdorssers/TeslaPy.git#egg=teslapy

# Pull latest set-reserve.py 
wget https://raw.githubusercontent.com/jasonacox/pypowerwall/main/tools/set-reserve.py

# Test
python3 set-reserve.py --read
READ: Current Battery Reserve Setting: 20% for 2 Powerwalls

@DaveTBlake
Copy link

using time based control it does all kinds of dumb stuff and pulls a few kW/day from the grid.

@mquilling0 doesn't it just!!!

I don't own a powerwall, so I cannot test it, but commit 50bdbfb should fix this, based on @DaveTBlake's code.

Thanks @tdorssers , sorry I didn't get my act together and raise a PR just left code suggestions. I'm very grateful for everything you have done making the API avialable, my Powerwall would be unmanageable without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants