core icon indicating copy to clipboard operation
core copied to clipboard

google_travel_time needs Routes API enabled since 2025.5.0

Open marksteward opened this issue 7 months ago • 9 comments

The problem

Since upgrading to 2025.5.0, all my travel time entities are set to Unknown and I have the following in my logs:

Logs
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 132, in __call__
    return self.type(v)
           ~~~~~~~~~^^^
ValueError: could not convert string to float: '...'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 384, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.13/site-packages/voluptuous/schema_builder.py", line 779, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 137, in __call__
    raise CoerceInvalid(msg)
voluptuous.error.CoerceInvalid: expected float

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/voluptuous/schema_builder.py", line 205, in __call__
    return self._compiled([], data)
           ~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 256, in _run
    return self._exec(self._compiled, value, path)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 386, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
voluptuous.error.AllInvalid: invalid latitude

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 956, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1304, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/google_travel_time/sensor.py", line 259, in async_update
    destination=convert_to_waypoint(self.hass, self._resolved_destination),
                ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/google_travel_time/helpers.py", line 39, in convert_to_waypoint
    vol.Schema(cv.gps(formatted_coordinates))
               ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 930, in __call__
    raise e if self.msg is None else ExactSequenceInvalid(self.msg)
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 928, in __call__
    v = type(v)(schema(x) for x, schema in zip(v, self._schemas))
  File "/usr/local/lib/python3.13/site-packages/voluptuous/validators.py", line 928, in <genexpr>
    v = type(v)(schema(x) for x, schema in zip(v, self._schemas))
                ~~~~~~^^^
  File "/usr/local/lib/python3.13/site-packages/voluptuous/schema_builder.py", line 209, in __call__
    raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: invalid latitude

I assume you need to include vol.MultipleInvalid in the exception handler in convert_to_waypoint, or maybe switch to just vol.Invalid. Using latlngs is a workaround for now.

The release note only says:

Google has deprecated the Distance Matrix API. The new Routes API does not provide the state attributes Destination addresses and Origin addresses anymore.

But I think that should give a little more guidance, e.g.:

You must enable the Routes API in your Google Cloud project, and if your API key is restricted, you must update it to allow the Routes API instead of the Distance Matrix API.

Also, adding a new entry to the integration when all other entries are disabled doesn't enable the device, which caused me a bit of confusion until I randomly enabled one of the other entries.

What version of Home Assistant Core has the issue?

2025.5.0

What was the last working version of Home Assistant Core?

2025.4.5

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Google Maps Travel Time

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet


Anything in the logs that might be useful for us?


Additional information

No response

marksteward avatar May 09 '25 00:05 marksteward

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

Code owner commands

Code owners of google_travel_time 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 google_travel_time 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)


google_travel_time documentation google_travel_time source (message by IssueLinks)

home-assistant[bot] avatar May 09 '25 00:05 home-assistant[bot]

Hi @marksteward check your logs.

If you see the same entry as me, just do as the log says and it will probably work again...

Error getting travel time: 403 Routes API has not been used in project xxxxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/routes.googleapis.com/overview?project=xxxxxxxxx then retry.

I'm a bit worried about the impact to Google API costs tough...

silke-99 avatar May 09 '25 15:05 silke-99

@silke-99 ahh yeah I do see that in the logs now, but I was going off the mysterious "Authentication error" in the UI. I think it's worth including in release notes because basically everyone will have to make this change. It would have made me think before installing the upgrade last thing at night.

Since Google changed their limits a few weeks ago I've been running at every 30 mins during the day and every hour during the night, which should be ~36 requests a day (~72 with traffic), and the 10000 limit allows for ~322/day.

marksteward avatar May 09 '25 16:05 marksteward

Same problem. When I try to reconfigure the integration with the api key in the ui, I have an authentication error. I checked in the gcp console, the api key is still valid.

Edit : sorry, I just saw the message from silke-99, the api was desactivated…

bax137 avatar May 11 '25 06:05 bax137

I have been having similar issue, I would suggest migrating to Waze or HERE Maps Tavel Time. Waze has no API key requirement so no worry about google charging. Personally I prefer HERE Maps

UiharuKazari2008 avatar May 12 '25 13:05 UiharuKazari2008

You have to enable the Routes API for your API key as stated in the updated(!) documentation I missed flagging this in the breaking changes section. Sorry!

@marksteward Since Google changed their billing they only allow 5000 free requests with "live traffic". Given these are what most people are using the limit is 161/day.

I will properly catch the exceptions and maybe raise a repair issue if possible

eifinger avatar May 12 '25 17:05 eifinger

@home-assistant rename google_travel_time needs Routes API enabled since 2025.5.0

eifinger avatar May 12 '25 17:05 eifinger

Thanks!

I read in the past that a traffic-aware request counted as two requests, but I see now that's not right and there's a separate lower limit for the Pro SKU. In practice, if you're not mixing SKUs this should be the same, so my scheme still works out at 4 routes with some headroom on the free tier. And the new default of every 10 minutes uses ~144/day for a single route, which is just under limit of 161/day.

marksteward avatar May 12 '25 18:05 marksteward

You have to enable the Routes API for your API key as stated in the updated(!) documentation I missed flagging this in the breaking changes section. Sorry!

@marksteward Since Google changed their billing they only allow 5000 free requests with "live traffic". Given these are what most people are using the limit is 161/day.

Speaking of the doco... the Routes API quotas look different to the Matrix ones; can we confirm what we should be setting the 161/day to?

Image

lingfish avatar May 12 '25 23:05 lingfish

I can't get this to work. I've got the API enabled for my key:

Image

but while setting up the integration I'm getting an Unknown error occured without anything in the logs

Image

benjamin-dcs avatar May 22 '25 10:05 benjamin-dcs

I can't get this to work. I've got the API enabled for my key:

Image

but while setting up the integration I'm getting an Unknown error occured without anything in the logs

Image

Are you sure there is nothing in the logs? There should either be a single error log or an uncaught exception with a stracktrace.

eifinger avatar May 22 '25 12:05 eifinger

I somewhere found the hint to use latitude & longitude for origin and destination as normal and plus-code addresses do not work here anymore. In combination with the assigned Routes API access it started working again. Actually just a workaround at the moment.

n-o-m-e-r-c-y avatar May 22 '25 12:05 n-o-m-e-r-c-y

Are you sure there is nothing in the logs? There should either be a single error log or an uncaught exception with a stracktrace.

Yes, unfortunately nothing in the logs. Networks console gives me a 400: Bad Request

benjamin-dcs avatar May 22 '25 15:05 benjamin-dcs

While it is true that switching to GPS coordinates solves the issue of it not working at all, the problem remains that disabling polling also seems to disable manual updates of the sensor....

Edit: It seems enabling/disabling polling solved the issue for me.

Caligo82 avatar May 22 '25 23:05 Caligo82

Are you sure there is nothing in the logs? There should either be a single error log or an uncaught exception with a stracktrace.

Yes, unfortunately nothing in the logs. Networks console gives me a 400: Bad Request

Can you please enable debug logging? It should then show logs how it resolves your destination sensor. Can you please verify if it is able to resolve it to a set of GPS coordinates?

eifinger avatar May 24 '25 06:05 eifinger

Are you sure there is nothing in the logs? There should either be a single error log or an uncaught exception with a stracktrace.

Yes, unfortunately nothing in the logs. Networks console gives me a 400: Bad Request

Can you please enable debug logging? It should then show logs how it resolves your destination sensor. Can you please verify if it is able to resolve it to a set of GPS coordinates?

what's the exact integration name I need to the logger in my config.yaml as I can't enable debug logging through the UI I believe

benjamin-dcs avatar May 24 '25 06:05 benjamin-dcs

Are you sure there is nothing in the logs? There should either be a single error log or an uncaught exception with a stracktrace.

Yes, unfortunately nothing in the logs. Networks console gives me a 400: Bad Request

Can you please enable debug logging? It should then show logs how it resolves your destination sensor. Can you please verify if it is able to resolve it to a set of GPS coordinates?

I tested with coordinates, this works

benjamin-dcs avatar May 24 '25 19:05 benjamin-dcs

@benjamin-dcs your issue is something else, I created https://github.com/home-assistant/core/issues/145660

eifinger avatar May 26 '25 21:05 eifinger