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

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

Hi,
thanks for this.

I have an error and i don’t see the problem :frowning:

2022-01-18 10:45:29.629 [ERROR] [.openhab.core.model.script.Speedtest] - --> speedtest failed. Output:
{"type":"result","timestamp":"2022-01-18T09:45:29Z","ping":{"jitter":2.948,"latency":13.353999999999999},"download":{"bandwidth":67932065,"bytes":907303768,"elapsed":15005},"upload":{"bandwidth":5883783,"bytes":37594424,"elapsed":6413},"packetLoss":0,"isp":"Vodafone Germany Cable","interface":{"internalIp":"192.168.230.10","name":"eth0","macAddr":"9E:EA:51:22:9A:90","isVpn":false,"externalIp":"95.91.30.83"},"server":{"id":38032,"host":"speedtest.drahtlos-dsl.de","port":8080,"name":"Drahtlos-DSL GmbH Mittelsachsen","location":"Leipzig","country":"Germany","ip":"94.100.70.2"},"result":{"id":"1d3bfc6f-3a83-4df7-a966-47004dc21c3f","url":"https://www.speedtest.net/result/c/1d3bfc6f-3a83-4df7-a966-47004dc21c3f","persisted":true}}

Anyone see the problem?
Greets

I found the place with the error, but do not understand the problem :frowning:
I changed the rules and now it works.

    if (speedtestCliOutput.startsWith("{\"type\":\"result\",")) //&& speedtestCliOutput.endsWith("}}"))```

Hi
thx. I am not an expert. I run openhabian on a RasPi4. I have no idea where to put these files then and what to do. If I got it right, you suggest there “armhf” config. OK. I have downloaded the files to my Mac. I can put it to my Rapsi…where? And what next?

You can put it in folder of your choice (e.g. home folder)
Then decompress it and copy speedtest executable file to /usr/bin/

Thx a lot @kristofejro - I can start speedtest now from the command line. Now I need to get it into OH3…which I realise is a challenge as there is no binding, and I dont know how to create a THING without a binding…but I am searching;)

I think a search is not required … Just look into the first post in this thread.
You have the speedtest linux client executable that needs to be called from within a rule and will assign values to your items. Items definition are also in the first post.

There´s a working binding available.

Just create the items. Thing is not required here. Just as it is in the first post.

@Alexollon just keep in mind that this binding is not officially supported (not included in official bundle) and its installation have to be done manually and not via GUI.