alias: Speedtest
description: Speedtest @ 1am
trigger:
- at: '01:00:00'
platform: time
condition: []
action:
- service: speedtestdotnet.speedtest
mode: single
This runs fine when clicking “run actions” and a speedtest is performed, when left to run on its own it fails with the below error and I have no idea why
Unexpected error fetching speedtestdotnet data: Unable to connect to servers to test latency.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/speedtest.py", line 1489, in get_best_server
fastest = sorted(results.keys())[0]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 151, in async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 139, in _async_update_data
return await self.update_method()
File "/usr/src/homeassistant/homeassistant/components/speedtestdotnet/__init__.py", line 174, in async_update
return await self.hass.async_add_executor_job(self.update_data)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/speedtestdotnet/__init__.py", line 162, in update_data
self.api.get_best_server()
File "/usr/local/lib/python3.8/site-packages/speedtest.py", line 1491, in get_best_server
raise SpeedtestBestServerFailure('Unable to connect to servers to '
speedtest.SpeedtestBestServerFailure: Unable to connect to servers to test latency.
Have you tried setting automatic updates in the integration?
Having said that this has been flakey lately I have found. 2021.3.4 seems better and my issues started in 2021.3.3
You can also try changing the schedule so it doesn’t run on the hour (for example, change the trigger to run at 01:02:00). I’ve found that running right on the hour causes the automated job to fail, presumably because there’s too many people doing the same thing.
In the integration you set an update interval and for me it seems to not run on an even minute however if you use an automation probably a good idea.
I haven’t seen any issues for the last fed days now…
Just created an account here as this is the first place where i find this problem mentioned. I am running speedtest.py automated from crontab on raspberry. I see the same error as the OP, but only if triggered by CRON. Running speedtest manually (either speedtest.py, or from the script pushing this into a google spreadsheet (https://github.com/frdmn/google-speedtest-chart)) works just fine - every single time.
Last time it ran well was 8 March, 20:00 CET - i can only see manual runs since then.
speedtest.py is executing just fine (even from chrome) - just like in the OP.
my guess is, that either populating the server list, pinging servers or sorting by ping fails when triggered from cron (hence the index [0] points to nothing)
Not sure how to find out if populating the server list works when triggered from cron - or how this could be affected by being run by cron.
yes, it worked just fine for a couple of weeks - and i only realized that it had stopped because the chart did not update any more. No touch to the system that i can think of.
In the actual speedtest.py file, there’s a DEBUG flag you can change from False to True and that should dump all the info when it runs, including server selection and whether the list was empty. I’d definitely check permissions as @DavidFW1960 suggested, and otherwise play around with scheduling offsets if you haven’t already (just mentioning again in case you missed my earlier comment).
I have similar issues. No problems until very recently. For example I restarted HA about 20 hours ago. With no changes, it stopped working 12 hours ago (Config=AutoDetect and refresh every 30 minutes)
forcing an update by calling the service from the GUI a) ran, b) seems to have unlocked it.
Right now I cannot select any German servers. They disappeared from the list. All countries with starting with D, E, F, G are missing. Anybody can confirm this?
Thanks