Hello,
I am very new to openHAB2.
I want to do something if an item remains in a special state for some time. There are several examples here in the forum, but i don’t get it running.
I’ve spent hours in debugging my rule script and searching the forum for these erros. Here is my very simplified Script:
var timer t1 = null
rule "Test_Switch_on"
when
Item Test_Switch changed to ON
then
logInfo("Rule_Test-Switch_on", "Switch is on.")
if (t1 == null) {
logInfo("Rule_Test-Switch_on","Hello! ")
t1 = createTimer(now.plusSeconds(10), [|
//do something cool
logInfo("log", "timer")
t1=null
])
}
end
There are errors when saving the script and when it’s fired too:
2017-12-29 23:48:05.346 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'mytest.rules', using it anyway:
The field Tmp_mytestRules.t1 refers to the missing type Object
The field Tmp_mytestRules.t1 refers to the missing type Object
2017-12-29 23:48:05.362 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mytest.rules'
2017-12-29 23:48:30.312 [INFO ] [ome.model.script.Rule_Test-Switch_on] - Switch is on.
2017-12-29 23:48:30.316 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test_Switch_on': Unknown variable or command '=='; line 8, column 7, length 10
@MartinKo: That was indeed the fault. Thank you very much!
The distinction between small and capital writing drives me crazy because I am used to languages where it does not matter…
What makes it more confusing is that e.g. types of integer are declared with “int” while a timer needs to be “Timer”?
I guess a syntax highlighter (e.g. for notepad++ or nano) would not help in this case? Do you use any Tools with syntax checking for coding rules?
@gersilex: as far as I read, you can use both ways. At least it works for me.
I use the official Visual Studio Code extension. It uses the Language Server Protocol of openHAB, so it not only checks the syntax, but it talks directly to the running server and uses its syntax and completion suggestions. It contains many snippets as well.
The Editor itself is very lightweight but you will need a graphical environment. Luckily, with something like openHABian or some linux skills, you can mount the openHAB config folder to your local computer and edit the files from there.