[OH2] strange behavior with rules

I’m using Openhab2 and having trouble with rules.

When i write a rule with if (a>0){…} this is working nog error’s
when i try it with < or = then there are error’s in the log.
What could be wrong ?

i’m currently at work and not able to post the error. Later i will also add the error.

Please post the example too.

I have only an Explanation for Problems with the “=”, this one is for assigning a value, for comparing use"==".
Other then that, we would need the code and the reported errors in order to help.

Here is the code, sorry stil no acces to the error log.
I am running openhabian on a raspberry pi 2, the release version not the beta.

val maxHumidity = 50
val minHumidity= 48

rule "Turn on fan"
when
    Item esp_douche_hum changed
then
    if(esp_douche_hum.state as Number > maxHumidity) {
        if(Douche.state != ON) Douche.sendCommand(ON)
    }
    else if(esp_douche_hum.state as Number < minHumidity) {
         Douche.sendCommand(OFF)
    }
end
1 Like
  • Type mismatch: cannot convert from Number< minHumidity> to boolean
else if((esp_douche_hum.state as Number) < minHumidity) {

But why is there no problem with the first if statement.
It is in my opinion the same als the last.

esp_douche_hum.state is a number, that is how i defined it in the items file.

if it’s a number

    if(esp_douche_hum.state > maxHumidity) {
...
    else if(esp_douche_hum.state < minHumidity) {

try it out

At last at home and time to check some things out.

still having error’s but the rule seems to work, what could cause the error ?

2018-01-11 17:50:20.757 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'fan.rules'
2018-01-11 17:50:20.777 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'fan.rules' is either empty or cannot be parsed correctly!
2018-01-11 17:50:21.969 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'fan.rules'

and these are the rules

val maxHumidity = 50
val minHumidity= 48

rule "Turn on fan"
when
    Item esp_douche_hum changed
then
    if(esp_douche_hum.state > maxHumidity) {
        if(Douche.state != ON) Douche.sendCommand(ON)
    }
    else if(esp_douche_hum.state < minHumidity) {
         Douche.sendCommand(OFF)
    }
end

and the error which i had the first time in my given example

2018-01-11 17:55:44.923 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'fan.rules'
2018-01-11 17:55:44.984 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'fan.rules' is either empty or cannot be parsed correctly!
2018-01-11 17:55:45.414 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'fan.rules' has errors, therefore ignoring it: [11,57]: missing '>' at ')'

Configuration model ‘…rules’ is either empty or cannot be parsed correctly!

seams to be a standard warning for every rule at the moment.

You have no Errors only Warnings. The observed Warning is caused by opening the file in an editor. Only the last warning is a syntax problem, look at the line11 and column 57 to find the problem.