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

Tesla Fleet: MESSAGEFAULT_ERROR_INCORRECT_EPOCH when unlocking charge port #133575

Open
tfriedlx opened this issue Dec 19, 2024 · 3 comments
Open

Comments

@tfriedlx
Copy link

The problem

I've uploaded my private key to my Tesla Model Y 2024 via Bluetooth and in general the commands like unlocking the charging port are working. However they only work for a limited time and after a while I get the error message "Incorrect epoch". Once I reload the integration its working again for some limited time.

What version of Home Assistant Core has the issue?

core-2024.12.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tesla leet

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tesla_fleet

Diagnostics information

config_entry-tesla_fleet-01JEQNWPX079X85JMCP3ZBGQZQ.json

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:245
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 14:07:27 (1 occurrences)
Last logged: 14:07:27

[140132555445664] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 39, in handle_command
    result = await command
             ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 373, in charge_port_door_open
    return await self._sendVehicleSecurity(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 228, in _sendVehicleSecurity
    return await self._send(DOMAIN_VEHICLE_SECURITY, command.SerializeToString())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 276, in _send
    resp = await self._signed_message(msg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 188, in _signed_message
    raise MESSAGE_FAULTS[resp.signedMessageStatus.signed_message_fault]
tesla_fleet_api.exceptions.TeslaFleetMessageFaultIncorrectEpoch: Incorrect Epoch

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
        hass, entity, func, data, call.context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 239, in async_handle_unlock_service
    await self.async_unlock(**self.add_default_code(kwargs))
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/lock.py", line 101, in async_unlock
    await handle_vehicle_command(self.api.charge_port_door_open())
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 52, in handle_vehicle_command
    result = await handle_command(command)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 41, in handle_command
    raise HomeAssistantError(
    ...<3 lines>...
    ) from e
homeassistant.exceptions.HomeAssistantError: Command failed: Incorrect Epoch

Additional information

No response

@home-assistant
Copy link

Hey there @Bre77, mind taking a look at this issue as it has been labeled with an integration (tesla_fleet) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tesla_fleet can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign tesla_fleet Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tesla_fleet documentation
tesla_fleet source
(message by IssueLinks)

@mookkari
Copy link

mookkari commented Dec 19, 2024

I have had same message "Incorrect epoch" several times in past weeks when unlocking the charging port. Sometimes it works, sometimes not. Today starting climate also gave "Incorrect epoch", I tried several times and always same error. Then I enabled debug logging and restarted Tesla fleet integration to get some information. But after integration was restarted everything worked as expected, climate heating was turned on without any issues.

At least with the last commands that I sent, Tesla was awake all time, so this is unrelated to the wake-up issue. I have created a script that tries to wake Tesla several times to overcome the wake-up issue. According to some document, it may take even 1.5 minutes to wake up the car and I think integration does not wait that long. Does integration expect Tesla to be wakened up manually before executing any command? That's why I have created a wrapper for all critical commands that I need (heating, charging, etc) that first push integration's wake button and wait until the car is online, if the car is not online in 3 minutes it will try to wake again, totally ten times. If the car is still sleeping it will send an error notification to the user.

This first logging is from my wake-up&start climate script that shows two errors from integrations:

Logger: homeassistant.components.script.tesla_kaynnista_ilmastointi
Source: helpers/script.py:2032
integration: Script ([documentation](https://www.home-assistant.io/integrations/script), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+script%22))
First occurred: 7:47:31 PM (60 occurrences)
Last logged: 8:07:55 PM
Tesla, käynnistä ilmastointi: Error executing script. Error for call_service at pos 1: Command failed: Incorrect Epoch
Tesla, käynnistä ilmastointi: Error executing script. Error for call_service at pos 1: Command failed: The vehicle is not 'online'.
Tesla, käynnistä ilmastointi: Already running

Even without debug logging there are few lines in the log directly from the Tesla fleet integration and HA:

Logger: tesla_fleet_api
Source: components/tesla_fleet/helpers.py:39
First occurred: 2:00:24 AM (56 occurrences)
Last logged: 8:15:39 PM
* already_set
* operation_status: OPERATIONSTATUS_ERROR signed_message_fault: MESSAGEFAULT_ERROR_INCORRECT_EPOCH

Logger: homeassistant
Source: components/tesla_fleet/helpers.py:41
First occurred: 7:47:31 PM (59 occurrences)
Last logged: 8:07:55 PM
Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 39, in handle_command
    result = await command
             ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 321, in auto_conditioning_start
    return await self._sendInfotainment(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 234, in _sendInfotainment
    return await self._send(DOMAIN_INFOTAINMENT, command.SerializeToString())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 276, in _send
    resp = await self._signed_message(msg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/tesla_fleet_api/vehiclesigned.py", line 188, in _signed_message
    raise MESSAGE_FAULTS[resp.signedMessageStatus.signed_message_fault]
tesla_fleet_api.exceptions.TeslaFleetMessageFaultIncorrectEpoch: Incorrect Epoch

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 707, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1801, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
        hass, entity, func, data, call.context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/climate.py", line 126, in async_turn_on
    await handle_vehicle_command(self.api.auto_conditioning_start())
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 52, in handle_vehicle_command
    result = await handle_command(command)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tesla_fleet/helpers.py", line 41, in handle_command
    raise HomeAssistantError(
    ...<3 lines>...
    ) from e
homeassistant.exceptions.HomeAssistantError: Command failed: Incorrect Epoch

@Bre77
Copy link
Contributor

Bre77 commented Dec 19, 2024

Does this just sort itself out eventually or do you need to reload/restart to fix the epoch?

This is going to be a bug in the underlying library as I had to write the command signing implementation myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants