tesla icon indicating copy to clipboard operation
tesla copied to clipboard

Tesla Vehicle Command Protocol required - Performing actions (such as lock, unlock etc) fails with a traceback

Open stellarhopper opened this issue 1 year ago • 90 comments

Version of the custom_component

v3.19.3

Configuration

Not sure what to attach here, but using the default config for everything.


Describe the bug

This is a fresh install of Home Assistant on the 'Yellow' board, and of this plugin. I'm able to sync data from tesla correctly, but performing any action such as locking/unlocking doors, setting charge limit etc doesn't seem to work. There is a traceback in the logs that is attached below.

Debug log


2023-11-12 17:10:09.296 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [548106961344] 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 99, in _async_lock
    await entity.async_lock(**remove_entity_service_fields(service_call))
  File "/config/custom_components/tesla_custom/lock.py", line 36, in async_lock
    await self._car.lock()
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/car.py", line 854, in lock
    data = await self._send_command("LOCK")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/car.py", line 775, in _send_command
    raise ex
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/car.py", line 760, in _send_command
    data = await self._controller.api(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/controller.py", line 1311, in api
    response = await self.__post_with_retries(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 88, in async_wrapped
    return await fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 47, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tenacity/__init__.py", line 325, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tenacity/__init__.py", line 158, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 50, in __call__
    result = await fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/controller.py", line 1334, in __post_with_retries
    return await self.__connection.post(command, method=method, data=data, url=url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/connection.py", line 165, in post
    return await self.__open(url, method=method, headers=self.head, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/teslajsonpy/connection.py", line 216, in __open
    raise TeslaException(resp.status_code)
teslajsonpy.exceptions.TeslaException

stellarhopper avatar Nov 13 '23 00:11 stellarhopper

Please enable debugging and then provide updated logs of the call.

alandtse avatar Nov 13 '23 02:11 alandtse

@alandtse Ah nice, looked into debug logging and I tink I have it on. With it I'm seeing an API error:

2023-11-13 00:42:19.918 DEBUG (MainThread) [custom_components.tesla_custom.lock] Locking: Doors                                                                                                                  
2023-11-13 00:42:19.918 DEBUG (MainThread) [teslajsonpy.car] Sending command: LOCK                                                                                                                               
2023-11-13 00:42:19.918 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:06:20                                                                                                                  
2023-11-13 00:42:19.919 DEBUG (MainThread) [teslajsonpy.connection] post: https://owner-api.teslamotors.com/api/1/vehicles/[removed]/command/door_lock {}                                                 
2023-11-13 00:42:20.048 DEBUG (MainThread) [teslajsonpy.connection] 403: {"response":null,"error":"Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/d
ocs/fleet-api#2023-10-09-rest-api-vehicle-commands-endpoint-deprecation-warning","error_description":""}   

stellarhopper avatar Nov 13 '23 07:11 stellarhopper

FWIW The Tesla software version is 2023.38.6

stellarhopper avatar Nov 13 '23 07:11 stellarhopper

Just adding to this - same issue for me - brand new MY FW 2023.32.200. When trying any action or calling an action (SCHEDULED_CHARGING) it fails with error [teslajsonpy.connection] 403: {"response":null,"error":"Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api#2023-10-09-rest-api-vehicle-commands-endpoint-deprecation-warning","error_description":""} Could this be Tesla implementing this on new vehicles? Polling works - same API call worked on my old 2020 M3.

efoverskov avatar Nov 13 '23 18:11 efoverskov

I'm getting the same thing, worked fine this morning but started to fail this afternoon with:

2023-11-13 19:48:20.837 DEBUG (MainThread) [teslajsonpy.connection] 403: {"response":null,"error":"Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api#2023-10-09-rest-api-vehicle-commands-endpoint-deprecation-warning","error_description":""}

joperezr avatar Nov 14 '23 03:11 joperezr

Yes, this is a known issue #742. Tesla is breaking the old API for newer vehicles. Hopefully someone who has such a vehicle will submit a PR.

alandtse avatar Nov 14 '23 06:11 alandtse

IIUC the new API is a Go SDK which AFAIK isn't trivially usable from Python, so I guess one would need to first write python bindings for that SDK, so that it can be used by this integration.

joperezr avatar Nov 14 '23 06:11 joperezr

Got my new Tesla MYLR last week softwareversion 2023.32.200 i have same problem. All data comes into Home Assistant fine, but I can't send anything the other way

mmeyerc avatar Nov 15 '23 07:11 mmeyerc

So I think I found a potential solution to this. According to https://github.com/teslamotors/vehicle-command, the repo not only contains the new Go command SDK, but instead it also provides an http proxy that can be setup which can receive calls using the old FLEET API, and can then internally use the go SDK in order to forward those commands appropriately so that they can start reaching the car again. The setup for this proxy is for sure not straight forward, and it involves generating private keys, and registering those with your car via a new tesla endpoint, but assuming we get over the setup hurdle, we should be able to continue to make the calls using the FLEET API and for those to work with new cars that require the new SDK. The overall plan would be basically this for folks that want to set this up:

  1. Users interested in this, will have to setup a server (either a new raspberry pi or the same one running home assistant in case its running in docker) which is running the HTTP proxy and is properly configured following these instructions.
  2. Then, users will go and configure the tesla home assistant integration in this repo by following the regular instructions in the README. One new requirement (feature request) would be that one new configuration setting is exposed by the integration, which is the url where the commands will be sent against. I only looked briefly at teslajsonpy APIs but it does look like they support passing in alternate urls for sending the commands. If this setting is provided to the integration, then the integration can just use that url when initializing the tesla controller, so that all calls are forwarded to it. Users will configure the url to be the address of the server that they have setup in step 1.
  3. Everything should work now 😃

This solution is of course not ideal because it will require a lot of setup from the user's side, but the main benefit is that it would require very minimal changes on this integration (just exposing the new setting and flowing it through) and will immediately add support to all of the cars that were built post-2021 (which of course will be quite a bit XD).

@alandtse thoughts? Does this sound reasonable?

joperezr avatar Nov 16 '23 04:11 joperezr

Happy to take a PR. If someone wants to create a HA Addon for the proxy, we can leverage that.

alandtse avatar Nov 16 '23 04:11 alandtse

is there any chance to get that to work?

daddyd0108 avatar Nov 26 '23 12:11 daddyd0108

Unfortunately you'll probably have to wait for someone with the new car that requires this to submit a PR or workaround. I'm not planning on buying a new Tesla (and doubt anyone would buy one for me ;) ) and the old api will continue to work for me.

alandtse avatar Nov 26 '23 23:11 alandtse

Btw I don't think this is so much related to a new car rather than maybe Tesla flipping a switch as to when the old API gets deprecated?

Mine is a 2021 Y.

On Sun, Nov 26, 2023, 16:38 Alan Tse @.***> wrote:

Unfortunately you'll probably have to wait for someone with the new car that requires this to submit a PR or workaround. I'm not planning on buying a new Tesla (and doubt anyone would buy one for me ;) ) and the old api will continue to work for me.

— Reply to this email directly, view it on GitHub https://github.com/alandtse/tesla/issues/774#issuecomment-1826939922, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIFCF26BTLKSUCSFLMMESDYGPHILAVCNFSM6AAAAAA7IL4KV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRWHEZTSOJSGI . You are receiving this because you authored the thread.Message ID: @.***>

stellarhopper avatar Nov 26 '23 23:11 stellarhopper

The setup for this proxy is for sure not straight forward, and it involves generating private keys, and registering those with your car via a new tesla endpoint, but assuming we get over the setup hurdle, we should be able to continue to make the calls using the FLEET API and for those to work with new cars that require the new SDK.

The big caveat here is that Tesla has to approve every single Fleet-API client. Which they likely won't do for individual vehicle owners. So all of this effort might end up only useful for a select few that by chance managed to gain Fleet-API access.

There are two solutions that "scale" and could allow every vehicle owner to continue to send commands:

  • Find out how the Tesla App is doing it, which I am trying and invite more collaborators in https://github.com/timdorr/tesla-api/discussions/769 - this would then send the command directly to Teslas servers but would also require a complicated setup procedure to register a key to the vehicle via Bluetooth.
  • One or multiple "trusted" Fleet-API "Partners" grant everybody access "through" them. As the TOS and common sense forbid sharing their credentials and keys directly, they would need to run the proxy on their infrastructure, which means you would need to authorize and trust them with more or less unlimited vehicle control. So you would send a variation of "/api/1/vehicles/{id}/command/charge_start" to say Teslascope's or maybe TeslaFi's API, they turn it into a signed command with their private key, and send that to the Fleet API with their partner credentials.

lotharbach avatar Nov 27 '23 11:11 lotharbach

A third solution that scale (but with different tradeoffs) :

  • Use the BLE integration from https://github.com/teslamotors/vehicle-command to have local polling of your Tesla. Benefit : local polling. Drawback : only works when your Tesla is at Home and that you have BLE range where it's parked.

gcamp avatar Nov 27 '23 14:11 gcamp

The big caveat here is that Tesla has to approve every single Fleet-API client. Which they likely won't do for individual vehicle owners. So all of this effort might end up only useful for a select few that by chance managed to gain Fleet-API access.

That could be in contradiction to their own "direct sale" idea. It could have been a dealer having fleet of his clients, however, every individual has to deal with Tesla directly. So, every individual should be able to get whatever is needed directly for each car separately. Needless to say this is selling point similar to superchargers. If that is gone, it will be a lot less tempting to have Tesla.

There are two solutions that "scale" and could allow every vehicle owner to continue to send commands:

* One or multiple "trusted" Fleet-API "Partners" grant everybody access "through" them. As the TOS and common sense forbid sharing their credentials and keys directly, they would need to run the proxy on their infrastructure, which means you would need to authorize and trust them with more or less unlimited vehicle control.  So you would send a variation of "/api/1/vehicles/{id}/command/charge_start" to say Teslascope's or maybe TeslaFi's API, they turn it into a signed command with their private key, and send that to the Fleet API with their partner credentials.

This is exactly what many do today - hand over vehicle control to random entities with no idea how trusted/secure they are. I believe whole idea is to stop it.

darek-margas avatar Nov 27 '23 23:11 darek-margas

Unfortunately you'll probably have to wait for someone with the new car that requires this to submit a PR or workaround. I'm not planning on buying a new Tesla (and doubt anyone would buy one for me ;) ) and the old api will continue to work for me.

It won't take long for yours. Update from ChargeHQ below:

UPDATE 2023-11-24

Tesla have announced that the old API will stop working on vehicles as follows:

November 2023 -newly delivered vehicles will only support the new API
Nov - Dec 2023 - the old API will stop working on existing vehicles that have not used the old API in the preceding 30 days
January 2024 - the old API will stop working on all vehicles

darek-margas avatar Nov 28 '23 12:11 darek-margas

What about using the Tessie API? I know it's not free, but they are using the official Tesla API. We could set up the Tessie token, and make API calls to our Teslas through Tessie API.

sjvc avatar Dec 02 '23 10:12 sjvc

only works when your Tesla is at Home and that you have BLE range where it's parked.

I guess someone could also cook up what is essentially a WAN-to-BLE gateway that you can install in your car to allow access outside of the home? I wonder if that gains you much over just using the new API.

juicejuice avatar Dec 07 '23 02:12 juicejuice

i maintain a program in hubitat that used to work for controlling the car.. now that seems also broken for newer cars as outlined above.. i see teslafi has an alexa integration.. hopefully they will make this continue to work.. and maybe even do their own local api.. i fear that this will be the only type of viable solutions in the future a big aggregator like them that handles the backend with tesla and you go through them to do commands... pain int he ass.

lgkahn avatar Dec 19 '23 21:12 lgkahn

I’ve got some experience in golang but not much with home assistant, and I have one of the new affected teslas.

If anyone wants to work together on this let me know - I’ve successfully got Tesla control working on a mac, but haven’t attempted with a raspberry pi (which is what I use for HA). I’d be looking at the BLE solution only, and mostly interested in changing options rather than full control.

danielnitsche avatar Dec 25 '23 09:12 danielnitsche

I’ve got some experience in golang but not much with home assistant, and I have one of the new affected teslas.

If anyone wants to work together on this let me know - I’ve successfully got Tesla control working on a mac, but haven’t attempted with a raspberry pi (which is what I use for HA). I’d be looking at the BLE solution only, and mostly interested in changing options rather than full control.

Hi, I have an affected 2021 M3P + a working HA in docker (Intel platform) currently using https://github.com/alandtse/tesla (all options are read-only). I'll be looking at the BLE integration @gcamp posted as I have time to see if it does what I need to send simple commands. Start/stop charging commands will be my priority since I will be working on an automation and/or script in HA that allows stop/start charging based upon Tesla charge level, current solar production, home battery storage charge level etc. I'd be interested in working with others to test/learn (on this or other synergistic projects) and perhaps even write some code once I have a decent foundation and better understand the codebase, goals etc.

motley-git avatar Dec 30 '23 17:12 motley-git

i am just ready to beta test a new version of tesla control i have implemented for the hubitat home automation.. this is using the teslafi interface so you have to sign up with them. currently it works if you are stll on the OLD tesla api version, but i have talked to teslafi and they will be modifying their implementation to work with the new protocoll/api that is rumored to take full control at the end of january.

due to the fact that tesla will be monitizing this and you need to be a company to effectively use the new api you will need a third party integrator like teslafi..

thus my implementation i hope will be transparent when they are done and the new api kicks fully in

lgkahn avatar Dec 30 '23 17:12 lgkahn

Recent core added Tessie integration and it works.

darek-margas avatar Jan 04 '24 10:01 darek-margas

Recent core added Tessie integration and it works.

But requires a tessie subscription

dcegelis avatar Jan 04 '24 17:01 dcegelis

I have a 2023 M3P, and am willing to assist with this. I will say I'm not too versed in Home Assistant, but am willing to learn.

haggertd avatar Jan 04 '24 23:01 haggertd

Tesla has shut down the API we've been relying on...

@alandtse Is there any news, developments, or even a glimmer of hope regarding this integration working again in the future? Any updates or insights you can provide would be greatly appreciated.

NyLan-1 avatar Jan 09 '24 15:01 NyLan-1

Just as an FYI this now appears to be affecting Powerwall as well as vehicles.

Everything is read only.

JasSmiths avatar Jan 26 '24 02:01 JasSmiths

I.implemented a new home automation integration in hubitat via www.Tessie.com if anyone is interested.

This to replace my prior integration that went direct to tesla.

lgkahn avatar Jan 26 '24 04:01 lgkahn

I.implemented a new home automation integration in hubitat via www.Tessie.com if anyone is interested.

This to replace my prior integration that went direct to tesla.

Isn't Tessie a paid service though?

haggertd avatar Jan 26 '24 04:01 haggertd