Add the official speedtest cli

Thanks for that. I’m on Rpi 4 so executed the command chmod +x speedtest using Terminal, which changed the file attributes to include executable, but this made no difference to the errors. The HASS Core error log shows the following:

TemplateError('JSONDecodeError: unexpected character: line 1 column 2 (char 1)') while processing template 'Template("{{ (states('sensor.speedtest_cli_data') | from_json).ping | round(2) }}")' for attribute '_attr_native_value' in entity 'sensor.speedtest_cli_ping'
12:13:21 PM – (ERROR) helpers/template_entity.py - message first occurred at 12:13:21 PM and shows up 3 times

Error while processing template: Template("{{ (states('sensor.speedtest_cli_data') | from_json).ping | round(2) }}")
12:13:21 PM – (ERROR) helpers/template.py - message first occurred at 12:13:21 PM and shows up 3 times

Command failed (with return code 2): /config/3rdparty/speedtest/speedtest --format=json --accept-license --accept-gdpr
12:13:10 PM – (ERROR) command_line

After a bit of research I thought the unexpected character could be double quotes in the command line, so I replaced these with a single quotes but it made no difference. If I try and execute the command under terminal I get the error speedtest: command not found, but I have the three files shown in the right directory.

Another issue this seems to create (even after a reboot, after removal of all files and config) is the HASSOS File Editor no longer displays any files under \config directory. The files are still visible on a network Windows PC, and can be accessed using File Editor “history” button if used recently.

I’m traveling on vacation, will verify in two days if you can wait if not figuring it out.
Test running just the speedtest commandline to verify it is at least running.

Thanks again, I’ll keep playing and see if anyone else has some hints. Typing speedtest at the commandline (in \config\3rdparty\speedtest directory) also fails with a command not found error. Three files are there: speedtest, speedtest.5, and speedtest.md.

As a check, if you downloaded the speedtest binary for x86_64, that is for an Intel platform and I don’t think that will work on an RPi 4. You’ll need one of the ARM binaries (not sure which one).

UPDATE: Looking at this link, you’ll probably need the aarch64 binary

Ahhh, thankyou…the x86_64 extension in the filename is definitely a hint isn’t it! I’ve downloaded the aarch64 binary from Speedtest CLI: Internet speed test for the command line and extracted it, then set it as executable.

Maybe a really dumb question, but what’s the syntaxt to test / execute the commands within the Terminal app at the CLI? I get a “speedtest: not found” error or “speedtest: command not found” error. I worked it out; needed to rename the file adding a .bin extension then execute using ./speedtest.bin.

Thanks to everyone for their assistance, I have it working on my RPi4 now. Summary of steps I used (for others on same platform, assume you have Terminal installed and Samba for a connected Windows 10/11 PC, with a drive mapped for \config):

On PC:

  1. Download compressed .tgz image from Speedtest CLI: Internet speed test for the command line, which for the RPi4 is under “Linux download / aarch64”.
  2. Open image (content is a .tar file).
  3. Connect to your HASSOS RPi, and under \config create folders \3rdparty\speedtest.
  4. Extract .tar file contents (3 files, speedtest.*) to the new directory \config\3rdparty\speedtest .

On HA, use Terminal:

  1. I had to make speedtest executable using chmod +x speedtest .
  2. Execute speedtest (to accept licences, typing “YES”) using ./speedtest .

Using HA File Editor, add all YAML config as shown in @ptr727’s post above Add the official speedtest cli - #27 by ptr727.

Lastly, restart HASSOS then add the new entities (I use dashboard option to locate “Unused entities”) to a card.

3 Likes

Glad you got it working, I updated my post with more details on how to download and extract the binary, and to pick the right platform.

Thank for your solution, it’s working great for me. I do have questions:
How to get the value for the server id and the last time of execution.
I’m also trying to get speedtest on demand working using a call-service link to this

shell_command:
   launch_speedtest_cli: /config/shell_commands/speedtest --format=json --accept-license --accept-gdpr

it seem to call the service but doesn’t update the sensors

  json_attributes:
    - 'download'
    - 'upload'
    - 'server_name'
    - 'isp'

- sensor:
  - name: Speedtest Download
    state: '{{ state_attr("sensor.speedtest_ping", "download") | round(2) }}'
    unit_of_measurement: Mbit/s
  - name: Speedtest Upload
    state: '{{ state_attr("sensor.speedtest_ping", "upload") | round(2) }}'
    unit_of_measurement: Mbit/s

In sensor, how to get a sensor for

    - 'server_name'
    - 'isp'

Thank you

Here it is:

  - name: Speedtest ISP
    state: '{{ state_attr("sensor.speedtest_ping", "isp") }}'
  - name: Speedtest Server Name
    state: '{{ state_attr("sensor.speedtest_ping", "server_name") }}'

Thank you,
That work perfectly but both return values were the same so I had to change a line in:
Speed Test Results - (from returned JSON string)
FROM: server_name = st_results[“server”][“name”]
TOL server_name = st_results[“server”][“location”]

ISP is your internet provider and server name is the one you are using to test the speed. Some providers also host speedtest servers so might be the same in your case.

In case anyone is interested I’ve created a wrapper to run official speedtest.net cli and post results to HA via MQTT with auto discovery. No configuration on HA side needed.
https://hub.docker.com/rep…/docker/adorobis/speedtest2mqtt
and here the repo:
https://github.com/adorobis/speedtest-CLI2mqtt
Feel free to comment and contribute :slight_smile:

2 Likes

Thanks for sharing it helped a lot

This looks promising. I need to run it on a different box that has a faster nic then my HA setup, how can I send the results to mqtt on my HA box?

n/m figured it out. Thanks, this is awesome!

1 Like

Ok, I’ve managed to install the docker container via Portainer and its running but how do I call the test to run from within HA ? Do I need to call a Python script to get it to run ?

Just came across this as I was looking to do the same! Thanks for the good work - it works flawlessly!

mb

1 Like

You don’t call it, you have to configure the parameters of your mqtt broker in the config.ini file as well as some other parameters and it will run at the frequency you specify. See some example file in the repo:

1 Like

Thank you, All sorted now.

Would that be worth adding to your GH repo to advise others ?

1 Like