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.
Edit:
Please give some feedback if you have tested it and it works.
I will adapt the first post of this tutorial then.
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.
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
speedtest-cli --simple is working properly while running it from the cli.
But running the rule via the OH3 gui or the manual start button in basicui isn’t working.
Exec Binding is installed and the command is whitelisted.
It always hangs up at “Messung läuft”. Don’t know exactly where it crashes but i think the command is not executed.
And you have installed that in the location like it is shown in the example?
In my personal rule i am runngin the speedtest command without the /usr/local/bin/ so the path may be different than it is in the example.
(But i am using the ookla varian tsince some time so that may be the deifference.)
// 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")
The syntax is not correct, it should be:
// execute the script, you may have to change the path depending on your system
var String speedtestCliOutput = executeCommandLine(Duration.ofSeconds(120), "/usr/local/bin/speedtest-cli", "--simple")
As said this was a shot in the Dark. @philf90 and me did already reach out to the Duration mistake and i have already corrected this in the openHAB Documentation.
But we should also add a understandable example for the multiple arguments too.
I will prepare something for this.
then
logInfo(filename, "--> speedtest executed...")
SpeedtestRunning.postUpdate("Messung läuft...")
// update timestamp for last execution
SpeedtestResultDate.postUpdate(new DateTimeType())
// execute the script, you may have to change the path depending on your system
// var String speedtestCliOutput = executeCommandLine("/usr/bin/speedtest-cli@@--simple", 120*1000) // OPENHAB 2.5
var String speedtestCliOutput = executeCommandLine(Duration.ofSeconds(120), "/usr/bin/speedtest-cli", "--simple") // NEU MIT OPENHAB 3
// for debugging:
//var String speedtestCliOutput = "Ping: 43.32 ms\nDownload: 21.64 Mbit/s\nUpload: 4.27 Mbit/s"
//logInfo(filename, "--> speedtest output:\n" + speedtestCliOutput + "\n\n")
SpeedtestRunning.postUpdate("Datenauswertung...")
// starts off with a fairly simple error check, should be enough to catch all problems I can think of
if (speedtestCliOutput.startsWith("Ping") && speedtestCliOutput.endsWith("Mbit/s")) {
var String[] results = speedtestCliOutput.split("\\r?\\n")
var float ping = new java.lang.Float(results.get(0).split(" ").get(1))
var float down = new java.lang.Float(results.get(1).split(" ").get(1))
var float up = new java.lang.Float(results.get(2).split(" ").get(1))
SpeedtestResultPing.postUpdate(ping)
SpeedtestResultDown.postUpdate(down)
SpeedtestResultUp.postUpdate(up)
SpeedtestSummary.postUpdate(String::format("↓ %.1f Mbit/s ↑ %.1f Mbit/s (%.0f ms)", down, up, ping))
SpeedtestRunning.postUpdate("-")
logInfo(filename, "--> speedtest finished.")
} else {
SpeedtestResultPing.postUpdate(0)
SpeedtestResultDown.postUpdate(0)
SpeedtestResultUp.postUpdate(0)
SpeedtestSummary.postUpdate("(unbekannt)")
SpeedtestRunning.postUpdate("Fehler bei der Ausführung")
logError(filename, "--> speedtest failed. Output:\n" + speedtestCliOutput + "\n\n")
}
SpeedtestRerun.postUpdate(OFF)
end
2020-12-22 21:27:33.005 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SpeedtestSummary' changed from Test ausführen! to (unbekannt)
2020-12-22 21:27:33.008 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SpeedtestRunning' changed from Datenauswertung... to Fehler bei der Ausführung
Hi,
I had a similar issue and it turns out the endsWith check was finding an extra carriage return after the Mbits/s check so causing the else statement to be actioned instead.
I had to amend the syntax to include the extra CR, at the moment my OH3 instance isn’t running so can get at the DSL rule to confirm.
I had a problem with the ‘if’ statement too, I simply tested the first condition and deleted the second, it seems the ‘&&’ (and) between them seems to be the culprit in OH3 vs OH2.
EDIT: btw I’m using the full json output of ‘speedtest’, not using ‘speedtest-cli’.