{"id":7218,"date":"2026-03-21T16:00:00","date_gmt":"2026-03-21T16:00:00","guid":{"rendered":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=7218"},"modified":"2026-03-21T16:30:25","modified_gmt":"2026-03-21T16:30:25","slug":"tesla-fleet-api-integration","status":"publish","type":"page","link":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=7218","title":{"rendered":"Tesla Fleet API integration"},"content":{"rendered":"\n<p>I first tried to configure the Tesla Fleet API integration for Home Assistant as soon as the Tesla PowerWall 3 installation was commissioned, but it kept failing &#8211; without reporting any meaningful error message. Now that integration is (even) more important, as a fundamental pre-requisite for Predbat, and now I&#8217;m a little more familiar with where Home Assistant writes its log messages, it&#8217;s time to try again.<\/p>\n\n\n\n<p>The instructions for configuring the Tesla Fleet API integration for Home Assistant are <a href=\"https:\/\/www.home-assistant.io\/integrations\/tesla_fleet\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> and they make perfect sense &#8211; they&#8217;re very similar to how other OAuth-based integrations work. The process fails at the step after agreeing to link the Tesla account to Home Assistant:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"292\" src=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2026\/03\/Screenshot-2026-03-21-at-15.17.14.png\" alt=\"\" class=\"wp-image-7219\" srcset=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2026\/03\/Screenshot-2026-03-21-at-15.17.14.png 703w, https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2026\/03\/Screenshot-2026-03-21-at-15.17.14-300x125.png 300w, https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2026\/03\/Screenshot-2026-03-21-at-15.17.14-500x208.png 500w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/figure>\n\n\n\n<p>There&#8217;s a popup window which briefly shows &#8220;Loading next step for Tesla Fleet API&#8221; &#8211; but then there&#8217;s another window which is simply headed &#8220;Error&#8221; (with an OK button).<\/p>\n\n\n\n<p>Looking at System > Logs shows a log message labelled <code>Error handling request from 172.16.115.203<\/code> and the lines at the end of the detailed error log show:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>File \"\/usr\/src\/homeassistant\/homeassistant\/components\/tesla_fleet\/config_flow.py\", line 87, in async_oauth_create_entry\n    await api.partner_login(\n        implementation.client_id, implementation.client_secret\n    )\n  File \"\/usr\/local\/lib\/python3.14\/site-packages\/tesla_fleet_api\/tesla\/fleet.py\", line 219, in partner_login\n    raise ValueError(f\"Partner login failed: {error_data}\")\nValueError: Partner login failed: {'error': 'invalid_scope', 'error_description': '<mark style=\"background-color:#ffff00\" class=\"has-inline-color\">The requested scopes are not granted.<\/mark>'}<\/code><\/pre>\n\n\n\n<p>So it would seem the code is asking for OAuth &#8216;scopes&#8217; which are not granted by the &#8216;Application&#8217; entry configured against the Tesla Fleet API for the Home Assistant integration &#8211; although all of the &#8216;scopes&#8217; noted as being Mandatory in the documentation are in place. Time to look at the code, I guess&#8230;<\/p>\n\n\n\n<p>Looking first at <code><a href=\"https:\/\/github.com\/home-assistant\/core\/blob\/dev\/homeassistant\/components\/tesla_fleet\/config_flow.py\" target=\"_blank\" rel=\"noreferrer noopener\">config_flow.py<\/a><\/code> (which is part of the Home Assistant integration codebase) line 87 does indeed call api.partner_login() &#8211; but that is implemented in a separate Python package called <code><a href=\"https:\/\/github.com\/Teslemetry\/python-tesla-fleet-api\/tree\/main\" target=\"_blank\" rel=\"noreferrer noopener\">tesla_fleet_api<\/a><\/code> which appears to be Teslemetry&#8217;s Python package. File <code><a href=\"https:\/\/github.com\/Teslemetry\/python-tesla-fleet-api\/blob\/main\/tesla_fleet_api\/tesla\/fleet.py\" target=\"_blank\" rel=\"noreferrer noopener\">fleet.py<\/a><\/code> implements <code>api.partner_login()<\/code> starting at line 188. Line 192 says:<\/p>\n\n\n\n<p><code>scopes: list[Scope] = [Scope.VEHICLE_DEVICE_DATA],<\/code> <\/p>\n\n\n\n<p>and some later code looks like it appends a list of specifically-requested scopes. Looking back at <code>config_flow.py<\/code> that includes the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>                partner_scope=True,\n                charging_scope=False,\n                energy_scope=False,\n                user_scope=False,\n                vehicle_scope=False,<\/code><\/pre>\n\n\n\n<p>which <em>appears<\/em> to be an attempt to say only the &#8216;partner&#8217; scope is required, maybe &#8211; but that isn&#8217;t working?<\/p>\n\n\n\n<p>Adding the &#8220;Vehicle Information&#8221; scope to the Home Assistant &#8216;application&#8217; entry on the Tesla developer portal made everything work OK. Presumably they assume everyone using Telemetry will have a Tesla vehicle. While this scope shouldn&#8217;t strictly be necessary, it doesn&#8217;t really hurt to add it (especially since my Tesla account is never going to have any Vehicles included).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I first tried to configure the Tesla Fleet API integration for Home Assistant as soon as the Tesla PowerWall 3 installation was commissioned, but it kept failing &#8211; without reporting any meaningful error message. Now that integration is (even) more &hellip; <a href=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=7218\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":7215,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7218","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/7218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7218"}],"version-history":[{"count":4,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/7218\/revisions"}],"predecessor-version":[{"id":7223,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/7218\/revisions\/7223"}],"up":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/7215"}],"wp:attachment":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}