Why does "Duration.ofSeconds(10)" not work

I started the migration of openHAB2 to 3 very slowly.
I did a fresh install of openHAB3.2 on a new machine.

I imported a rule from my working openHAB 2 setup.

This rule executes an external command on the openHAB console.
I saw many examples but why on earth does this not work on my setup

This is my simplified command:

var ScriptResponse = executeCommandLine(Duration.ofSeconds(10),"ssh")
logInfo("DEBUGSCRIPT", ScriptResponse )

Why is this not working? VSCode says “The method ofSeconds(int) is undefined for the type Class(org.eclipse.xtext.diagnostics.Diagnostic.Linking)”

It is just as the official documentation suggests:

// When you need the output in your further rule processing
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh", itemState1, itemState2);

I would expect a fresh install could run this example.

I read somewhere I have to import “var Duration = Java.type(“java.time.Duration”);”. This did not help.

Why is it not recognized?
Do I have to install additional addons to make Example Rules working in openHAB3?

Any help highly appreciated.

Try using the full class name.

java.time.Duration.ofSeconds(60)

I entered:

var ScriptResponse = executeCommandLine(java.time.Duration.ofSeconds(10),“ssh”)

and got the following error in VSCode:
Type mismatch: cannot convert from Duration to String(org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types)

After running the command it seems there happens something afterall, despite the error.
Could it be the VSCode saying there is something wrong (red underlined) but in reality there is nothing wrong?

Also without the additional java.time, there happens something I noticed now.
My DSL looks like:

rule “React on setting_11 change/update”
when
Item setting_11 changed from OFF to ON
then
//var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), “path/to/my/script.sh”)
//var ScriptResponse = executeCommandLine(Duration.ofSeconds(120),“/etc/openhab/scripts/weather.sh”, text)
//var ScriptResponse = executeCommandLine(Duration.ofSeconds(10),“ssh”,“-p”,“8101”,“-i”,“C:/MyOpenHAB3_ID_RSA”,“openhab@localhost”,“log:se”,“TRACE”,“org.openhab.binding.velux”)
var ScriptResponse = executeCommandLine(Duration.ofSeconds(10),“ssh”,“-p”,“8101”,“-i”,“C:/MyOpenHAB3_ID_RSA”,“openhab@localhost”,“log:set”,“TRACE”,“org.openhab.binding.velux”)
logInfo(“DEBUGSCRIPT”, ScriptResponse )
end
rule “React on setting_11 change/update”
when
Item setting_11 changed from ON to OFF
then
var ScriptResponse = executeCommandLine(Duration.ofSeconds(10),“ssh”,“-p”,“8101”,“-i”,“C:/MyOpenHAB3_ID_RSA”,“openhab@localhost”,“log:set”,“INFO”,“org.openhab.binding.velux”)
logInfo(“DEBUGSCRIPT”, ScriptResponse )
end

My good working command on openHAB2 was:

executeCommandLine(“ssh -p 8101 -i C:/MyOpenHAB3_ID_RSA openhab@localhost log:set TRACE org.openhab.binding.velux”)

do you think I have correctly translated this for the new syntax in openHAB3?

The executeCommandLine gives this error in VSCode:
Invalid number of arguments. The method executeCommandLine(String, int) is not applicable for the arguments (Object,String,String,String,String,String,String,String,String,String)(org.eclipse.xtext.xbase.validation.IssueCodes.invalid_number_of_arguments)

It’s a little hard to tell. Use code fences, not quotes for code.

```
code goes here
```

You never say what the “something” it does is. It’s very possible for VSCode to highlight something as an error that isn’t and error. That will tell you if you’ve done it right or not. Each argument to the script is usually a separate argument to the function call. However here, your command is ssh so I would expect everything after openhab@localhost to be just one argument because that is how ssh sees it.

I also would not be surprised if it would want you to combine the - tags with their value. For example -p 8101 would be one argument instead of two.

I wonder if your VSCode is still talking to the LSP for a running OH 2.5 instance because that error message is flat out wrong. There is no longer any executeCommandLine in OH 3 that accepts String, int as the arguments.

Thanks Rich. Do you have an idea how I can make the ssh command and the response visible? Then I can find out what works and what not. Then ‘something’ will we more specific also.

I suppose that when VSCode lists the variables and values of the openHAB3 instance correct, the right LSP is addressed. Or could the still be a difference in what is displayed and where the syntax is checked?

Your help is much appreciatex.

Geert

I can’t say anything about VSCode and the LSP since I haven’t used either in well over a year now. But it it’s telling you that it’s expecting executeCommandLine(String, int) it’s not OH 3, it’s OH 2.

The command executed should appear in the logs. The results from the command is put in ScriptResponse so log that too.

Today I started the computer running openHAB3 again and guess?
The not recognized errors are gone in VSCode. Don’t know why but now the Duration is proved valid in VSCode.

I am still struggling with how to see what is exactly executed on the Karaf console when I issue this ssh using executeCommandLine-command. It is not shown in the logs. Any ideas?

you are sure that it is being executed ? Add log entries before and after the call to executeCommandLine.
ssh itself is running in the cmd box ?
You copied the private ssh key from the old instance to the new instance ?
You imported the public ssh key into the new instance ?

I am sure it is executed. I can check it by the result of the log:list command.
I created an new private and public key.