Speedtest-cli Internet Up-/Downlink Measurement Integration

yes is installed.
should i do ther anything withe the exec binding?

I installed via the easy_install method - how do I uninstall it?

You should check the easy_install documentation on that.

For anyone coming to this thread having issues getting this to work on Windows, here are some tips:

  • download v1.0.4 of the speedtest utility from here:
    https://github.com/zpeters/speedtest/releases
    The newer v2.0 that is available doesn’t have a ‘-r’ (“report”) command line argument option, so the output , while it looks nice in a window, is not formatted for easy parsing, and won’t match what the above-provided .rules code is expecting. Unless you are awesome at parsing strings in the OH rules code, you will cost yourself a lot of time and head-banging-against-wall.

  • Your executeCommandLine line should include the -r option discussed above:

var String speedtestCliOutput = executeCommandLine("C:\\path\\speedtest-v1.0.4.exe -s xxxx -r", 120*1000)

(my above line also includes a -s command line argument, which allows you to specify a consistent server against which to run the speed test, which I think should make for more consistent results?)

  • the if statement when starting to analyze results needs to be changed to check for "202" instead of "201". This was not initially obvious to me, but that statement is intended to check for an output line that starts with the current year/decade, since the entire output starts with a year-prefixed datestamp, i.e.:
    2020-02-17 02:13:43 -0600|xxxx|"<your server location here>"|29.96|62532|6319
    So if your previous code stopped working on January 1st, that’s probably why :slight_smile:
2 Likes

I am running openHab within docker on a Synology NAS.
In addition to the openHab container I installed the container from tianon to be able to execute the speedtest-cli.

I am afterwards able to run the speedtest using a terminal ssh session:

someguy@DS918plus:/usr/local/bin$ sudo docker run --rm --net=host tianon/speedtest
Password:
Retrieving speedtest.net configuration...
Testing from Deutsche Glasfaser Wholesale (xxx.xxx.xxx.xxx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by myLoc managed IT AG (Dusseldorf) [27.70 km]: 14.842 ms
Testing download speed................................................................................
Download: 329.80 Mbit/s
Testing upload speed......................................................................................................
Upload: 88.96 Mbit/s

But how should my rules file look like with the executeCommandLine(…)?

Did anyone tried to use the official speedtest cli from https://www.speedtest.net/de/apps/cli
It seems like the speedtest-cli from Sivel is not made for speeds over 400 Mbit/s.
Atleast for me the speedtest-cli almost never reaches the full speed while a measuring from the same host with speedtest net works fine.

Edit: I was able to get the rule running with the official speedtest cli and will create a new thread.

Edit2: I created a new thread for the Speedtest CLI by Ookla measurement

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:

        https://www.speedtest.net/about/eula
        https://www.speedtest.net/about/terms
        https://www.speedtest.net/about/privacy

==============================================================================

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":"192.168.1.3","name":"enp2s0","macAddr":"04:D9:F5:89:28:F3","isVpn":false,"externalIp":"180.150.42.98"},"server":{"id":6355,"name":"AARNet","location":"Sydney","country":"Australia","host":"nsw-brwy-speedtest.aarnet.net.au","port":8080,"ip":"182.255.120.11"},"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"
when
	Time cron "38 */30 * * * ?" or // every 30 minutes
    Item Speed_Run received command ON
then
	if(Speed_Run.state == OFF) {
		Speed_Run.postUpdate(ON)
	}
    // 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")
	Speed_Ping.postUpdate(Float::parseFloat(ping))
	Speed_Down.postUpdate(downNum)
	Speed_Up.postUpdate(upNum)
	logInfo("+++ NETWORK", "--> speedtest finished.")
    Speed_Run.postUpdate(OFF)
end
// ******* Connection Speedtest END ******* //