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.