Add the official speedtest cli

The current speed test sensor is giving really bad results recently so I installed this. I am running a Pi4 off SSD so have Hassio running under buster and I installed this last night per these commands

sudo apt-get install gnupg1 apt-transport-https dirmngr
export INSTALL_KEY=379CE192D401AB61
export DEB_DISTRO=$(lsb_release -sc)
sudo apt-key adv --keyserver --recv-keys $INSTALL_KEY
echo "deb ${DEB_DISTRO} main" | sudo tee  /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
sudo apt-get install speedtest

It runs great from within putty but I am having trouble getting the command line sensor to parse the json data to use

[email protected]:~ $ speedtest --f json-pretty
    "type": "result",
    "timestamp": "2020-01-19T13:01:56Z",
    "ping": {
        "jitter": 2.601,
        "latency": 12.276999999999999
    "download": {
        "bandwidth": 26542566,
        "bytes": 295601960,
        "elapsed": 11509
    "upload": {
        "bandwidth": 2614214,
        "bytes": 10224328,
        "elapsed": 3907

- platform: command_line
  name: Speedtest
  command: 'speedtest --f json-pretty'
  value_template: '{{[0].bandwidth| multiply(0.00762939453125) | round(2) }}'
  scan_interval: 1800

Anyone have any ideas how to get the “download.bandwidth”, “upload.bandwidth” to parse any usable data - would be much appreciated ?

1 Like

I didn’t get that far myself. I’m running HA in docker and didn’t really know how to make it run the speedtest.

Just run each command in turn then the final speedtest command. If I can sort out the json then I will bin the main integration.

I think my issue is that I don’t know how to install the package inside the docker container, or figure out how to run a command outside the container, from inside it. But I might be missing something…

If you can ssh into whatever you are running then you just run the commands. What are you running?

I guess I can ssh, just not sure how exactly to construct the command with username and pw.

I am running my main HA in docker on Debian 10 on an old Intel NUC.

Just installed the cli on a Pi also, running hassbian, to look at the json parsing.

Try this:

value_template: "{{['bandwidth'] }}"

There is no username or password for speedtest.

I’ll try your command later - just added a new one to see if that works.

Still no luck. With all settings I am not getting any data in the logs. Wonder if the command line sensor will wait long enough for the test to complete. Timeout is enough time for the test to complete.

- platform: command_line
  name: Speedtest
  command: 'speedtest --f json'
      - bandwidth
  value_template: '{{ | multiply(0.00762939453125) | round(2) }}'
  scan_interval: 1800
  command_timeout: 20
  unit_of_measurement: Mbps

When speedtest is executed the first time is prompts for two license acceptances. I opened a terminal as the homeassistant user and accepted the terms before the command worked for me.

I have only seen that once.

Have you been able to run the command from within HA and get some data back?

I keep trying but struggling to get anything - always shows unknown and the logs show empty data errors.

Yes after that it worked.

Please share your config :grinning:

Open a terminal, change to the homeassistant user, run the program and accept the two license agreements:

[email protected]:~ $ sudo -u homeassistant -H -s
[email protected]:/home/pi $ speedtest --f json-pretty


- platform: command_line
    name: Speedtest
    command: "speedtest --f json-pretty"
    value_template: "{{['bandwidth'] }}"
    command_timeout: 30
    scan_interval: 1800




I think my issue is related to running Hassio in docker - think it’s an access issue outside of docker that stops the command from running properly. Even using your code I still get nothing back.

I tried running the command as a shell command so that I could pipe the speedtest command and accept the terms and conditions but that didn’t work either.

Shame that the current sensor gives me a result about 50% lower than the CLI command gives.

Glad you got it sorted.

Well I have the same issue on my main HA which runs in docker. This was just a test on a rpi I also have running hassbian.

I tried running console commands in portainer but they would not work. If I run the command speedtest, which uses the built in version, that runs slow as well. Think the main integration needs to be updated. Will raise an issue tomorrow if there isn’t one already.

I use hassio on an RP3 and have the same problem with
I tried the test with the ethernet port and a gigabit usb adapter, but the download remains below 50 mbit/s (for comparison: i reach 200 mbit/s with my notebook). Can’t test the hint with the terminal and command line, because of hassio (=no hassbian).

The Pi3 shares the ethernet port with USB so it will be slower than FE (100mbit) speeds. The 3B+ can go higher and I was getting the full 200mbit of my connection up to about 3 months ago before it started playing up. My new Pi4 has the same issue so I use the integration for my download speed and the Speedtest integration for upload and latency.

1 Like