Rule script tutorial

  • Platform information:
    • Hardware: R Pi3
    • OS: Openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.4.0
  • Issue of the topic: “Hello world script in rule”

Please I am novice in rules and I want to make a simple rule to compare two temperatures and in case, that outside temperature is greater than inside temperature, star fan

A have a rule triggered by change in outside temperature in which is next script

rule “Ventilator kuchyn”
when
Item Chalupa_ChalupaVenku changed
then
if((Chalupa_ChalupaVenku.state as DecimalType) > (Chalupa_ChalupaKuchyn.state as DecimalType)) {
Sonoff4585_Sonoff4585Switch.sendCommand(ON)
}
else {
Sonoff4585_Sonoff4585Switch.sendCommand(OFF)
}
end

But in log i found this

2020-03-29 07:57:26.986 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: <eval>:1:6 Expected ; but found Ventilator kuchyn
rule "Ventilator kuchyn"
      ^ in <eval> at line number 1 at column number 6

Can someone help to make a first kick how to write script in rules, please ? Thanks in advance.

you use the wrong “.
use " instead.

1 Like

As @HaKuNa said:

Must be "Ventilator kuchyn"-> is not the same as "

I tried to change script by copying from here, but without success :frowning: still the same error
rule "Ventilator kuchyn"
but without success

2020-03-29 12:46:57.534 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: <eval>:1:6 Expected ; but found Ventilator kuchyn

rule "Ventilator kuchyn"

      ^ in <eval> at line number 1 at column number 6

I tried copy string from openhab tutorial but still the same… For sure. I create a rule in GUI, it is triggered by change temperature and in action I have " execute a given scrip" in form is selected Java script as “scripting language used” another variant is not.

I think you are trying to use the rules feature in PaperUI ? Sometimes called “NGRE”

The example you are using is a “DSL” rule. This is how openHAB-1 rules were, and can continue to be used in OH2, but the method is to edit rules in text files and place them in a /rules folder.
You cannot use PaperUI to do that.

Yes, i am trying make script “what to do” in Paper UI. |Looks like, that it is the problem.
It is possible to write script in PaperUI ? I can not find any tutorial like “hello world” for it.
And is it possible to call from PaperUI rule writed in text format in /rules folder ?

Yes, you have a choice of scripting languages

No, the different rule systems can co-exist on your openHAB, and of course share Items etc., but you cannot import one into the other.

Thank you all my friends. Now I understand it clear. Have a nice day.