From 6677ad7d15938c5c89bc3e450324f64d3a322df3 Mon Sep 17 00:00:00 2001 From: Matt Day Date: Thu, 28 May 2026 16:04:52 +0100 Subject: [PATCH 1/5] fix: add part 5 for longer access tokens --- docs/inverter-setup.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/inverter-setup.md b/docs/inverter-setup.md index 174e3e873..71a8ccd63 100644 --- a/docs/inverter-setup.md +++ b/docs/inverter-setup.md @@ -2427,6 +2427,11 @@ input_text: max: 255 mode: password + tesla_access_token_part5: + name: "Tesla Access Token - Part 5" + max: 255 + mode: password + tesla_energy_site_id: name: "Tesla Energy Site ID" unit_of_measurement: "" @@ -2469,7 +2474,12 @@ automation: target: entity_id: input_text.tesla_access_token_part4 data: - value: "{{ tesla_response.content.access_token[750:] }}" + value: "{{ tesla_response.content.access_token[750:1000] }}" + - service: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part5 + data: + value: "{{ tesla_response.content.access_token[1000:] }}" - service: input_text.set_value target: entity_id: input_text.tesla_refresh_token_part1 @@ -2555,7 +2565,8 @@ rest_command: Bearer {{ (states('input_text.tesla_access_token_part1') or '') + (states('input_text.tesla_access_token_part2') or '') + (states('input_text.tesla_access_token_part3') or '') + - (states('input_text.tesla_access_token_part4') or '') }} + (states('input_text.tesla_access_token_part4') or '') + + (states('input_text.tesla_access_token_part5') or '') }} tesla_api_get_current_tariff: url: "https://owner-api.teslamotors.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/tariff_rate" @@ -2565,7 +2576,8 @@ rest_command: Bearer {{ (states('input_text.tesla_access_token_part1') or '') + (states('input_text.tesla_access_token_part2') or '') + (states('input_text.tesla_access_token_part3') or '') + - (states('input_text.tesla_access_token_part4') or '') }} + (states('input_text.tesla_access_token_part4') or '') + + (states('input_text.tesla_access_token_part5') or '') }} tesla_api_set_export_now_tariff: url: "https://owner-api.teslamotors.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/time_of_use_settings" @@ -2575,7 +2587,8 @@ rest_command: Bearer {{ (states('input_text.tesla_access_token_part1') or '') + (states('input_text.tesla_access_token_part2') or '') + (states('input_text.tesla_access_token_part3') or '') + - (states('input_text.tesla_access_token_part4') or '') }} + (states('input_text.tesla_access_token_part4') or '') + + (states('input_text.tesla_access_token_part5') or '') }} Content-Type: application/json payload: > {% set now = now() %} @@ -2689,7 +2702,8 @@ rest_command: Bearer {{ (states('input_text.tesla_access_token_part1') or '') + (states('input_text.tesla_access_token_part2') or '') + (states('input_text.tesla_access_token_part3') or '') + - (states('input_text.tesla_access_token_part4') or '') }} + (states('input_text.tesla_access_token_part4') or '') + + (states('input_text.tesla_access_token_part5') or '') }} Content-Type: application/json payload: > { From f0ef4b7deebe35612f51ff8ee54de116824756a9 Mon Sep 17 00:00:00 2001 From: Matt Day Date: Thu, 28 May 2026 16:10:19 +0100 Subject: [PATCH 2/5] fix: remove inaccurate line on api key gen --- docs/inverter-setup.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/inverter-setup.md b/docs/inverter-setup.md index 71a8ccd63..02b3cea91 100644 --- a/docs/inverter-setup.md +++ b/docs/inverter-setup.md @@ -2438,7 +2438,9 @@ input_text: icon: mdi:lightning-bolt-outline ``` -- Use the [Access Token Generator for Tesla](https://chromewebstore.google.com/detail/access-token-generator-fo/djpjpanpjaimfjalnpkppkjiedmgpjpe?hl=en) to create a token +- Consult either the [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/authentication/third-party-tokens) or use the [Easy Tesla API Token Generator](https://www.myteslamate.com/tesla-token) to generate an access token. + + - This token needs to be copied, and then split into 4 parts (up to 255 characters long), so each part can be copied into the "refresh" input helpers From a53888d72bfbb643087ecd8ca93c716507101836 Mon Sep 17 00:00:00 2001 From: Matt Day Date: Thu, 28 May 2026 16:11:24 +0100 Subject: [PATCH 3/5] fix: remove broken API mechanism --- docs/inverter-setup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/inverter-setup.md b/docs/inverter-setup.md index 02b3cea91..327636bb3 100644 --- a/docs/inverter-setup.md +++ b/docs/inverter-setup.md @@ -2438,11 +2438,11 @@ input_text: icon: mdi:lightning-bolt-outline ``` -- Consult either the [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/authentication/third-party-tokens) or use the [Easy Tesla API Token Generator](https://www.myteslamate.com/tesla-token) to generate an access token. +- Consult either the [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/authentication/third-party-tokens) or use the [Easy Tesla API Token Generator](https://www.myteslamate.com/tesla-token) to generate an access + refresh token. -- This token needs to be copied, and then split into 4 parts (up to 255 characters long), so each part can be copied into the "refresh" input helpers +- This token needs to be copied, and then split into 4-5 parts (up to 255 characters long), so each part can be copied into the input helpers - An automation then uses the refresh token to generate an access token valid for 8 hours, and a new refresh token than is valid for ~30 days.
Create the following automation using the HA UI or by adding to `configuration.yaml`, the automation triggers an automatic refresh of the access token every 8 hours: From 1c86dde4fd1f32dd27f34470070a9c80e8d2eb6b Mon Sep 17 00:00:00 2001 From: Matt Day Date: Fri, 29 May 2026 23:10:17 +0100 Subject: [PATCH 4/5] fix: implement changes in #3965 --- docs/inverter-setup.md | 77 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/docs/inverter-setup.md b/docs/inverter-setup.md index 327636bb3..13efea454 100644 --- a/docs/inverter-setup.md +++ b/docs/inverter-setup.md @@ -2438,9 +2438,65 @@ input_text: icon: mdi:lightning-bolt-outline ``` -- Consult either the [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/authentication/third-party-tokens) or use the [Easy Tesla API Token Generator](https://www.myteslamate.com/tesla-token) to generate an access + refresh token. +You then need to obtain an access token for the API. There are two ways - either use the existing Fleet Integration if you have that setup, or manually obtain them. + +### Option 1: Tesla Fleet Integration (recommended) + +The Tesla Fleet integration already handles token exchanges for you. You can simply use this token for the REST API calls. - +Create a shell command to access the Tesla Fleet token: + +```yaml +shell_command: + get_tesla_fleet_token: >- + jq -r 'first(.data.entries[] | select(.domain == "tesla_fleet")) | .data.token.access_token' /config/.storage/core.config_entries +``` + +Now create an automation to populate the access token: + +```yaml +- id: refresh_tesla_access_token + alias: Refresh Tesla Access Token + description: Sync Tesla Fleet token from HA integration every hour + triggers: + - hours: /1 + trigger: time_pattern + - event: start + trigger: homeassistant + actions: + - action: shell_command.get_tesla_fleet_token + response_variable: token_response + - action: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part1 + data: + value: "{{ token_response.stdout[0:220] }}" + - action: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part2 + data: + value: "{{ token_response.stdout[220:440] }}" + - action: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part3 + data: + value: "{{ token_response.stdout[440:660] }}" + - action: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part4 + data: + value: "{{ token_response.stdout[660:880] }}" + - action: input_text.set_value + target: + entity_id: input_text.tesla_access_token_part5 + data: + value: "{{ token_response.stdout[880:] }}" + mode: single + ``` + +### Option 2: Another integration + +- Consult either the [Tesla Fleet API Documentation](https://developer.tesla.com/docs/fleet-api/authentication/third-party-tokens) or use the [Easy Tesla API Token Generator](https://www.myteslamate.com/tesla-token) to generate an access + refresh token. - This token needs to be copied, and then split into 4-5 parts (up to 255 characters long), so each part can be copied into the input helpers @@ -2514,8 +2570,11 @@ automation: notification_id: "tesla_token_update" ``` -- An automation executes every time HA starts and every midnight to populate the Tesla site id input_helper. - Create the following automation using the HA UI or by adding to `configuration.yaml`: +### Automations + +Whether using Fleet or another method, you will need to create a site ID automation. + +Create the following automation using the HA UI or by adding to `configuration.yaml`: ```yaml automation: @@ -2543,7 +2602,7 @@ automation: - tesla_api_set_export_now_tariff - sets a custom export rate tariff to force the Powerwall to export, - tesla_api_set_iog_custom_tariff - returns the Powerwall to the Octopus IOG tariff. Check the rates in the payload match your current tariff rates, or if you are on a different tariff, you will need to customise the REST payload to your tariff details - In `configuration.yaml` add the following lines: + In `configuration.yaml` add the following lines:F ```yaml rest_command: @@ -2560,7 +2619,7 @@ rest_command: (states('input_text.tesla_refresh_token_part5') or '') }}&scope=openid%20email%20offline_access" tesla_api_get_products: - url: "https://owner-api.teslamotors.com/api/1/products" + url: "https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/products" method: GET headers: Authorization: >- @@ -2571,7 +2630,7 @@ rest_command: (states('input_text.tesla_access_token_part5') or '') }} tesla_api_get_current_tariff: - url: "https://owner-api.teslamotors.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/tariff_rate" + url: "https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/tariff_rate" method: GET headers: Authorization: >- @@ -2582,7 +2641,7 @@ rest_command: (states('input_text.tesla_access_token_part5') or '') }} tesla_api_set_export_now_tariff: - url: "https://owner-api.teslamotors.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/time_of_use_settings" + url: "https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/time_of_use_settings" method: POST headers: Authorization: >- @@ -2697,7 +2756,7 @@ rest_command: } tesla_api_set_iog_custom_tariff: - url: "https://owner-api.teslamotors.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/time_of_use_settings" + url: "https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/energy_sites/{{ states('input_text.tesla_energy_site_id') }}/time_of_use_settings" method: POST headers: Authorization: >- From eb78079fdfa24036dc22e305ca17237d12c941b1 Mon Sep 17 00:00:00 2001 From: Matt Day Date: Fri, 29 May 2026 23:17:07 +0100 Subject: [PATCH 5/5] fix: trailing F --- docs/inverter-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/inverter-setup.md b/docs/inverter-setup.md index 13efea454..c589b1ccf 100644 --- a/docs/inverter-setup.md +++ b/docs/inverter-setup.md @@ -2602,7 +2602,7 @@ automation: - tesla_api_set_export_now_tariff - sets a custom export rate tariff to force the Powerwall to export, - tesla_api_set_iog_custom_tariff - returns the Powerwall to the Octopus IOG tariff. Check the rates in the payload match your current tariff rates, or if you are on a different tariff, you will need to customise the REST payload to your tariff details - In `configuration.yaml` add the following lines:F + In `configuration.yaml` add the following lines: ```yaml rest_command: