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

Waze - "Timeout getting route" Trying to Add New Route #100417

Closed
mathmaniac43 opened this issue Sep 15, 2023 · 16 comments · Fixed by #100456
Closed

Waze - "Timeout getting route" Trying to Add New Route #100417

mathmaniac43 opened this issue Sep 15, 2023 · 16 comments · Fixed by #100456

Comments

@mathmaniac43
Copy link

mathmaniac43 commented Sep 15, 2023

The problem

Hello,

I have a few Waze Travel Time Entities working well in HA. I want to add another one, but for a much longer route (several hours). This fails during setup (as in, I try to add the Entity, but cannot because it times out and errors), presumably because it is taking too long for the Waze API to return the result and a timeout occurs.

Here are example settings that demonstrate the timeout problem:

Origin: 1600 Pennsylvania Avenue NW, Washington, DC 20500
Destination: 351 West 31st Street, New York, NY 10001
Region: North America or USA

Is there a way to optionally increase the timeout for a Waze Entity when setting it up? I think that keeping the timeout relatively short by default makes sense, but it would be great to have the option to increase it for known long routes (and perhaps have that setting persist for each time the entity updates).

Thanks!
Nick

What version of Home Assistant Core has the issue?

core-2023.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Waze Travel Time

Link to integration documentation on our website

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

Diagnostics information

N/A

Example YAML snippet

N/A

Anything in the logs that might be useful for us?

This is from the log, copied from the web UI.

[homeassistant.components.waze_travel_time.helpers] Error trying to validate entry: Timeout getting route

Additional information

N/A

@home-assistant
Copy link

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

Code owner commands

Code owners of waze_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 waze_travel_time Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


waze_travel_time documentation
waze_travel_time source
(message by IssueLinks)

@eifinger
Copy link
Contributor

Hi @mathmaniac43. Sometimes the Waze servers are overloaded. I just tried your route manually with pywaze and it succeded. Can you try again?

@mathmaniac43
Copy link
Author

Thanks for the tip. Just tried again, same failure. It is possible that the servers are overloaded again. I can wait, hope, and try again... but would love to see a more robust solution if possible.

@eifinger
Copy link
Contributor

The timeout should be 10s. Do you have the feeling that it takes that long or does it error out after 3-5s already?

@mathmaniac43
Copy link
Author

mathmaniac43 commented Sep 15, 2023 via email

@eifinger eifinger mentioned this issue Sep 15, 2023
20 tasks
@eifinger
Copy link
Contributor

Default timeout was 5 not 10. Raised a PR to change that.

@eifinger
Copy link
Contributor

Making it configurable is a lot more work and can be done at a later time

@mathmaniac43
Copy link
Author

Totally get it, and hopefully this will work for most folks anyways. I appreciate the rapid response and fix!

@mathmaniac43
Copy link
Author

Hello! Upgraded to 2023.9.3 today, which updated the timeout to 10s. Wanted to share my status.

The route I tried still timed out. I decided to work around the issue by making source and destination text helpers, using close-to-one-another addresses in them to allow me to add the Waze entity using those helpers, then set the helpers to the actual far-apart addresses. Each time I try to manually update the entities, I get a warning about the 10s timeout. So for my case at least, a higher and/or configurable timeout will be needed.

I assume this is a future and potentially low-priority task, which I understand. Let me know if you would like me to make a new issue for that. Thanks.

@eifinger
Copy link
Contributor

Hi. Thank you for your fast feedback.

Would you be willing to run a python script to give me more insight into your timeouts?

@eifinger
Copy link
Contributor

eifinger commented Sep 25, 2023

Steps for linux/macOS are as follows (let me know if you are in Windows and can't use WSL):

  1. Create a new directory somewhere and change into it
  2. Create a new file time_it.py and copy the python code below into it.
  3. Open a terminal/cli in the newly created folder
  4. Create a python virtual env: python3 -m venv venv
  5. Activate the env source venv/bin/activate
  6. Install pywaze: pip3 install pywaze
  7. Gather timings: python3 ./time_it.py
mkdir waze_test
cd waze_test
touch time_it.py
python3 -m venv venv
source venv/bin/activate
pip3 install pywaze
python3 ./time_it.py
#!/usr/bin/env python3

import asyncio
import time

from pywaze import route_calculator

async def get_times(start: str, end: str) -> list[float]:
    """Return the travel time home."""

    durations = []

    async with route_calculator.WazeRouteCalculator(timeout=60) as client:
        for _ in range(20):
            try:
                start_time = time.time()
                await client.calc_route_info(start, end)
                duration = time.time() - start_time
                print(f"Duration: {duration}")
                durations.append(duration)
            except Exception as e:
                print(f"Error: {e}")
            await asyncio.sleep(0.5)
    print(f"Average: {sum(durations) / len(durations)}")
    print(f"Min: {min(durations)}")
    print(f"Max: {max(durations)}")

start = "50.00332659227126,8.262322651915843"
end = "50.08414976707619,8.247836017342934"

asyncio.run(get_times(start, end))

@mathmaniac43
Copy link
Author

Yes, will try to run that later today and get back to you. I will first try to run it in my HA Docker container if I can to capture the runtime as accurately as possible.

@mathmaniac43
Copy link
Author

Ran a few times from inside my container, as promised. Thanks again for taking another look.

Results from the original script (with what I assume are lat/long):

/config/waze_test # python3 time_it.py 
Duration: 1.1001298427581787
Duration: 1.1898229122161865
Duration: 0.7029321193695068
Duration: 0.5369219779968262
Duration: 5.5711705684661865
Duration: 0.5466053485870361
Duration: 0.5389900207519531
Duration: 0.7680435180664062
Duration: 0.5189065933227539
Duration: 0.9873321056365967
Duration: 5.203672647476196
Duration: 5.459490537643433
Duration: 0.6492164134979248
Duration: 0.6298627853393555
Duration: 0.8454484939575195
Duration: 0.5368838310241699
Duration: 3.0861992835998535
Duration: 0.7854437828063965
Duration: 0.5522491931915283
Duration: 0.6721987724304199
Average: 1.5440760374069213
Min: 0.5189065933227539
Max: 5.5711705684661865

Modified script (with the example addresses I used in the issue description):

#!/usr/bin/env python3

import asyncio
import time

from pywaze import route_calculator

async def get_times(start: str, end: str) -> list[float]:
    """Return the travel time home."""

    durations = []

    async with route_calculator.WazeRouteCalculator(timeout=60) as client:
        for _ in range(20):
            try:
                start_time = time.time()
                start_coords = await client.address_to_coords(start)
                end_coords = await client.address_to_coords(start)
                start_coords_str = f'{start_coords["lat"]},{start_coords["lon"]}'
                end_coords_str = f'{end_coords["lat"]},{end_coords["lon"]}'
                await client.calc_route_info(start_coords_str, end_coords_str)
                duration = time.time() - start_time
                print(f"Duration: {duration}")
                durations.append(duration)
            except Exception as e:
                print(f"Error: {e}")
            await asyncio.sleep(0.5)
    print(f"Average: {sum(durations) / len(durations)}")
    print(f"Min: {min(durations)}")
    print(f"Max: {max(durations)}")

start = "1600 Pennsylvania Avenue NW, Washington, DC 20500"
end = "351 West 31st Street, New York, NY 10001"

asyncio.run(get_times(start, end))

Modified Script Results:

/config/waze_test # python3 time_it.py 
Duration: 0.8638455867767334
Duration: 0.8390858173370361
Duration: 0.8146271705627441
Duration: 0.8307678699493408
Duration: 1.5382299423217773
Duration: 3.470391273498535
Duration: 0.7945919036865234
Duration: 0.8008780479431152
Duration: 0.8225200176239014
Duration: 0.9084787368774414
Duration: 1.5585627555847168
Duration: 0.7821705341339111
Duration: 5.525111675262451
Duration: 0.8133370876312256
Duration: 1.0565540790557861
Duration: 0.8240575790405273
Duration: 0.867389440536499
Duration: 2.837029457092285
Duration: 0.8509154319763184
Duration: 0.7837250232696533
Average: 1.3791134715080262
Min: 0.7821705341339111
Max: 5.525111675262451

Maybe I am paranoid, but the fact that the time changes so arbitrarily makes me wonder if there is some kind of cycle where the servers are being hammered... maybe I'll try a few seconds of offset from the "every 5 minutes" update automation I have, instead of at zero seconds...

@eifinger
Copy link
Contributor

This is really odd. It never comes close to the 10s timeout. Do your requests in HA always time out or just "sometimes"?

@mathmaniac43
Copy link
Author

The HA timeouts are consistent, every single time using the addresses I provided. I have no idea what's causing it to time out at this point...

@eifinger
Copy link
Contributor

Can you run my original script again but use the addresses from your modified example? address_to_coords is called automatically by pywaze when it does not detect coordinates in start or end.

Maybe this yields different responses....

@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants