Speedtest-cli Internet Up-/Downlink Measurement Integration

Hello my speedtest says this in log :

21:45:02.637 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestRunning changed from Measurement in Progress... to Data Analysis...
21:45:02.638 [ERROR] [ipse.smarthome.model.script.Speedtest] - --> speedtest failed. Output:

You may only use this Speedtest software and information generated
from it for personal, non-commercial use, through a command line
interface on a personal computer. Your use of this software is subject
to the End User License Agreement, Terms of Use and Privacy Policy at
these URLs:



To accept the message please run speedtest interactively or use the following:

    speedtest --accept-license

the speedtest.exe file runs without any problem on the pc and have admin rights

do anybody know what is wrong ?? i have tried different versions boath v2.0 and v1.4

im on Openhab version snapshot 2.5.3 so mabye its the ? exec.whitelist
what to right ? , i have the misc / exec.whitelist ,but it`s emty.

What CLI are you using? The one from this thread or the one from Ookla?

i tried both but none off them i workinig for me :frowning:

The problem in your last error is the missing acceptance of the GDPR and license agreement.
You need to accept both with the user you‘re using to run the speedtest from your oH instance.

do you know how on windows ? to do that ,the exe file runs fine all to the end both as admin and as user is that it ? and i was asked to write YES both times

Have a look at this example

Speedtest is hilarious

I run from the SAME machine speedtest-cli, and I get 16megabits upload

When it runs in a rule, I get 2mbits to the same server!

Please have a look at my solution to use the Ookla Speedtest CLI instead.

1 Like

Thank you

I get the following error, I had to add --accept license in the var for the command too but it seems to work which is odd :slight_smile:

Thanks for your work on this tutorial, its great!!!

10:26:32.225 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestRunning changed from Measurement Running... to Data Evaulation...
10:26:32.229 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestResultPing changed from 5.902 to 5.964
10:26:32.230 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestResultDown changed from 50.77056800 to 49.37103200
10:26:32.230 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestResultUp changed from 18.20844000 to 12.39939200
10:26:32.231 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestSummary changed from ᐁ  50.8 Mbit/s  ᐃ 18.2 Mbit/s (6 ms) to ᐁ  49.4 Mbit/s  ᐃ 12.4 Mbit/s (6 ms)
10:26:32.231 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestResultDate changed from 2020-10-22T23:24:05.000+0000 to 2020-10-22T23:26:32.000+0000
10:26:32.231 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestResultImage changed from https://www.speedtest.net/result/c/bc0bbad3-62a1-4fd1-b5ae-e2413034f785.png to https://www.speedtest.net/result/c/916160a8-21e5-439e-801b-9a8e3adf8149.png
10:26:32.232 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestRunning changed from Data Evaulation... to -
10:26:32.232 [INFO ] [smarthome.event.ItemStateChangedEvent] - SpeedtestRerun changed from ON to OFF
10:26:33.213 [ERROR] [ipse.smarthome.model.script.Speedtest] - --> speedtest failed. Output:
{"type":"log","timestamp":"2020-10-22T23:26:31Z","message":"Trying to get interface information on non-initialized socket.","level":"error"}
{"type":"result","timestamp":"2020-10-22T23:26:33Z","ping":{"jitter":0.432,"latency":87.745000000000005},"download":{"bandwidth":9566802,"bytes":127452960,"elapsed":15010},"upload":{"bandwidth":1257922,"bytes":8726656,"elapsed":6900},"packetLoss":3.6666666666666665,"isp":"Aussie Broadband","interface":{"internalIp":"","name":"enp2s0","macAddr":"04:D9:F5:89:28:F3","isVpn":false,"externalIp":""},"server":{"id":6355,"name":"AARNet","location":"Sydney","country":"Australia","host":"nsw-brwy-speedtest.aarnet.net.au","port":8080,"ip":""},"result":{"id":"118a79fa-8b6a-4e97-ba02-ebc01d0cf4b8","url":"https://www.speedtest.net/result/c/118a79fa-8b6a-4e97-ba02-ebc01d0cf4b8"}}
  1. copied speedtest.py in /etc/openhab2/automation/lib/python/personal
  2. rebooted openHAB
  3. copied your rule
    I get the error:
    2020-10-23 11:38:39.104 [ERROR] [jsr223.jython.SpeedtestPy           ] - Traceback (most recent call last):
      File "/etc/openhab2/automation/lib/python/core/log.py", line 51, in wrapper
        return fn(*args, **kwargs)
      File "<script>", line 67, in execute_speedest
    AttributeError: 'function' object has no attribute 'Speedtest'

line 67:

s = speedtest.Speedtest()

Can’t really help you, but i’d guess something wrong with the speedtest script or imports.

I have the same issue.
Where did you get the 1.0.2?

Never mind.
I use now this one, which works fine and supports json output:

@NCO: Could you please provide your .rules to have a look at json parsing from SpeedTest++?

Sure no problem:

// ******* Connection Speedtest ******* //
rule "Speedtest"
	Time cron "38 */30 * * * ?" or // every 30 minutes
    Item Speed_Run received command ON
	if(Speed_Run.state == OFF) {
    // update timestamp for last execution
    Speed_Date.postUpdate(new DateTimeType())
	var String output = executeCommandLine("/usr/local/bin/SpeedTest --output json", 90000)
	val String ping = transform("JSONPATH", "$.ping",output)
 	val String down = transform("JSONPATH", "$.download",output)
 	val String up   = transform("JSONPATH", "$.upload",output)
	val float downNum = Float::parseFloat(down) / 1000000
	val float upNum = Float::parseFloat(up) / 1000000
	logInfo("+++ NETWORK", "ping: " + ping + " ms / download: " + downNum + "Mbit/sec / upload: " + upNum + "Mbit/sec")
	logInfo("+++ NETWORK", "--> speedtest finished.")
// ******* Connection Speedtest END ******* //


no worries - that was easy :wink:

Will there be a version for OH3?
It seems that the rules are not running properly. Maybe there are some other issues too.

Just a shot in the dark and untestested (yet), but the executeCommandline option had some breaking change in openHAB 3.

Breaking changes in short:

  • Parameter order has changed
  • Timeout is now in secconds
  • Parameters don’t have to be separated with @@ anymore

So please test the following idea:

Take the example script part:

 // execute the script, you may have to change the path depending on your system
var String speedtestCliOutput = executeCommandLine("/usr/local/bin/speedtest-cli@@--simple", 120*1000)

and change the function paramaters as following:

 // execute the script, you may have to change the path depending on your system
var String speedtestCliOutput = executeCommandLine(120, "/usr/local/bin/speedtest-cli --simple")

Of course you should transfer any additions or changes you possibly made to this line yourself too. :slight_smile:


Please give some feedback if you have tested it and it works.
I will adapt the first post of this tutorial then.

1 Like

Thank you for that quick reply. I’ve tested your changes, but without success.
I’ve attached you a screenshot with the errors on the bottom.
It seems that there is a problem with the timeout parameter and the section where the string gets splitted into the different output string.

And that’s what the openhab.log says

2020-12-22 10:45:47.489 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘speedtest.rules’, using it anyway:
The constructor Float(String) is deprecated
The constructor Float(String) is deprecated
The constructor Float(String) is deprecated

Did you test the script while ignoring these error messages?
I would not wonder if the language server doesn’t know about this change too…