[SOLVED] Rule Syntax error while dealing with numbers

  • Platform information:
    • Hardware: Raspberry Pi3 B+, ARM,1Gb Ram, 8Gb Disk
    • OS: Raspbian GNU/Linux 8 (jessie)
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
    • openHAB version: openHAB 2.3.0 Release Build
  • Issue of the topic: Simple rule seems not to work
  • Please post configurations (if applicable):
    ** Items **
    Number:Temperature    Netatmo_Cucina_Temperature "Temperature [%.1f %unit%]" <temperature>    { channel = "netatmo:NAMain:home:netatmo_inside:Temperature" }
    Number:Dimensionless  Netatmo_Cucina_Humidity    "Humidity [%d %unit%]"      <humidity>       { channel = "netatmo:NAMain:home:netatmo_inside:Humidity" }
    Number:Dimensionless  Netatmo_Cucina_Co2         "Co2 [%d %unit%]"           <carbondioxide>  { channel = "netatmo:NAMain:home:netatmo_inside:Co2" }

** Rule **

rule "AC cucina"                                                                                                                                                                                                                                                                                                             
when                                                                                                                                                                                                                                                                                                                         
  Item Netatmo_Cucina_Temperature changed                                                                                                                                                                                                                                                                                    
then                                                                                                                                                                                                                                                                                                                         
  if (Netatmo_Cucina_Temperature.state > 27.5) {                                                                                                                                                                                                                                                                             
    publish("prova","prova","cucinatemp")                                                                                                                                                                                                                                                                                    
  } else {                                                                                                                                                                                                                                                                                                                   
    publish("prova","prova","cucinatemp_down")                                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                                                          
end      

While the items function correctly (as i’m able to display them in a sitemap and are correct), I got an error while saving the rule:

2018-08-19 11:04:52.454 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'AC cucina': Unknown variable or command '>'; line 5, column 7, length 33

I’ve read some docs and example rules and it seems pretty much correct (the syntax, at least). Please disregard the action as it is just a test to be sure that something is triggered (FYI: mqtt is working correctly so, that is not a problem).

Thanks.

Luca

Please use

if (!(Netatmo_Cucina_Temperature.state instanceof Number)) // if state changed to NULL
    return; // stop rule
if ((Netatmo_Cucina_Temperature.state as QuantityType<Number>) > 27.5) {  // get the state as a Number without Unit of Measurement
    publish(...)
} else {
    publish(...)
}
2 Likes

Or:

rule "AC cucina"                                                                                                                                                                                                                                                                                                             
when                                                                                                                                                                                                                                                                                                                         
  Item Netatmo_Cucina_Temperature changed                                                                                                                                                                                                                                                                                    
then                                                                                                                                                                                                                                                                                                                         
  if (Netatmo_Cucina_Temperature.state > 27.5|"°C") {                                                                                                                                                                                                                                                                             
    publish("prova","prova","cucinatemp")                                                                                                                                                                                                                                                                                    
  } else {                                                                                                                                                                                                                                                                                                                   
    publish("prova","prova","cucinatemp_down")                                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                                                          
end    
1 Like

Do the unit types handle NULL or will this generate an error when Netatmo_Cucina_Temperature is NULL?

I don’t know…
Still at work. Let’s test it.

Tried and it works!
Thank you!

Coolio, can you please tick the solution

@rlkoshak
BTW, the unit type handles NULL just fine

Ticked. thanks again.

How? Meaning what do I get?

Netatmo_Cucina_Temperature.state > 27.5|“°C”
  • false
  • null pointer exception
  • cannot cast to Comparable exception
  • true
  • something else?

I thought you meant is the NULL state for the Quantitytype is the same and Number type
It is not NULL °C, is what I meant
I haven’t checked a comparison with a NULL state as my rules exclude this.
On my phone so I’ll try tonight or tomorrow