Speedtest server ID

As @fanuch mentions below, you are still able to configure via configuration.yaml

Documentation shows server_id. Does that not work?

That’s how i was using speedtest in the past to measure my ping to the closest/fastest server. Few weeks ago speedtest integration stopped working, i have looked on the forums and found an advice to move from YAML config to UI configuration. I have done and indeed it’s working when configured in the UI, but i cannot choose same server anymore. I have assumed that YAML config for speedtest is being deprecated/no longer maintaned, similarly to many other intergrations.

Don’t know what to tell you. The source code still uses the server_id from the configurations. It’s available for anyone to have a look at.
The last change was 12 days ago (from today) to add the sever list, but did not change the server_id.

To be honest, without sharing your configurations, anyone would be guessing.


*Edit

Decided to do some quick testing of my own and here’s my analysis…

  • When you first add the integration, or the first time after an update that has the integration, there is a separate configuration that gets added somewhere.
  • On reboots this separate configuration exits
  • On server_id changes, the integration overrules the manual configuration
  • If you delete the integration and reboot, only then does the server_id get loaded in again

Looks like you’re correct @dinth that it’s “broken” in the sense that updates don’t change anything.

1 Like

This is an issue for me where the server that I want to test against doesn’t show up in the dropdown in the GUI configuration either for some reason.

I have server_id configured in the config yaml but it doesn’t get used.

2 Likes

I’ll mention a setup I did several months ago (so I may have forgotten some of the details) which maybe rather more complicated than it should be, but something you may be able to use.

In essence I use a python script that calls a speedtest binary developed by OOKLA called Speedtest CLI. The python script uses the server-id of my choosing. I call the script (using HA shell command) whenever I need it to run it using an automation. The script parses the returned values from the binary and in turn calls the HA APIs (using tokens) to update the Speedtest sensors. The Speedtest sensors are setup using the normal HA Speedtest integration, but I have it configured for manual mode, which means the integration doesn’t update the sensors (except maybe at startup time?).

The reason I did this was because I found that the HA Speedtest integration’s test results were highly inaccurate, whereas the binary has about the same result as running the SpeedTest App on Windows.

If one of OOKLA’s binary can run on your machine, then this approach will work for you.

Sounds like a good approach as a workaround. I’ve noticed that the results aren’t as accurate for higher bandwidth connections for the python speedtest library compared to the official speedtest cli even when I am using the same servers.

Any chance you could share your config and script in some form?

Sure. Hope this helps.

4 Likes

Thanks for sharing this!

Not sure where I’m going wrong, but I can’t for the life of me get this to run from a shell_command.

It works great when running from the terminal, but just get an error when executing the shell_command service. (return code: 127)

shell_command:
  launch_speedtest_cli: /config/shell_commands/launch_speed_test.sh

I’ve tried with and without /config/ but still no dice. Any thoughts? I’m running HassOS

Edit:
After further investigation, it definitely looks like it’s an issue with the path, I’ve tried many different configurations, but can’t seem to nail it down.

2021-01-14 17:07:50 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `/config/shell_commands/launch_speed_test.sh`, return code: 127:
b'/bin/sh: /config/shell_commands/launch_speed_test.sh: not found\n'

I was able to get this to work…didn’t realize there are a few other differences with HassOS.
Here is what I did:

  • The Python3 path is different /usr/local/bin/python3. Edit the first line of both the launch_speed_test.sh and the speedtest-cli-2ha.py to have the path /usr/local/bin/python3
  • Path to the speedtest files is /config/shell_commands/ so change the 2nd line in the launch_speed_test.sh file to account for this and in the speedtest-cli-2ha.py change the SPEEDTEST_PATH to /config/shell_commands/speedtest.bin
  • The URL to reach homeassistant can NOT be http://homeassistant.local. However http://homeassistant works fine.
1 Like

Appreciate the help!

I made the changes, however when I run manually I receive the error:

./speedtest-cli-2ha.py: bad interpreter: /usr/local/bin/python3: no such file or directory

I looked and my python3 is located at:

/usr/bin/python3

Oh that’s interesting! As a check, did you go inside the homeassistant container from hassos command line to find your python3 path?

I’m using the SSH & Web Terminal add on and navigating from there. I believe that’s the homeassistant container right?

In my case the ssh/web terminal takes me to the ssh addon container and in my case this container doesn’t have any python code

Update: Problem solved!

I wasn’t able to ever get the .sh file to execute from HA for some reason, but I was able to call the .py direct and it works great.

I kept your suggested changes and the shell_command path that finally worked for me is:

shell_command: #Starting 0.114, command timesout after 60s.
  launch_speedtest_cli: "/usr/local/bin/python3 /config/shell_commands/speedtest-cli-2ha.py"

Thanks again for sharing and helping me get this going!

Many thanks for your work and inspiration. I’ve made it a bit simpler - only the python script exists which is called directly from HA command_line sensor. It populates the state and additional attributes based on output in json format made by the script. Here is my fork of your repo:

Looking forward to any comments, especially explaining why I should not do it this way :slight_smile:

Glad I could inspire :slight_smile:

Thanks a lot for your help.
Do you have any idea how can i decrease the number of digits after the decimal point ?

Thanks a lot

I have a few questions.

  • Where do you find your HA token which they ask for in speedtest-cli-2ha.py?
  • I can’t find python anywhere when I use ssh in the terminal and go to the different locations. Even doing a “which python” or “python -version” returns that python doesn’t exist. Is it “hidden” as a Home Assistant install and not seen as python the app itself? OR do I need to install it?
    I’m running Home Assistant on a Raspberry Pi 4.

Thanks.

Oh also, @jmart518 you said it wasn’t in usr/local/bin but then you say to use usr/bin.
So where you wrong the first time around?

You need to use | round (0) when defining your states.
I usually just redefine states.

- platform: template
  sensors:
    speedtest_download_rd:
      friendly_name: Speedtest Download Rounded
      unit_of_measurement: Mbit/s
      value_template: "{{ states('sensor.speedtest_download') | round(0) }}"