Tesla Integration not Working since 1/30/21

same here.

1 Like

I took a quick look and the integration is using teslajsonpy 0.11.5, I updated it to 0.18.0 and still doesnt work. I think the underlaying teslajsonpy is the issue.
I have an integration that changes mode in the powerwall and also has to go through the public API. It uses teslapy 1.1.0 and it works.
Changing the integration to use teslapy will be a big change… I think we need to figure out why teslajsonpy doesnt work and can use teslapy as reference.

The callstack when using 0.18.0 is:

File "/config/custom_components/tesla/config_flow.py", line 57, in async_step_user
info = await validate_input(self.hass, user_input)
File "/config/custom_components/tesla/config_flow.py", line 159, in validate_input
(config[CONF_TOKEN], config[CONF_ACCESS_TOKEN]) = await controller.connect(
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 288, in connect
cars = await self.get_vehicles()
File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 407, in get_vehicles
return (await self.__connection.get("vehicles"))["response"]
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 90, in get
return await self.post(command, "get", None)
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 112, in post
self.code = await self.get_authorization_code(
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 405, in get_authorization_code
html = await resp.text()
TypeError: 'str' object is not callable

Fixed in 2021.5.0 for me.

1 Like

+1 for 2021.5.0

Yippee! Me too.

Works! Fixed in 2021.5.0

Today I upgraded to 2021.5.2 from 2021.5.0 and the Tesla integration is working again. (It did not work in 2021.5.0 for me under HASS.IO NUC image.

Justin.

Not working for me in 2021.5.5. Getting the following in the logs:

[homeassistant.components.tesla.config_flow] Authentication error: Unable to login with credentials

Triple checked that my email address and password are correct. MFA is not enabled.

1 Like

same here getting errors son 2021.5.5

there’s a captcha on the tesla.com web login, is that new?

Seems like the captcha is new. I’ve never seen it before.

On 2021.5.5, it’s not working for me either.

Setup failed for tesla: Integration failed to initialize.
Authentication error: Unable to login with credentials

I can’t set up the integration either. Same error as others “Authentication error: Unable to login with credentials”.

I’ve tried both my normal account with 2FA disabled, and a new “fresh” account that never had 2FA. I tried both the latest container and OS on my Pi (2021.5.5). I think captcha is the problem, too.

Are there any plans to move to using OAUTH tokens instead of username/password?

This integration does not work for me either, and I think I know why:

Most apps that access your Tesla now do not use your login information - they use your Tesla Refresh token. This can be generated by a free app on the iOS App Store and I’m sure there is some other ways to do it - iOS app store app I used to get my Teslascope and Bestla app configured to access and control stuff on my tesla: ‎Auth app for Tesla on the App Store.

Probably there is a way to switch the authentication on this integration to do the same thing.

“On January 29th, Tesla finalized the transition to their new OAuth authentication system and deprecated legacy endpoints used by third-party services for generating and refreshing tokens.”

Here is the source code for the Auth App mentioned above: GitHub - TeslaBuds/AuthAppForTesla

Maybe someone with the right skills can update the integration to use authentication tokens

So I’m running into the same issue, I dug into the source a little bit and jammed my v3 token (the new ones Tesla is requiring) in directly bypassing the username/password. It worked perfect finally, so the fix isn’t too hard. If nobody else is working on a fix I can probably come up with a patch so you can just put in your token in the next day or two. I maybe able to fix the username/password issue too, but I’d need to dig into the library they are using for tesla authentication and I don’t really know anything about it at the moment so I’ll look into that.

Did you “jam in your v3 token” by manually editing the config file? Could you suggest some basic steps?

In your config folder, create /custom_components/tesla directory and mirror the original tesla component source from here: core/homeassistant/components/tesla at a59460a23336627d0bc12b1eefffdaa516e55e87 · home-assistant/core · GitHub

Then modify the validate_input function of config_flow.py to read as follows (putting your token and refresh token in):

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,
        )
        config[CONF_TOKEN] = "YOUR_REFRESH_TOKEN"
        config[CONF_ACCESS_TOKEN] = "YOUR_TOKEN"
        config[CONF_EXPIRATION] = 1625180411000 # your expiry here but no quotes
        config[CONF_USERNAME] = "No Username"
        config[CONF_PASSWORD] = "No Password"
    except IncompleteCredentials as ex:
        _LOGGER.error("Authentication error: %s %s", ex.message, ex)
        raise InvalidAuth() from ex
    except TeslaException as ex:
        if ex.code == HTTP_UNAUTHORIZED:
            _LOGGER.error("Invalid credentials: %s", ex)
            raise InvalidAuth() from ex
        _LOGGER.error("Unable to communicate with Tesla API: %s", ex)
        raise CannotConnect() from ex
    return config

When the new integration shows up, just put anything in for the username and password and it should be successful. This will override the built in tesla integration and it’s a dirty fix with baked in credentials that you shouldn’t use, but it works in a pinch. To remove it and revert, you can just delete the ‘tesla’ folder from your ‘custom_components’ directory.

Today, interestingly, my Tesla integration is working again, without me doing anything.

Moving to tokens is the Right Thing to Do, though, in the long run.
Not technically difficult, but I’m afraid I’m a bit swamped at the moment or I’d volunteer.

Hi Cody-

I implemented your recommendation, and cycled HA but am still getting an invalid credentials error. I used the Tesla auth app to generate the tokens, which I assume was correct?