Tesla Integration not Working since 1/30/21

My Tesla Integration was working fine till today, when I updated home assistant Core; I now get the invalid credentials error

Same. Stopped working with latest Core update. “Invalid Authentication”

Restored 2021.7.4 snapshot, still not working - so I’m assuming it’s an external issue.

not working in 8.2

Updated solution for Aug 6 2021

The Tesla login is really finicky. I was able to get it working via the default interface, but after I changed my password (to invalidate some other apps that I didn’t want to use), it broke and trying to login with the new password resulted in “Invalid credentials”. I tried rebooting and clearing HA and it still didn’t work. I suspect the tokens are cached somewhere. This happened with v2021.8.2 of HA.

What did work is a modification of @Cody_Frolander 's suggested solution, as follows:

  1. Download the “Auth for Tesla” app on iOS. Open the app and get your refresh and access tokens.
  2. Download the latest source code of HomeAssistant onto your local computer.
  3. Navigate to homeassistant/components/tesla.
  4. Open config_flow.py in your favorite text/programming editor.
  5. Modify the validate_input method as follows:
async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """

    config = {}
    async_client = httpx.AsyncClient(headers={USER_AGENT: SERVER_SOFTWARE}, timeout=60)

    try:
        # controller = TeslaAPI(
        #     async_client,
        #     email=data[CONF_USERNAME],
        #     password=data[CONF_PASSWORD],
        #     update_interval=DEFAULT_SCAN_INTERVAL,
        # )
        # result = await controller.connect(
        #     test_login=True, mfa_code=(data[CONF_MFA] if CONF_MFA in data else "")
        # )
        config[CONF_TOKEN] = "Refresh Token from Auth for Tesla"
        config[CONF_ACCESS_TOKEN] = "Access Token from Auth for Tesla"
        config[CONF_EXPIRATION] = 1625180411000 
        config[CONF_USERNAME] = "No user"
        config[CONF_PASSWORD] = "No password"

The commented-out portions are the new changes I added. If you do not add those, the connection will fail and you will still get an “Invalid credentials” error.

You will also need to open the manifest.json file and add

  "iot_class": "cloud_polling",
  "version": "2018.8.6"
}

at the end. This is because the new versions of HA require version to be specified for custom_integrations. I also find it helpful to change the name of the integration to something like “Tesla custom”.

  1. Copy the tesla folder to your custom_components folder.
  2. Reboot HA. Wait a few mins for everything to be loaded. Add Intergration. Enter any email or password. And you should be done!
4 Likes

Thanks @shyuep, this works. Will the refresh token last forever? Is it only the access token that expires? If so, this is good enough to keep working for a while.

Seems like the root problem lies with teslajsonpy not coping with Tesla’s auth process anymore. If this gets fixed, then the integration as checked into git should start working again.

This issue seems to be fixed by core 2021.8.4:

Without knowing exactly, I’m assuming is has somesting to do with ‘Update const.py’ as this ‘const.py’ is mentioned in the ‘config_flow.py’ from the Tesla component:

from homeassistant import config_entries, core, exceptions
from homeassistant.const import (
    CONF_ACCESS_TOKEN,
    CONF_PASSWORD,
    CONF_SCAN_INTERVAL,
    CONF_TOKEN,
    CONF_USERNAME,
    HTTP_UNAUTHORIZED,

BR Søren

1 Like

Sadly 2021.8.4 did not fix me. Things I’ve learned from reading for hours about the issue:

  • It’s a server side problem (Tesla API side)
  • The error manifests itself in not being able to authenticate.

My best guess is that Tesla API is presenting a Captcha or similar challenge that the current Tesla integration cannot quite handle so it fails. This would explain why sometimes people retry and it works (Tesla API did not present the challenge for some reason, some because the password was just changed or something).

From the unofficial API site:

Tesla’s SSO service has a WAF (web application firewall) that may temporarily block you if you make repeated, execessive requests. This is to prevent bots from attacking the service, either as a brute force or denial-of-service attack. This normally presents as a “challenge” page, which requires running some non-trivial JavaScript code to validate that you have a full browser engine available. While you can potentially fully evaluate this page to remove the block, the best practice for now is to reduce your calls to the SSO service to a minimum and avoid things like automatic request retries.

For now, some of the things I’ve seen work are:

  • You get lucky and you get no challenge so you auth successfully
  • You get a new API key yourself and change your .storage file.
  • You use custom repos or custom code like @shyuep 's post above

Ofc, hoping we can figure out a place to solve this for everyone in a more robust way

I posted a PR that fixed it in a robust way with a proxy months ago when this first popped up. It was rejected because of the supposed risk that someone with edit access to Tesla’s login page could theoretically hack HA instances. So the only remaining robust option is that Tesla offers a third-party oauth to developers instead of relying on us to hack the login.

I broke out the fix into a custom component on HACS but I have no intention of fixing core’s login issues since I specifically didn’t want to deal with it breaking every-time Tesla changed the login method page. (e.g., captcha, MFA, push).

2 Likes

The issue I have and not sure if it’s common to everyone else.

It was working fine then stopped working early August 2021 which I presume is related to the access token expiry period.

I’ve removed the app and tried to re-install however when I type in the login credentials it prompts invalid configuration.

I then proceeded to navigate to homeassistant/components/tesla folder as mentioned in the posts above, however can’t find this folder. (Using a Pi with Samba)

I plead with anyone who can help as I had all sorts of wizzy automations and dashboards created with the Tesla intergration, it was a thing of beauty!

I’m stuggling to get this working after upgrading yesterday.

I’ve edited the config_flow.py file, and the commented out changes above are now include in the core code, so I didn’t need to add these.

I updated the config section as below:

config[CONF_TOKEN] = "My Refresh Token here, inside the speech marks"
        config[CONF_ACCESS_TOKEN] = "My Access Token here, inside the speech marks"
        config[CONF_EXPIRATION] = 1625180411000 
        config[CONF_USERNAME] = "No user"
        config[CONF_PASSWORD] = "No password"

I also added the "version’ line into the mainfest.json (the iot_class was there) and changed the name to Tesla_custom then restarted HA but I’m not seeing the integration in HACS

Pretty new to this, so might be making a schoolboy error! Any ideas? Thanks

I have the exact same issue. Trying to get it back and running and no luck

Same issue with me after last 2 updates .2021-08-09

@shallax I think the refresh token should last a good long while. Of course, you might need to update it once in a while (months most likely). There are several third-party apps that allow the use of refresh tokens. Hopefully the official integration gets fixed in the meantime.

@adrianwi I am at the latest HA version and it works for me. Perhaps it might be useful to rename the directory and name of the integration to something like tesla_custom just to avoid conflict with the default integration.

Any updates on this? Would love to get Tesla integration working again :slight_smile:

1 Like

The custom component works

@shyuep thanks for the reply. I’m still struggling to get this working, but I’m sure it’s just something I’m doing wrong. I get the custom integration displaying as it has the name I used, and it’s also missing the field names on the user/password entry pop-up, but whatever I enter (genuine username/password or made up) it doesn’t connect. I’m pretty sure i’ve copied and pasted the codes from the AuthAppForTesla correctly, so not sure what else to try.

Not the end of the world, as I’m still playing with HA, but it was nice to have the Tesla info available there too. Hopefully there can be a more permanent solution, along the lines of the other 3rd party apps?

Yeah I’m following the instructions too with the custom, it isn’t working for me either sadly. Hopefully someone can robustly fix this. Just a shame this is such a volatile integration.

2 Likes

same problem here, please fix! “Invalid authentication”

Same problem here :face_with_head_bandage:. i tried to uninstalled the tesla integration, rebooted HA, new installation of tesla integration —> invalid authentication.

Created a new tesla account —> invalid authentication.