Speedtest CLI by Ookla - Internet Up-/Downlink Measurement Integration

I had exactly the same issue as yours :slight_smile:
After upgrade from OH 2.5 to OH 3 I have decided to do some cleanup and removed /var/lib/openhab2 folder.
After some digging it turned out that speedtest app is using openhab user’s home directory which was not changed during the upgrade process.
It is set in /etc/passwd

So you need to change home directory to /var/lib/openhab (remove “2”) and restart the system.
After that speedtest should work without a problem. At least it works in my case.

I hope it can help someone with this kind of problem :slight_smile:

hello,
I tested it. can it be that it doesn’t work with opnehab 3? i can’t get it to work. I have a fresh installed OH3 on debian.
It stucks on “Messung läuft” status. Where can I check whether the measurement is really running?
“visibility” doesn’t work anymore on OH3? It’s still included in the instructions

I have a problem,
When I run the speedtest command via cmd in Windows 10 then I get speed 950D & 105U
and when I run a speed test through openhab then I get less than 200D

1 Like

I have the same issue - when speedtest is executed on openhabian, the download result is always about 5x slower than what is shown if I run the test directly from speedtest.net or any other device. Running direct in a browser or other device sees download sitting at around 120.

Openhabian (I’m still on openhab2) is running on a pi3, so download is always going to be capped at around 100mb (or slightly less), but the result through this tool show download speed at about 20. I run a rule every 3 hours and occasionally one execution will shown download at over 90 down.

Ping also seems higher using this tool, but weirdly upload seems to be unaffected.

You have to be aware of many things here:

  1. the most important one: only RPi4 uses “true” gigabit ethernet
  2. results may vary, regarding on load of device and your infrastructure

ad 1)
please be aware, that only RPi4 uses a gigabit ethernet card on th SoC, which allows (theroretically) “full 1000Mbit”. In real life, the bandwidth is also dependend on other things going on inside the Raspberry Pi.
Your RPi3 (if it’s model B+) can at best use a gigabit ethernet “over USB”, which means, it’s still limited to about 300Mbit. But seeing you’re speed capped at about 100Mbit, my bet is on a RPi3 B only :wink:
if you’re using speedtest via Wifi, you get all kinds of stuff - but nothing reliable

ad 2)
based on how your network is built and which components you have at hand, this one could also be a pretty serious bottleneck. e.g. even if you used Cat5/6/7 cables and true gigabit switches and stuff, they still may not deliver true gigabit, depending on how you crimped the cables or how they’re bent in the curves, which patch cables you use, etc.

That said: the best way to get a “true” bandwith test is to

  1. disconnect each and every network client, be it wifi or LAN
  2. directly connect your RPi4 to your router - with a vanilla raspbian lite running only speedtest CLI

if you run your typical setup in parallel, you’ll always use up bandwidth from your mobiles, your SmartTVs, your Alexas, … :wink:

I would be interested to hear how this binding works for you then

[speedtest] Binding for Ookla’s Speedtest - Initial contribution by bigbasec · Pull Request #9913 · openhab/openhab-addons (github.com)

Hello,

i get a Error Massage at command “sudo apt-get update”

Err:10 https://ookla.bintray.com/debian buster InRelease
403 Forbidden [IP: 52.38.32.109 443]

Access to the server is not permitted.

> ## If migrating from prior bintray install instructions please first...
> # sudo rm /etc/apt/sources.list.d/speedtest.list
> # sudo apt-get update
> # sudo apt-get remove speedtest
> ## Other non-official binaries will conflict with Speedtest CLI
> # Example how to remove using apt-get
> # sudo apt-get remove speedtest-cli
> curl -s https://install.speedtest.net/app/cli/install.deb.sh | sudo bash
> sudo apt-get install speedtest

At
curl -s https://install.speedtest.net/app/cli/install.deb.sh | sudo bash

then i get the following Error

This distribution version is not currently supported via package management, please use the direct download builds per architecture found at Speedtest CLI - Internet connection measurement for developers

Did you follow all steps prior to the curl command?

I installed a completely new installation of OH3 (Openhabian on Raspberry 4B) and therefore did not install a speedtest-cli

Then I am out of ideas, sorry

Bintray repo is not working for some time now.

On that page: Speedtest CLI - Internet connection measurement for developers you can download executable for speedtest.
(for RPI: https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-armhf-linux.tgz)

Second option I have found is:

You can download deb or rep to install speedtest.

This caused me some pain after upgrading from 2.5 straight to 3.1, both installs using openHABian. Several things have changed since the OP. I hope I’m not duplicating too much, I couldn’t find much of this spelt out. For the benefit of others, what I needed to change is below.

A fresh openhabian install did not include speedtest-cli. I followed the uninstall commands in the OP anyway, but this did nothing. The official install from Ookla has changed somewhat. They now reference the package at packagecloud, linked by kristofejiro above. I followed the speedtest.net instructions but needed to make a modification. If you’re uncomfortable running a shell script downloaded blindly (you probably should be), as the instructions suggest, there’s also step by step instructions.

The file in

/etc/apt/sources.list.d/ookla_speedtest-cli.list

needs to contain the following line for apt to find the package (replace “raspbian” with “debian”, and assuming you’re using “buster”):

deb https://packagecloud.io/ookla/speedtest-cli/debian/ buster main

Then run at the prompt:

sudo apt-get update
sudo apt-get install speedtest

Now that speedtest is installed, run it with following command to accept the license and then again to make sure the output comes back as json

sudo -u openhab speedtest
sudo -u openhab speedtest -f json

In the speedtest.rule make the following changes. It is [documented that the executeCommandLine syntax has changed in OH3 (sorry, aren’t allowed too many links). Each parameter needs to be in quotes and separated by a comma. And the timeout needs to be the first parameter. There’s probably a better way to write this rule now with different rule engines, but the simplest way (minimal changes) to get the OP’s rule working is to change just a part of the “speedtest” rule to:

    // execute the script, you may have to change the path depending on your system
    // Please use -f json and not -f json-pretty
    //val speedtestExecute = "speedtest -f json"
    var speedtestCliOutput = executeCommandLine(Duration.ofSeconds(120),"speedtest","-f","json")

    // for debugging:
    // var String speedtestCliOutput = "Ping: 43.32 ms\nDownload: 21.64 Mbit/s\nUpload: 4.27 Mbit/s"
    // logInfo(ruleId, "--> speedtest output:\n" + speedtestCliOutput + "\n\n")
    SpeedtestRunning.postUpdate("Crunching Results...")

    // starts off with a fairly simple error check, should be enough to catch all problems I can think of
    if (speedtestCliOutput.startsWith("{\"type\":\"result\","))

It’s a bit embarrassing, but I gave up trying to make the && operator work in xtend. It used to work, but now doesn’t seem to. I gave up and now the if statement just uses one condition.

I added “speedtest” to the exec.whitelist, but this doesn’t seem to be required, so I pulled it out again.

I had the time to implement the speedtest in my oH 3.1 environment yesterday and will update the post later today.
I updated the OP to comply with the changes introduced by oH 3.

I´m not running this solution anymore and switched to the binding made by @bhomeyer based on this tutorial.
On top i´m using the remote openHAB binding to connect my raspberry Pi 4 main instance to my speedtest VM.
I spend some time to found a solution to download the speedtest result image from the url returned and store it into an item.
I´m now able to not only send a Telegram message when the Down-/Upload goes under a predefined value but also send me the result image :smiley:
I´ll share this solution in another thread.

@KidSquid could you please check your Windows part and what needs to be changed for oH 3?

Could you pleas double check that?
It´s not working with this syntax :slight_smile:
Do you mean sudo -u openhab speedtest?

Yes, sorry, it is: sudo -u openhab speedtest. I’ve edited my post above.
Thanks very much for modifying the OP. Hope this saves someone else an afternoon :slight_smile:

Hi, i´m on openhab 2.5 and i changed from old speedtest to the new one:

I get 2 error messages:

{
“resource”: “/etc/openhab2/rules/speedtest.rules”,
“owner”: “generated_diagnostic_collection_name#1”,
“code”: “org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types”,
“severity”: 8,
“message”: “Type mismatch: cannot convert from BigDecimal to float”,
“startLineNumber”: 65,
“startColumn”: 16,
“endLineNumber”: 65,
“endColumn”: 29
}

This two parts in my rules-file are the lines from the error messages:

 var float down = Float::parseFloat(transform("JSONPATH", "$.download.bandwidth", speedtestCliOutput))
        down = (down / calc)
        SpeedtestResultDown.postUpdate(down)

        var float up = Float::parseFloat(transform("JSONPATH", "$.upload.bandwidth", speedtestCliOutput))
        up = (up / calc)
        SpeedtestResultUp.postUpdate(up)

Any idea?

Hi Stefan,

how did you install speedtest? I get the following error when I try to install as per Speedtest CLI: Internet speed test for the command line.

openhabian@openhabian:/ $ sudo apt-get install curl
[sudo] password for openhabian: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.74.0-1.3+deb11u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
openhabian@openhabian:/ $ curl -s https://install.speedtest.net/app/cli/install.deb.sh | sudo bash

This distribution version is not currently supported via package management, please use the direct download builds per architecture found at https://www.speedtest.net/apps/cli

br
a

Then try to do what is in the last line of your code :slight_smile:

It will be this file probably:

https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz