Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polling and commands fail due to Error 429 - Too Many Requests - Tesla rate limiting #961

Open
2 tasks done
r4nd0mbr1ck opened this issue May 9, 2024 · 66 comments
Open
2 tasks done
Labels
car For items that relate to Tesla vehicles enhancement New feature or request help wanted Extra attention is needed triage New issues raised that need initial attention

Comments

@r4nd0mbr1ck
Copy link

r4nd0mbr1ck commented May 9, 2024

Is there an existing issue for this?

  • I have searched both the existing open issues & recently closed issues and did not find a duplicate of this issue.

I have read about the Fleet API and understand I may need to use it

  • I understand issues relating to read only commands will be auto closed if not using the Fleet API.

Version of the Tesla component

3.21.0

Version of the Tesla car software

2024.14.3

Model

Model Y

Current Behavior

I setup the Fleet API via Tesla HTTP Proxy add-on a few days back. The custom integration was working at that point and I could see vehicle status and also issue commands. Today, commands stopped working but stats get updated. The integration been throwing a range of errors. Initially it was throwing UnknownException and since then I have deleted the integration, generated new Refresh Token in Tesla HTTP Proxy and set it up again. See latest log here https://pastebin.com/3R0s2Wcr - this starts from custom integration setup and until includes issue of one command.

Expected Behavior

Commands should work

Debug logs

2024-05-09 17:40:27.467 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Running in supervised environment
2024-05-09 17:40:27.499 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Found addon: c0<REDACTED>_tesla_http_proxy
2024-05-09 17:40:41.224 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Credentials successfully connected to the Tesla API
2024-05-09 17:40:41.227 DEBUG (MainThread) [custom_components.tesla_custom] Trusting CA: {'subject': ((('countryName', 'TR'),), (('localityName', 'Gebze - Kocaeli'),), (('organizationName', 'Turkiye Bilimsel ve Teknolojik Arastirma Kurumu - TUBITAK'),), (('organizationalUnitName', 'Kamu Sertifikasyon Merkezi - Kamu SM'),), (('commonName', 'TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1'),)), 'issuer': ((('countryName', 'TR'),), (('localityName', 'Gebze - Kocaeli'),), (('organizationName', 'Turkiye Bilimsel ve Teknolojik Arastirma Kurumu - TUBITAK'),), (('organizationalUnitName', 'Kamu Sertifikasyon Merkezi - Kamu SM'),), (('commonName', 'TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1'),)), 'version': 3, 'serialNumber': '01', 'notBefore': 'Nov 25 08:25:55 2013 GMT', 'notAfter': 'Oct 25 08:25:55 2043 GMT'}
2024-05-09 17:40:41.242 DEBUG (MainThread) [teslajsonpy.controller] 552 endpoints loaded
2024-05-09 17:40:41.242 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19853 days, 6:19:19
2024-05-09 17:40:41.242 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-05-09 17:40:41.242 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-05-09 17:40:42.061 DEBUG (MainThread) [teslajsonpy.connection] Saved new auth info {'access_token': '<REDACTED>', 'refresh_token': '<REDACTED>', 'expires_in': 1715305241}
2024-05-09 17:40:42.061 DEBUG (MainThread) [teslajsonpy.connection] Successfully refreshed oauth
2024-05-09 17:40:42.061 DEBUG (MainThread) [teslajsonpy.connection] get: https://c0<REDACTED>-tesla-http-proxy/api/1/products {}
2024-05-09 17:40:42.867 DEBUG (MainThread) [teslajsonpy.connection] 200: {"response":[{"id":<REDACTED>,"user_id":<REDACTED>,"vehicle_id":<REDACTED>,"vin":"<REDACTED_VIN>","color":null,"access_type":"OWNER","display_name":"shadowfax","option_codes":null,"cached_data":"EicKAgoAEgISABoCIgAqAhIAOgwIq/vxsQYQgKeEmwPABgDQBgDgBgAatwEKAhIA+gEGCJDBybAGmgICGgDiAgwIq/vxsQYQgKeEmwPqAgIKAPICAgoA8gkICgIKABIAGgDABmTIBlDQBjLYBmToBgHwBgD9BihNSkOFB5K8KUONByhNSkOQB06YB06lB6eliT6tBwAAgD+1BwAAg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H45j/3ZB/k0v97Z0jjJRA136kyxPvAcesu/DjcUewNW6bC/9NrUvHvGwZVubEyKXOiuBWEjhpyEvH3bgYMFO+4Fjf5oNvA055+WquCKQbxXsbV6mVR5G+FBGkro6Of5yrLvTrN0Ni/JRoLCLH8lLIGEMDU4kwiDAjQyI2tBhCAu8KVAqI4ngQSgAQ5mjsshBAUpHXc91MFp/qPki0hfOxC2t0uhqptUwZfzSLA4mWjO+kKjvaRwoDzZ4FU0rXD4e49+61bRithGmOsW3csnwTFlZrXKrM0suSnAcD5C0e1VlOlUoeGxQ+1Si7TSkrrJ5d1XSFan5aVDNN3bYWD69LYH3a07IKBThA1ZmDH+wQA6zW+g5YkyRN9mDshEBqb4ORK/Cu6SRz4oSne0mzj6MPF3ui/2CSthsEdyNLGYLF23axUsIcDinIgMQhQhgjxm3sSZUSopmXCJt0DR0m8dMYh7m3tvtgUFUqgGg7m+C/SyOeyuKWOIJ58KuW/entWSNfNVDmcSwSzE3nsW/Gapj8IGR7q0KrmLezdwTc6XaBtHWeFeQbnwxzSlwY66VREBJNAnAYUtkdygEwDTGpPU+VfLlnZZJIv+vkAUc6qFbbxBNyK38h7aQPyxBMzXxU3+/RTg+WXgtsER0+l/nVqvxjyrrynX/MLyg5BXqZNGJ46ost78msG426d/E3Qgd358W2M/NXcUGJ5ij8lsS0TMNM7EocJWQ/zCREA2Xy3bBxCFgjfg2tfBFiG+Vhu2fgw24gKbwZyJN19aYWEiNlmSUZorT0Sa2EBAc2Ql+LOaq5qwNJEA1GqKpo/XYlMFPW9a0I/TriZkVqR6u8VQM6YgQHEUIWq4WKo//9lThoLCLH8lLIGEMDU4kwiDAj/5futBhCAk6uyAbg+AQ==","granular_access":{"hide_private":false},"tokens":["a93e355b1a27cf80","ea98435367380ffe"],"state":"offline","in_service":false,"id_s":"<REDACTED>","calendar_enabled":true,"api_version":76,"backseat_token":null,"backseat_token_updated_at":null,"ble_autopair_enrolled":false,"command_signing":"required","release_notes_supported":true}],"count":1}
2024-05-09 17:40:42.867 DEBUG (MainThread) [teslajsonpy.controller] 47947: Changing car_online from {} to False
2024-05-09 17:40:42.867 DEBUG (MainThread) [teslajsonpy.controller] 47947: Resetting last_parked_timestamp to: 1715240441 shift_state None
2024-05-09 17:40:42.867 DEBUG (MainThread) [teslajsonpy.controller] 47947: Sending wake request with deadline of: 1715240502
2024-05-09 17:40:42.867 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 8:00:00
2024-05-09 17:40:42.868 DEBUG (MainThread) [teslajsonpy.connection] post: https://c0<REDACTED>-tesla-http-proxy/api/1/vehicles/<REDACTED_VIN>/wake_up {}
2024-05-09 17:40:43.072 DEBUG (MainThread) [teslajsonpy.connection] 429: Retry later

2024-05-09 17:40:43.072 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during setup, car will still be added. 429: TOO_MANY_REQUESTS
2024-05-09 17:40:43.073 INFO (MainThread) [custom_components.tesla_custom.teslamate] Un-subbing from all MQTT Topics.
2024-05-09 17:40:43.073 INFO (MainThread) [custom_components.tesla_custom.teslamate] Un-subbed from all MQTT Topics.
2024-05-09 17:40:43.073 DEBUG (MainThread) [custom_components.tesla_custom] Connected to the Tesla API
2024-05-09 17:40:43.073 DEBUG (MainThread) [custom_components.tesla_custom] Saving new tokens in config_entry
2024-05-09 17:40:43.073 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:40:43.074 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 2 Interval 60
2024-05-09 17:40:43.074 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240443 ago. Last parked: 2 ago. Last wake up 1715240443 ago. 
2024-05-09 17:40:43.074 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:40:43.099 DEBUG (MainThread) [custom_components.tesla_custom.teslamate] Got car ID. VIN:<REDACTED_VIN> TeslamateID: None
2024-05-09 17:40:53.076 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:40:53.076 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 12 Interval 60
2024-05-09 17:40:53.076 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240453 ago. Last parked: 12 ago. Last wake up 1715240453 ago. 
2024-05-09 17:40:53.076 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:40:53.122 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:40:53.123 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 12 Interval 60
2024-05-09 17:40:53.123 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:03.122 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:03.122 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 22 Interval 60
2024-05-09 17:41:03.122 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:03.298 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:03.298 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 22 Interval 60
2024-05-09 17:41:03.298 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240463 ago. Last parked: 22 ago. Last wake up 1715240463 ago. 
2024-05-09 17:41:03.298 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:13.122 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:13.122 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 32 Interval 60
2024-05-09 17:41:13.122 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:13.296 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:13.296 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 32 Interval 60
2024-05-09 17:41:13.296 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240473 ago. Last parked: 32 ago. Last wake up 1715240473 ago. 
2024-05-09 17:41:13.296 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:23.124 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:23.124 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 42 Interval 60
2024-05-09 17:41:23.124 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:23.297 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:23.297 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 42 Interval 60
2024-05-09 17:41:23.297 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240483 ago. Last parked: 42 ago. Last wake up 1715240483 ago. 
2024-05-09 17:41:23.297 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:33.121 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:33.122 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 52 Interval 60
2024-05-09 17:41:33.122 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:33.296 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:33.296 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 52 Interval 60
2024-05-09 17:41:33.296 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240493 ago. Last parked: 52 ago. Last wake up 1715240493 ago. 
2024-05-09 17:41:33.296 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:43.123 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:43.123 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 62 Interval 60
2024-05-09 17:41:43.123 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:58:59
2024-05-09 17:41:43.123 DEBUG (MainThread) [teslajsonpy.connection] get: https://c0<REDACTED>-tesla-http-proxy/api/1/products {}
2024-05-09 17:41:43.296 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:43.404 DEBUG (MainThread) [teslajsonpy.connection] 200: {"response":[{"id":<REDACTED>,"user_id":<REDACTED>,"vehicle_id":<REDACTED>,"vin":"<REDACTED_VIN>","color":null,"access_type":"OWNER","display_name":"shadowfax","option_codes":null,"cached_data":"EicKAgoAEgISABoCIgAqAhIAOgwIq/vxsQYQgKeEmwPABgDQBgDgBgAatwEKAhIA+gEGCJDBybAGmgICGgDiAgwIq/vxsQYQgKeEmwPqAgIKAPICAgoA8gkICgIKABIAGgDABmTIBlDQBjLYBmToBgHwBgD9BihNSkOFB5K8KUONByhNSkOQB06YB06lB6eliT6tBwAAgD+1BwAAgD+4BwLABxDIBwDQBwDoBwDwBwD4BwCQCACoCAHACADICBDQCBCYCZELoAkAqAkQuAn0CMAJAMgJ6ALQCQDlCQAAAAD4CQAilwHyAQIKAIoCDAir+/GxBhCAp4SbA5oCAgoArQZnZqJBtQYAAIRBvQYAAKBBxQYAAKBByAYA0AYA2AYA4AYA6AYA8AYA/QYAAHBBhQcAAOBBiAcAkAcAmAcAoAcAqAcA0AcA6AcA8AcA+AcAgAgAiA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Z4FU0rXD4e49+61bRithGmOsW3csnwTFlZrXKrM0suSnAcD5C0e1VlOlUoeGxQ+1Si7TSkrrJ5d1XSFan5aVDNN3bYWD69LYH3a07IKBThA1ZmDH+wQA6zW+g5YkyRN9mDshEBqb4ORK/Cu6SRz4oSne0mzj6MPF3ui/2CSthsEdyNLGYLF23axUsIcDinIgMQhQhgjxm3sSZUSopmXCJt0DR0m8dMYh7m3tvtgUFUqgGg7m+C/SyOeyuKWOIJ58KuW/entWSNfNVDmcSwSzE3nsW/Gapj8IGR7q0KrmLezdwTc6XaBtHWeFeQbnwxzSlwY66VREBJNAnAYUtkdygEwDTGpPU+VfLlnZZJIv+vkAUc6qFbbxBNyK38h7aQPyxBMzXxU3+/RTg+WXgtsER0+l/nVqvxjyrrynX/MLyg5BXqZNGJ46ost78msG426d/E3Qgd358W2M/NXcUGJ5ij8lsS0TMNM7EocJWQ/zCREA2Xy3bBxCFgjfg2tfBFiG+Vhu2fgw24gKbwZyJN19aYWEiNlmSUZorT0Sa2EBAc2Ql+LOaq5qwNJEA1GqKpo/XYlMFPW9a0I/TriZkVqR6u8VQM6YgQHEUIWq4WKo//9lThoLCLH8lLIGEMDU4kwiDAj/5futBhCAk6uyAbg+AQ==","granular_access":{"hide_private":false},"tokens":["a93e355b1a27cf80","ea98435367380ffe"],"state":"offline","in_service":false,"id_s":"<REDACTED>","calendar_enabled":true,"api_version":76,"backseat_token":null,"backseat_token_updated_at":null,"ble_autopair_enrolled":false,"command_signing":"required","release_notes_supported":true}],"count":1}
2024-05-09 17:41:43.405 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.282 seconds (success: True)
2024-05-09 17:41:43.405 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 0 Interval 60
2024-05-09 17:41:43.405 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240503 ago. Last parked: 62 ago. Last wake up 1715240503 ago. 
2024-05-09 17:41:43.405 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.108 seconds (success: True)
2024-05-09 17:41:45.830 DEBUG (MainThread) [teslajsonpy.controller] 47947: Sending wake request with deadline of: 1715240565
2024-05-09 17:41:45.830 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:58:57
2024-05-09 17:41:45.830 DEBUG (MainThread) [teslajsonpy.connection] post: https://c0<REDACTED>-tesla-http-proxy/api/1/vehicles/<REDACTED_VIN>/wake_up {}
2024-05-09 17:41:46.039 DEBUG (MainThread) [teslajsonpy.connection] 429: Retry later

2024-05-09 17:41:46.039 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140353510598976] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 134, in _async_press_action
    await self.async_press()
  File "/config/custom_components/tesla_custom/button.py", line 68, in async_press
    await self._car.wake_up()
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/car.py", line 1130, in wake_up
    await self._controller.wake_up(car_id=self.id)
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/controller.py", line 475, in wake_up
    result = await self.api(
             ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/controller.py", line 1375, in api
    return await self.__post_with_retries_except_unavailable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/_asyncio.py", line 88, in async_wrapped
    return await fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/_asyncio.py", line 47, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/__init__.py", line 314, in iter
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.12/site-packages/tenacity/_asyncio.py", line 50, in __call__
    result = await fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/controller.py", line 1407, in __post_with_retries_except_unavailable
    return await self.__connection.post(command, method=method, data=data, url=url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/connection.py", line 166, in post
    return await self.__open(url, method=method, headers=self.head, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/teslajsonpy/connection.py", line 218, in __open
    raise TeslaException(resp.status_code)
teslajsonpy.exceptions.TeslaException
2024-05-09 17:41:53.122 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:53.122 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 10 Interval 60
2024-05-09 17:41:53.122 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:41:53.297 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:41:53.297 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 10 Interval 60
2024-05-09 17:41:53.297 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240513 ago. Last parked: 72 ago. Last wake up 1715240513 ago. 
2024-05-09 17:41:53.297 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:42:03.121 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:42:03.122 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 20 Interval 60
2024-05-09 17:42:03.122 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)
2024-05-09 17:42:03.297 DEBUG (MainThread) [custom_components.tesla_custom] Running controller.update()
2024-05-09 17:42:03.298 DEBUG (MainThread) [teslajsonpy.controller] Get vehicles. Force: False Time: 20 Interval 60
2024-05-09 17:42:03.298 DEBUG (MainThread) [teslajsonpy.controller] 47947: Skipping update with state offline. Polling: True. Last update: 1715240523 ago. Last parked: 82 ago. Last wake up 1715240523 ago. 
2024-05-09 17:42:03.298 DEBUG (MainThread) [custom_components.tesla_custom] Finished fetching tesla_custom data in 0.000 seconds (success: True)

Anything else?

I can see Running controller.update() in the logs every 10 seconds or so. Not sure if that has any implications. Polling is at the default 660 seconds.

@r4nd0mbr1ck r4nd0mbr1ck added car For items that relate to Tesla vehicles triage New issues raised that need initial attention labels May 9, 2024
@rileymd88
Copy link

I also received the same 429 error today. It looks like Tesla are starting to implement the rate limits which have been public for a while:
https://developer.tesla.com/docs/fleet-api#membership-tiers

According to the API response header Retry-After I have been rate limited for 24 hours :|

@rileymd88 rileymd88 mentioned this issue May 9, 2024
2 tasks
@r4nd0mbr1ck
Copy link
Author

Yikes! 50 commands per day? There goes my automation for excess solar charging.

@alandtse alandtse added enhancement New feature or request help wanted Extra attention is needed labels May 10, 2024
@alandtse alandtse changed the title Executing commands (wake up, set charge limit, HVAC, etc) throws errors Polling and commands fail due to Error 429 - Too Many Requests - Tesla rate limiting May 10, 2024
@alandtse
Copy link
Owner

Short term, we need a PR to identify the time period specified in Retry-After and possibly delay polling until that point. We also would need to decide if we just queue the pending command, or just fail immediately with the error.

The issue is a user really needs to do something at this point if they are getting rate limited as it's unclear if Tesla will do anything negative, including ban users who continue to try to do things while rate limited.

@peter-funktionIT
Copy link

peter-funktionIT commented May 10, 2024

Short term, we need a PR to identify the time period specified in Retry-After and possibly delay polling until that point.
Maybe I misunderstand you, but just wanted to add that when I got rate-limited yesterday polling still worked fine, all my sensors like battery updated correctly. I just couldn't send any commands.

From rileymd88's link above (https://developer.tesla.com/docs/fleet-api#membership-tiers) I would guess I hit the "Command limits" of 50 reqs/day.
Looking further down in the Tesla API documentation "Vehicle Commands" are all POSTs (https://developer.tesla.com/docs/fleet-api#vehicle-commands)

For "Device data limits" at 1 reqs/5min we should mostly be fine, as default polling interval is at 10 minutes if I'm not mistaken.

I do however agree with you on the solution to verify Retry-After and delay polling if this unlikely event should occur.

For Vehicle Commands however I'm not sure what to do. It's not really an option to delay the sending of the command for 24 hours.
Perhaps exposing a sensor, Rate Limited, with the number of seconds (taken from Retry-After) to wait until a command can be issued again?
That way the sensor can be used in automations as some sort of failsafe.

@sgriessini
Copy link

Yikes! 50 commands per day? There goes my automation for excess solar charging.

Same for me, automation uses data and commands every minute. Now I have to adjust manually 😕

@zlymeda
Copy link

zlymeda commented May 10, 2024

Yikes! 50 commands per day? There goes my automation for excess solar charging.

Same for me, automation uses data and commands every minute. Now I have to adjust manually 😕

You can use BLE for commands (that are not rate-limited), as you are connecting to the car directly.
I am running a modified version of the HTTP proxy, where I try to connect via BLE first, it is not perfect solution, I will need to improve it once I have time. sometime the BLE is stuck and even using the context cancelling in go, still won't prevent from deadlock from time to time. So If I detect the deadlock, I just restart the service..

@rubin110
Copy link

rubin110 commented May 12, 2024

So I'm trying to understand this bug. I can no longer send commands to my car, however I'm getting data back and just as frequently as few months prior through Teslamate. Wouldn't both be hitting the same issue?

@rileymd88
Copy link

So I'm trying to understand this bug. I can no longer send commands to my car, however I'm getting data back and just as frequently as few months prior through Teslamate. Wouldn't both be hitting the same issue?

This add on uses the new Fleet APIs which have the rate limits. Teslamate still uses the old deprecated Owners API which did not have any rate limiting in place.

@bkrishnadas-mq
Copy link

Yikes! 50 commands per day? There goes my automation for excess solar charging.

Same for me, automation uses data and commands every minute. Now I have to adjust manually 😕

You can use BLE for commands (that are not rate-limited), as you are connecting to the car directly. I am running a modified version of the HTTP proxy,

Any links/doco on how this works and how to set this up?

@NavBlue1
Copy link

NavBlue1 commented May 13, 2024

Does anyone please know how or if Teslemetry is getting around this?

I could be wrong but I thought it used the fleet api as well. And I’m not talking about the few entity’s you can stream with Teslemetry.

After getting rate limited using this custom integration, I got my old Teslemetry hacs integration up and running again I can do a “Home Assistant core integration : update entity” service call every 15s which effectively does a force update on all Teslemetry entities and not get rate limited.

@sreuter
Copy link

sreuter commented May 14, 2024

We contacted Tesla regarding this, and they confirmed that they started to roll out their documented rate limits. That being said, we believe their implementation is buggy. For instance, we get a 429 with a Retry-After: 86400 when calling the wake_up endpoint, which has a documented rate limit of 5 API requests / car / hour.

This value seems odd for two reasons:

  1. This number shouldn't be static. When you try again in 5 minutes, it should show a value around 86100. Otherwise, you might get a Retry-After: 86400 while it might work 2 minutes later again.
  2. The number 86400 (a full day) does not make sense for an endpoint with an hourly measurement window.

We told Tesla that we'd love to adhere to their limits (even tho some limits feel extremely small) but would need a bit more guidance. The whole wake_up thing also never made sense to us in the first place. It should just be possible to set a wake car if asleep flag on any important call instead of having to make a separate call first. Also, what if the vehicle doesn't have a signal for some time? One would waste their daily budget of 5 calls a day per car quite fast.

We hope they come around soon to help their consumers with better advice. ¯_(ツ)_/¯

@abreingan
Copy link

I also seem to be having this problem, using llamafilm's Proxy, which I only started using a few days back. I am using this for solar charging and it normally works well until sometime in the afternoon and then stops.
I would be interested in zlymeda's comment about BLE. If this works to change charging amps then that is most of the commands I issue.

@zlymeda
Copy link

zlymeda commented May 16, 2024

the go repo for running http proxy, as well as using BLE is here: https://github.com/teslamotors/vehicle-command
you should find all the necessary information there.

then I modified the method loadVehicleAndCommandFromRequest. first I try to use BLE connection.. if that fails I will fallback to HTTP:

// try to use BLE
conn, err := ble.NewConnection(ctx, vin)
if err == nil {
	car, err = vehicle.NewVehicle(conn, p.commandKey, p.sessions)
	if err == nil {
		return car, commandToExecuteFunc, nil
	}
}

// if above fails, use HTTP
car, err = acct.GetVehicle(ctx, vin, p.commandKey, p.sessions)

@OrbitTheSun
Copy link

OrbitTheSun commented May 16, 2024

When blocked, I found that the mobile app still has access to the vehicle data. This also applies when my cell phone and my server have the same IP address. By using the app, I was even able to temporarily unblock my server. Does anyone have any idea whether the cell phone app isn't blocked and how?

@abreingan
Copy link

Thanks zlymeda.
I have just started using llamafilm's version of the proxy as I got cut off a couple of weeks back, so I might let things mature for a while and hope Tesla comes out with information about the scheme, especially how they might charge for this. That would be simplest.

I suspect that many will have the same issues as I do, my Home Assistant server is behind CGNat and out of BLE range from the car.

@PedroKTFC
Copy link

I've started getting the Error 429 this afternoon. Looking in the logs I notice I have the following entries:

2024-05-22 23:19:12.982 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:19:22.986 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:19:32.974 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:19:43.041 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:19:52.973 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:20:02.974 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:20:12.993 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:20:22.975 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS
2024-05-22 23:20:32.982 WARNING (MainThread) [teslajsonpy.controller] Unable to get vehicle data during poll. 429: TOO_MANY_REQUESTS

Note these seem to be going on continously, this is just a selection.

It seems like something is (re?)trying a poll every 10 seconds. Since the 429 started, and reading about the 50 a day limit, I've changed my polling interval from 660 seconds to 2000, which should total less than 50. I've no idea about the underlying process but could these be swamping the Tesla servers?

In fact, might this mean I will never recover (these are continuing to spew out as I write this)?

@alandtse
Copy link
Owner

Yes, the old API used to let you access the list of vehicles and determine basic status before connecting to the vehicle without a rate limit. This was hitting Tesla's server and not your car. We do it every 10 secs. Apparently that is rate limited now. Happy to take a PR but this now means we can't detect wakeups as quickly so there might have to be a complete rearchitecture.

@PedroKTFC
Copy link

Ah, thanks for the comment and link. So it looks if I set the car's Polling switch off the car isn't polled but are the Tesla servers always polled every 10s by the integration? If so I'll raise a PR.

Also, in my automations, I use the Charger switch to start and stop the car charging. Some questions about this:

  • if I disable polling, will the switch ever be turned on or off?
  • If not, could I force it by using either of the Force data update or Wake up buttons?
  • If so, which one would be best? If not, is there any other way of turning charging on and off?

For my case I don't need the car's information to be always up to date, only when I want to request it.

@raphmur
Copy link

raphmur commented May 25, 2024

Same problem here, and same goal: usage of excess solar...
I really like the BLE option, whether you are in range, or could setup an ESP wifi to BLE relay or other contraption...
However @zlymeda I don't really get what you have done by modifying the method. I mean, is this Go library already used by this Tesla integration? If yes, that would be a simple option to be added, or even systematic...

@dreamonhigh

This comment has been minimized.

@zlymeda
Copy link

zlymeda commented May 25, 2024

the original HTTP proxy only connects to cars via HTTP, not BLE. however, the repo contains a cli for executing commands via HTTP or BLE. I had to modify the method (in the proxy) so that the BLE is tried first, if BLE fails => I use HTTP.

for my "solar excess" usage it is enough. but it is not great. the better solution would be to "know" if the car is home, and so BLE is reachable. I need to find more time to improve it. the problem, I mentioned before is that the BLE sometimes gets stuck and even context cancellation does not prevent it from blocking forever. so my workaround is: if this is detected kill the app. I run the app as a service, so killing it means restarting.
even the BLE connection is issued every time there is a request. this is a proxy for multiple cars (potentially). but I think, we could build a "single car" proxy, that could re-use the ble connection and probably other things as well.

I tried monitoring the car via BLE, but once it is monitoring it can't do other things, like issue command via BLE. the BLE seems not to be able to do more things at once. so I'll need some strategy to detect if the car is home (asking HA?, checking the GPS via HTTP?, ...) and based on that use BLE or HTTP.

also there are issues in the official repo about reading information via BLE. right now, we can issue commands via BLE, but we don't know the state of the car and we need to use HTTP for that. if they add support for reading charge limit, charging state, ... via BLE, then we could build solar excess charging solely using BLE.

@raphmur
Copy link

raphmur commented May 26, 2024

Thanks.
Looking at the code from the Tesla Custom Integration, I do not see any reference to the official vehicle-command library, as the API call URLs are hardcoded in library teslajsonpy https://github.com/zabuldon/teslajsonpy
@zlymeda Did you manage your solar charge regulator with HomeAssistant and Tesla SDK? or any other wizardry? :)

I am no fluent in Go, but happy to learn and to help to upgrade with this BLE integration... For what I need:

  • I get current charging amps data --> which could still be HTTP or "saved" from previous successful sent command via BLE
  • Then calculate few variables and send new charging order --> can be done via BLE
  • This every 2 or 3 minutes, so I assume the BLE session could drop in between, so just create a new one

The ideal way of working (maybe) would be for this TeslaCustomIntegration to use directly (or fork and change) the vehicle-command SDK... Again, happy to help, but the starting point is not super clear for me.

@raphmur
Copy link

raphmur commented Jun 6, 2024

Indeed, I did not mention. I tried also to recover the keypair from the proxy, but no success.
So I created a new (local) keypair using openssl as per the tutorial here (the one from Shankar K). It has no link with your Tesla Dav account, it is recognized by the car as a BLE key, and that's it. More or less the same way of working (I assume) as with pairing your phone as a key.

/!\ Please be aware that getting your Pi stolen or hacked will compromize your car (but you can delete the key from the car).

For BLE proxy, I did not read through enough.

@abreingan
Copy link

Thank you - I will go fiddle with that.

@MrBLJ
Copy link

MrBLJ commented Jun 7, 2024

Indeed, I did not mention. I tried also to recover the keypair from the proxy, but no success. So I created a new (local) keypair using openssl as per the tutorial here (the one from Shankar K). It has no link with your Tesla Dav account, it is recognized by the car as a BLE key, and that's it. More or less the same way of working (I assume) as with pairing your phone as a key.

/!\ Please be aware that getting your Pi stolen or hacked will compromize your car (but you can delete the key from the car).

For BLE proxy, I did not read through enough.

Thanks a lot for your work. It's most welcome and useful for charging our cars with excess solar power.

@andreaconfa
Copy link

andreaconfa commented Jun 9, 2024

Hi all,

I spent quite some time fiddling around... Main target for me is excess solar charging regulation, for which I refresh the charging amps every 2 minutes. I was seeing generic "TeslaException", and well, I assumed I was rate limited, but in fact I was using the old API.

1st action is to setup FleetAPI. The "howto" in the Tesla HTTP Proxy Add-On is sufficient, but be very focused, especially if you are not a specialist. Then re-create your Tesla in HA with FleetAPI. Please be aware that you need some sort of business credentials (probably not mandatory though). --> It restored the possibility to send commands. However, I am now clearly rate limited mainly on commands This way if you set limits (as above posts) on polling rate, you should be ok for now if you don't abuse.

2nd action / hack is to use the official Tesla Vehicle Command SDK, which contains cli tools to send commands via BLE to your Tesla. This package is already part of the proxy deployed in step one, but only for the HTTP proxy. @zlymeda managed to directly integrate BLE calls within the Tesla HTTP calls (in the proxy) as a hack, but not working for me... To make it short: I installed tesla-control on a spare machine and used shell/ssh commands from HA to send commands via BLE to the Tesla. Steps taken:

  1. Install basic raspbian on an old RPi 3B laying around (but any linux / mac machine with BLE should work). ~30-60min
  2. Clone and compile (with golang >1.21) the cli tools from the Tesla SDK. The one I am interested in is tesla-control ~10min
  3. Follow this tutorial from Shankar Kumarasamy to:
  • Generate a new keypair to send ble commands to your Tesla (the tesla-keygen cli tool did not work for me) ~10min
  • Push the public key to your Tesla with tesla-control ~5min
  • Successfully send commands to your Tesla with BLE, then stop the tutorial there
  1. Be happy
  2. Generate SSH keypair to allow HA to connect to your spare machine on which you installed tesla-control ~5min
  3. Create a shell script in HA with the command below, and make it executable ~5min
    ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no -q [login]@[ip of ble machine] /path/to/tesla-control/tesla-control -ble -vin [your VIN] -key-name /path/to/teslakeypair/private.pem -key-file /path/to/teslakeypair/private.pem $@
  4. Create a "shell_command" as per guide ~5min
  5. Then instead of calling the commands from the Tesla Custom Integration objects, you use the shell command created, with the arguments you need (see example below) depends on you
  6. Be more happy
  7. Finetune the delays as the BLE command may sometimes timeout or fail (busy device)
    I also adapted my solar regulation to "assume" Tesla state based on sent commands, instead of polling data. Maybe useless, but not tested.

To make things sustainable for solar charge regulators, I would see:

  • Easy option: buy a wall charger with is controllable........ $$$
  • Create a custom integration to implement only the BLE tesla-control, and then remove the need for third party beacon. Something like "Tesla local commands" --> I will try...
  • Nicely integrate BLE commands in the existing integration. Maybe in teslajsonpy...

image

Hi,
thank you for the little guide.
I was able to deploy and use the raspberry toghether with home assistant to control my car via BLE.

The only problem is that, when i send commands to the car, i receive very ofter the error:
Error: ble: failed to enumerate device services: ATT request failed: input channel closed: io: read/write on closed pipe
Did you know how to solve this?

Due to this issue i had to create a script that check if the command is successful or not, and in this case it retry it for 5 time, maybe this can be useful for someone:

image

To change the charge setpoint of the car i call this script with arguments (like VIN and amps number). The script will cycle and and when the command is sent without error (for maximum 5 times)

@BogdanDIA
Copy link

BogdanDIA commented Jun 9, 2024

Hi all,

I was searching the github issues list to find some info as yesterday my v2 API access seized to work. I did install the HTTP proxy and followed all the gory details to make FleetAPI working. So now FleetAPI works.
However, BLE seemed from the beginning a better solution for charging from solar excess. I will write here what I've done so far.

  • BLE commands worked from day 1 of Tesla publishing the FleetAPI in 2023. I initially installed the software on a rpi3 and it worked fine although there was a bit delay like 1-2 seconds from the command until the car reacts to it.
  • From a previous project where I tested the relay attack for the BLE connection between the phone and the car (which worked really well) I understood something important. Specifically that on rpi3 the BLE works very poorly when WiFi is used. That is because BLE and WiFi share the same 2.4Ghz band and the wifi signal drowns the BLE receiver. So, going further, I tried a rpi5 that has the 5Ghz wifi band. This allowed a huge improvement for the BLE connection between the rpi5 and the car. Improvement is both in longer distance and stability of connection.
  • I'm not a big fan of golang but I did some research on how to convert the code to a pure C, C++ so I can run the BLE code on an ESP32. There are some code converters but even with just a single file from the golang library it failed. So this is still some work in progress as ESP32 should be quite nice to have in this project.
  • detecting if the car is home I've done with an ESP32 by receiving the iBeacons sent by the car. There are 4x BLE transceivers (center, rear, left, right). They are used by the car to detect where the phone is physically located by comparing the RSSI received from each of the transceivers. The transceivers emit iBeacons at a high rate so multiplied by 4x it gives a very fast presence detection and this is why I use it for turning the lights on when I reach at my home's gate. The 4x transceivers are also used for detecting the location of each of the wheels so that's why there is no need to pair each of the wheels to the car.
  • the BLE FleetAPI from Tesla does not provide status from the car if one wants to get e.g. SoC or batt charge limit or other data. We can send only commands and the only feedback is a sort to communication error in case something is not working so it is like shooting in the dark. We asked Tesla on github to improve the API with status commands but so far there is nothing changed in the API.

BTW, just as info, this is one example of the BLE measurements (of the phone signal) done by the car and sent to the phone during the authentication phase when the user tries to open the driver's door but the phone is too far so the car will not unlock:

alert {
alertHandlePulledWithoutAuth {
timeSinceAlertSet_ms: 858
connectionCount: 1
deviceSpecificPayload {
keyChannel: 3
RSSILeft: -78
RSSIRight: -92
RSSIRear: 127
RSSICenter: -88
}
}
}

All in all, I think the BLE will be good for communication with the car for charging and not only because there will be no rate limiting and no need for internet access. Hope Tesla will not try to monetize BLE as they try with the server connection.

@raphmur
Copy link

raphmur commented Jun 9, 2024

Super

Thanks @BogdanDIA for clarification! For BLE performance, I assume using a ethernet RPi3 and leaving the full antenna for BLE should improve...? Or using an external bluetooth dongle maybe....

@andreaconfa, I like your tweak, though it just becomes specific for one command (set charge amps), which should not be a big issue as this is one of the main goals...
I did not see this exact error but some similar on busy channel or pipe.... I just retried the command and it worked. What I have found relevant:

  • don't spam commands too often: leave at lease 15sec between calls
  • when it fails: retry and usually it works. I use this in a loop anyways so it is not a major concern if 1 loop fails.
    I though of implementing this failsafe version but your code is useful now! Be careful, I have found that the "wake" command, with "-domain vcsec wake" is not usually successful even if no error is thrown.

I really used this "BLE trial & error spamming technique" as a last option :) So it could probably be done smartly with and integration, failsafe solutions, ... Oh well

@BogdanDIA
Copy link

Thanks @BogdanDIA for clarification! For BLE performance, I assume using a ethernet RPi3 and leaving the full antenna for BLE should improve...? Or using an external bluetooth dongle maybe....

@raphmur yes, the ethernet shoud work while having wifi disabled.

@MrBLJ
Copy link

MrBLJ commented Jun 10, 2024

Your post is super interesting, thanks a lot.

I tried a rpi5 that has the 5Ghz wifi band. This allowed a huge improvement for the BLE connection between the rpi5 and the car. Improvement is both in longer distance and stability of connection.

From what I've read, there is some kind of unicorn out there in the form of ESP32-C5 which is able to connect to 5Ghz wifi networks. However I don't think it's available yet.

Based on your experience, without interference from Wi-Fi and Bluetooth (using either an RPi 5 or an Ethernet connection), what is the maximum distance at which we can place the device from the car? I am trying to decide whether I should run an Ethernet cable to my garage and use an old RPi 3, or buy a new RPi 5 (which costs at least $60 where I live) and utilize the 5 GHz Wi-Fi.

detecting if the car is home I've done with an ESP32 by receiving the iBeacons sent by the car.

Can you expand on that :

  • Are you using esphome with BLE beacons ?
  • How reliable is this ? For now I'm using a proximity sensor in HA with a few device trackers, it works most of the time but I'm wondering if it could be improved.

ESP32 should be quite nice to have in this project.

I'm pretty confident in telling you I'm not the only one that'd be very interested in such a solution. In this case however, could we have issues between Wi-Fi and Bluetooth ?

@BogdanDIA
Copy link

Your post is super interesting, thanks a lot.

I tried a rpi5 that has the 5Ghz wifi band. This allowed a huge improvement for the BLE connection between the rpi5 and the car. Improvement is both in longer distance and stability of connection.

From what I've read, there is some kind of unicorn out there in the form of ESP32-C5 which is able to connect to 5Ghz wifi networks. However I don't think it's available yet.

Based on your experience, without interference from Wi-Fi and Bluetooth (using either an RPi 5 or an Ethernet connection), what is the maximum distance at which we can place the device from the car? I am trying to decide whether I should run an Ethernet cable to my garage and use an old RPi 3, or buy a new RPi 5 (which costs at least $60 where I live) and utilize the 5 GHz Wi-Fi.

detecting if the car is home I've done with an ESP32 by receiving the iBeacons sent by the car.

Can you expand on that :

* Are you using [esphome with BLE beacons](https://esphome.io/components/text_sensor/ble_scanner.html) ?

* How reliable is this ? For now I'm using a [proximity](https://www.home-assistant.io/integrations/proximity/) sensor in HA with a few device trackers, it works _most_ of the time but I'm wondering if it could be improved.

ESP32 should be quite nice to have in this project.

I'm pretty confident in telling you I'm not the only one that'd be very interested in such a solution. In this case however, could we have issues between Wi-Fi and Bluetooth ?

I've checked the ESP32 C5 few months ago but as you said it was not ready. The major work would be porting the golang to the ESP. Encrypting the FW in ESP should give a good level of protection for the car's keys.

I think you need to experiment with the maximum distance you can obtain as it depends on many variables like LOS(line of sight) or not, number of other networks in the area, existing walls, etc. A for myself, I started with having a laptop at 5 meters from the car and making the BLE FleetAPI working on it I switched to rpi3 by placing it in the same spot as the laptop. It did not work as there were a lot of comm errors so that is why I switched to rpi5 on 5Ghz band. Did not check max distance, though.

For car presence I started with the iBeacon HA integration which was awfully slow especially when departing from home so I decided to use ESPHome with my own implementation. Instead of using the RSSI in calculating the distance, I used the count of the iBeacon messages received from the car. This works very well in this case where the car sends tens of messages per second. When there is no message received for e.g. 3 seconds it is clear the car is not close. This worked flawlessly for more than 6 mo now.
One thing to note is that during car's software update there is a period of 15-20 seconds when iBeacons are not sent and this needs to be taken in consideration e.g in HA automation that will not trigger the action while updating the car.

But there are other ways to change the charging parameters for the experimenters, one of them being with CAN commands. Been fiddling with CAN for sometime with an rpi/ESP32 and a OBD2 dongle, no keys needed, just 8byte messages. I don't recommend it though as I've seen Tesla changing some of the CAN commands format from time to time during the years. And also that some people say that Tesla logs strange CAN messages that do not come from MCU but from other busses of the car. On the flip side, the S3EXY buttons from enhance do the same thing by sending CAN messages instead of MCU or other devices on the buses.

@i-am-shodan
Copy link

I'd check out https://github.com/pmdroid/tesla-ble and see if the API is the same.

@iainbullock
Copy link

iainbullock commented Jun 10, 2024

Thanks for everyone's contribution to this.

I have created a docker container which will send commands from Home Assistant via MQTT to a car using BLE. It is useful to run on a remote device e.g. Raspberry Pi located close to where the car is parked. MQTT will auto-populate the various entities in Home Assistant, such that Buttons can be pressed (and Services called from Automations) to send commands. There is a Number entity to set the charging current. It's a first release so will need further work no doubt

https://github.com/iainbullock/tesla_ble_mqtt_docker

@andreaconfa
Copy link

andreaconfa commented Jun 10, 2024 via email

@raphmur
Copy link

raphmur commented Jun 10, 2024

Thanks @iainbullock! Looking great.
You mention in your docs that the wake command does not work. I managed to get it to work with the -domain vcsec parameter. I will try to contribute directly then.
Are you familiar with HA integrations? It seems that with this, we are not too far from deriving your project to make the integration work locally on the HA host 😀. It should be feasible, but so far I do not know how to access the BLE device in HAOS...

Anyways, this thread is getting very long and it seems that most of us have a workaround with FleetAPI (with increased polling intervals) + BLE for frequent commands when close to the car.

I suggest to close this issue as solved, marking Ian's repo as solution... @alandtse? At least until a more packaged solution raises with the full bundle HA extension: Fleet API + local BLE (on HA host) + remote BLE (on ESP or RPi), including some proximity/location sensors...

Maybe switch this discussion to Discord or anything less verbose on the Internet? I just initialized this channel

@iainbullock
Copy link

I did consider making it a HA Custom Integration, however I wanted it to on a device remote from my HA server so it could be close to the car. Please contribute to my project it would be most appreciated.

@BogdanDIA
Copy link

I'd check out https://github.com/pmdroid/tesla-ble and see if the API is the same.

Seems to be the old one that has been reverse engineered form the Android phone.
But I think the old one and the new one are still coexisting in the latest version of the car's SW.

@iainbullock
Copy link

Hi, This is awesome. Unfortunately I already see an issue for my use-case. I have two car (and this mean two different vins). Maybe you can make the VIN number as a setting in home assistant instead of passing it directly to the docker container…. Do you think is possible ? Thanks

Definately possible, I thought about it but decided to get this simple version released to see what comments / contributions it gets

@iainbullock
Copy link

I'd check out https://github.com/pmdroid/tesla-ble and see if the API is the same.

Thanks for the suggestion. I'm going to be away for two weeks soon, so might not get chance until i get back. It will be interesting to see what develops in the meantime

@andreaconfa
Copy link

Hi, This is awesome. Unfortunately I already see an issue for my use-case. I have two car (and this mean two different vins). Maybe you can make the VIN number as a setting in home assistant instead of passing it directly to the docker container…. Do you think is possible ? Thanks

Definately possible, I thought about it but decided to get this simple version released to see what comments / contributions it gets

I can try to contribute to this but I’m not sure what is the best way to do it.

Using the vin as parameter in home assistant (sent via Mqtt) means that people with only one car need to also use it when not needed.

Maybe a combination of fixed vin in docker (as a default one) and mqtt paremeter to override the default vin can be the way to do it.

@iainbullock
Copy link

Hi, This is awesome. Unfortunately I already see an issue for my use-case. I have two car (and this mean two different vins). Maybe you can make the VIN number as a setting in home assistant instead of passing it directly to the docker container…. Do you think is possible ? Thanks

Definately possible, I thought about it but decided to get this simple version released to see what comments / contributions it gets

I can try to contribute to this but I’m not sure what is the best way to do it.

Using the vin as parameter in home assistant (sent via Mqtt) means that people with only one car need to also use it when not needed.

Maybe a combination of fixed vin in docker (as a default one) and mqtt paremeter to override the default vin can be the way to do it.

I think you opened an issue on my project page. Please can you repeat the question there and we can discuss it there thanks
tesla-local-control/tesla_ble_mqtt_docker#1

@andreaconfa
Copy link

Thanks @iainbullock! Looking great. You mention in your docs that the wake command does not work. I managed to get it to work with the -domain vcsec parameter. I will try to contribute directly then. Are you familiar with HA integrations? It seems that with this, we are not too far from deriving your project to make the integration work locally on the HA host 😀. It should be feasible, but so far I do not know how to access the BLE device in HAOS...

Anyways, this thread is getting very long and it seems that most of us have a workaround with FleetAPI (with increased polling intervals) + BLE for frequent commands when close to the car.

I suggest to close this issue as solved, marking Ian's repo as solution... @alandtse? At least until a more packaged solution raises with the full bundle HA extension: Fleet API + local BLE (on HA host) + remote BLE (on ESP or RPi), including some proximity/location sensors...

Maybe switch this discussion to Discord or anything less verbose on the Internet? I just initialized this channel

the discord link is not working

@raphmur
Copy link

raphmur commented Jun 10, 2024

edited

@rubin110
Copy link

It's been over a week with connecting to my model 3 through the http proxy, setting HA to only poll once an hour, getting most of the my data through Teslamate/MQTT, I haven't had any issues with occasionally interact with the vehicle.

I'm interesting in messing with the BT proxy, but I think that's a winter time project.

@raphmur
Copy link

raphmur commented Jun 15, 2024

Do you speak German?

I have just discovered this project: https://evcc.io/en/
... with this issue: Tesla fleet API error 429 Too Many Requests
and this package to implement a BLE proxy.

Anyone has got elements of context?

As for now @iainbullock has bundled a set of commands in a self running docker image, that connects to MQTT: https://github.com/iainbullock/tesla_ble_mqtt_docker
And I bundled it in an Add on (still very early beta): https://github.com/raphmur/tesla-local-control-addon

We will probably work around these two to increase the stability and usability over BLE.

@yoziru
Copy link

yoziru commented Jul 22, 2024

I made https://github.com/yoziru/esphome-tesla-ble to get around this. Set up on an ESP32 and it shows up as an ESPHome device. Bonus: it works locally and offline

@emaberga81
Copy link

What is the suggestion to not get rate limited then? Changing the polling interval from 660s/30s to something else? :)

@PedroKTFC
Copy link

I only poll on demand now. For example, when I want to see my car's current stats, I use a binary helper that triggers a NodeRed routine that enables polling, updates data and then disables polling (and resets the binary helper).

@emaberga81
Copy link

I only poll on demand now. For example, when I want to see my car's current stats, I use a binary helper that triggers a NodeRed routine that enables polling, updates data and then disables polling (and resets the binary helper).

Good idea, I have to implement something loke that. But what do you do when you start charging to get the charging status updated? That is quite important for my heating/energy saving automations 🤔 You trigger a status update manually?

@PedroKTFC
Copy link

I trigger an update through an automation (in my case in NodeRed). Another example is I have free electricity from Octopus Energy so I have an automation that starts charging when the free power starts and stops when it ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
car For items that relate to Tesla vehicles enhancement New feature or request help wanted Extra attention is needed triage New issues raised that need initial attention
Projects
None yet
Development

No branches or pull requests