Speedtest-cli Internet Up-/Downlink Measurement Integration

OK, have figured out by myself I think :grin: No “Thing” and “channel” required as the rule itself updates the items directly. At least it gets reasonable results which are close to the ones started from command line.

Sorry for the bother. :flushed:

Would anyone be able to share some SVG icons?

Hey Tommy,
I’ve just updated the first posting for openHAB 2 and added a new archive file containing pngs and svgs.

2 Likes

installed it and worked flawlessly!!!

1 Like

I just set this up at home. Things seem to working as I’m getting what looks like accurate speed tests, but seeing a strange error in my log when I run it of:

2017-04-14 13:54:58.678 [INFO ] [arthome.model.script.speedtest.rules] - --> speedtest executed...
2017-04-14 13:55:01.633 [WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 12789210 failed: null
2017-04-14 13:55:01.634 [WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 12789211 failed: 

And can anyone tell me what “Statistics” on the sitemap should be doing or showing?. I just show the three dots, … Should that be going to graph or other?

The warnings you are seeing are yield by io.openhabcloud.internal.CloudClient, which is probably related to your myopenhab setup.

The three dots under statistics are just a placeholder for whatever statistics you want to generate out of your measurements over time (see persistence). My recommendation would be Grafana graphs, see InfluxDB+Grafana persistence and graphing

Great scripts, just a quick comment for future improvements: Lots of people use a switch item called Presence_anyone or similiar that indicates if someone is home or not, Its been discussed here to run it hourly or twice per day, So one idea is that we run it hourly(cron rule) but only if nobody is home(Presence_anybody.state ==FALSE)

rule "Speedtest"
when
    (Time cron "0 0 * * * ?" and Presence_anybody.state ==FALSE) or
    Item SpeedtestRerun received command ON
then

Just an idea…

3 Likes

Can you edit you orginal post to include this as an option with the link provided on how to do so in your tutorial.(Its superb btw, took less then 5 minutes to install, if you take away the fact that i had to install 7z to unzip rar)

1 Like

Hey Kim,
thanks for these comments!

That would be possible, although I’m not sure if it’s actually needed. I never saw any significant influences on speedtest caused by users. Do you?

The rule as you defined it would not work. There is no and operator for events. You need to do it similar to this:

rule "Speedtest"
when
    Time cron "0 0 * * * ?" or
    Item SpeedtestRerun received command ON
then
    if (Presence_anybody.state == FALSE) {
        ...
    }
end

I’m not sure if it’s meaningful to add this to the initial post.

Yes. Good idea… Done!

This is great, thanks!

I might extend it to restart my router if there is no external/internet connection

Hey, happy you like it!

As for your second idea, I think you’d be happier with a ping based solution.

Ping 8.8.8.8 every 5 minutes, if no response reboot router.

this approach is a bit lighter. I’m not sure if you want to run a speedtest every 5 minutes or wait one hour for your line to reconnect…?

I think “val” is a typo and schould be “var”?
Could you fix that if I am right?

and…
I think giving the startup-timer a name could be better. or?
e.g.

var Timer startup_Speedtest

rule "Speedtest init"
when
    System started
then
    startup_Speedtest = createTimer(now.plusSeconds(195)) [|
        if (SpeedtestRerun.state == NULL) SpeedtestRerun.postUpdate(OFF)
        if (SpeedtestRunning.state == NULL) SpeedtestRunning.postUpdate("-")
        if (SpeedtestSummary.state == NULL || SpeedtestSummary.state == "")
            SpeedtestSummary.postUpdate("⁉ (unbekannt)")
    ]
end

could you fix that also if applicable?

AND… thanks for this example… really nice… :slight_smile:

This is not a typo and is correct and appropriate as written. Use “val” when you have a variable that should never be reassigned. In this case filename is a constant so val is appropriate.

It’s unnecessary. The timer is never referenced again. It is never checked and never cancelled so there is no need to assign it to a variable. You can if you want to be it doesn’t do anything for you.

1 Like

yup thanks Rich :slight_smile:

@mboremski if you are interested check out:

i need to cheer for your willingness to contribute, not many do that. My examples are far from perfect and if you ever find room for improvement, shoot :wink:

2 Likes

Thanks, yes thats probably a better solution for checking more often.

And no, dont really want to run the speedtest every 5min :wink:

In fact, as I run Openhab on a Pi3 I might need to move the speedtest off openhab (still feed the data into the db) as it only has a 100mbit ethernet (I have, or should have, a 250/100 link).

Sorry, I’m just learning. Tell me please where to copy the code below?

Rule (Linux speedtest.rules)

val String filename = "speedtest.rules"

rule "Speedtest init"
when
    System started
then
    createTimer(now.plusSeconds(195)) [|
        if (SpeedtestRerun.state == NULL) SpeedtestRerun.postUpdate(OFF)
        if (SpeedtestRunning.state == NULL) SpeedtestRunning.postUpdate("-")
        if (SpeedtestSummary.state == NULL || SpeedtestSummary.state == "")
            SpeedtestSummary.postUpdate("⁉ (unbekannt)")
    ]
end

I recommend the Beginner’s Tutorial, and the User’s Guide in the docs site. There will almost certainly be other similar fundamental questions you will face soon.

To answer your specific question, if you installed on Linux using apt or yum the file goes in /etc/openhab2/rules.

If installed manually or on another OS it goes in the conf/rules folder under wherever you unzipped OH to.

1 Like

Thank you! It turns out it’s not two different files (two blocks of code as the author of the article showed), but one file. I put it in the rules folder and it all worked. But unfortunately the data record does not work in influxdb (collectd works) and openhab does not transfer data to the database. The empty database is created from scratch and a separate openhab user is created for it, all privileges are set for both writing and reading.

Sys: Ubuntu Server 16.04.3 X64
openhab: 2.1.0

Openhab2:
1. Install influxdb persistence

2. The data in the file is filled: influxdb.cfg

url=http://127.0.0.1:8086
user=openhab
password=mypass
db=openhab
retentionPolicy=autogen

3. influxdb.persist:

    Strategies {
        everyMinute : "0 * * * * ?"
        everyHour   : "0 0 * * * ?"
        everyDay    : "0 0 0 * * ?"
        default = everyMinute
    }

    Items {
        gInfluxDB* : strategy = everyChange, everyMinute
        Presence_Phone : strategy = everyChange
    }

4. SpeedTest.items

Group gSpeedtest <"network-icon"> (Whg)

String      SpeedtestSummary        "Ск.Инта: [%s]"             <"speedtest_network">       (gSpeedtest, gInfluxDB)
Number      SpeedtestResultPing     "Ping [%.3f ms]"             <"speedtest_next5">         (gSpeedtest, gInfluxDB)
Number      SpeedtestResultDown     "Downlink [%.2f Mbit/s]"     <"speedtest_download">      (gSpeedtest, gInfluxDB)
Number      SpeedtestResultUp       "Uplink [%.2f Mbit/s]"       <"speedtest_upload">        (gSpeedtest, gInfluxDB)
String      SpeedtestRunning        "Speedtest запущен ... [%s]" <"speedtest_new">           (gSpeedtest)
Switch      SpeedtestRerun          "Ручной запуск"              <"speedtest_reload2">       (gSpeedtest)
DateTime    SpeedtestResultDate     "История: [%1$td.%1$tm.%1$tY в %1$tH:%1$tM]"   <"speedtest_problem4">      (gSpeedtest, gInfluxDB)

5. sudo systemctl status influxdb:

No data db openhab:

root@edgi-server:/etc/openhab2/items# influx
Connected to http://localhost:8086 version 1.4.0~n201709010800
InfluxDB shell version: 1.4.0~n201709010800
> auth
username: openhab
password:
> use openhab
Using database openhab
> show measurements
>
>
>

nothing no data from openhab

First make sure to reboot OH. There is some weird behavior right now with groups where changes in group membership are not picked up properly until a reboot.

no work. reboot OH did not help
there are more ideas? can provide some more data? I need very much what would have worked, I have been fighting for many days.