Speedtest-cli Internet Up-/Downlink Measurement Integration

This is a problem probably related to a bad state of your system.
Check your memory with df -h and free. Upgrade. Restart your system.

Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/root 30G 4,6G 24G 17% /
devtmpfs 459M 0 459M 0% /dev
tmpfs 463M 0 463M 0% /dev/shm
tmpfs 463M 47M 417M 11% /run
tmpfs 5,0M 8,0K 5,0M 1% /run/lock
tmpfs 463M 0 463M 0% /sys/fs/cgroup
/dev/mmcblk0p1 60M 20M 41M 34% /boot
tmpfs 93M 0 93M 0% /run/user/1000

pi@raspberrypi:~ $ free
total used free shared buffers cached
Mem: 948016 829852 118164 48040 5368 86472
-/+ buffers/cache: 738012 210004
Swap: 102396 96320 6076

My system is actually up to date .I have 32 GB memory Card.
Must still try again Restart.
Thanks

This worked great on my OH 1.9 installation. Thanks a lot.:relaxed:

I’ve switched to OH2 and now I’m struggeling a bit in using this without “compatibility mode”, i.e. implementing this in native OH2 terms. Mainly the integration of thing (exec binding) and rule. Could you provide an example (or even an updated version of the files :wink: )?

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