[SOLVED] Simple Rule comparing a temperature value not working

I am using OpenHab since one week and already managed to set up some simple rules (if this changes do that), but I am going crazy about this simple use case:

Every day at a given time, I want OH to send me a mail and telegram message when min temperature for the next day is below 4 degrees (to remind me shielding the windows of my car).

What I did so far:

Item definition:

Number   Temp_Frost    "Temperature Frost [%.2f]"{weather="locationId=home, forecast=1, type=temperature, property=min"}

Item shows nicely in sitemap using

Text item=Temp_Frost label="Frost" icon="temperature"

Now I set up this rule:

rule "Mail Frost"

when
  Time cron "0 7 16 * * ?"
 
then
	if(Temp_Frost < 4) {
  sendMail("someone@gmail.com", "Achtung Frost!", "This is the message.")
  sendTelegram("bot1", "Achtung Frost!")
 }
end

When the rule is firing, in the log I get

Error during the execution of rule ‘Mail Frost’: Unknown variable or command ‘<’; line 60, column 5, length 14

2018-11-15 16:07:00.014 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Mail Frost': Unknown variable or command '<'; line 60, column 5, length 14

The CRON part itself works nicely, cause if I don’t use the “if…”-Statement, the rule fires at the given time and sends me mail and telegram.

What am I doing wrong?

Try using the items state in the rule e.g.

(Temp_Frost.state < 4)

or use a var like:

var Temp = Temp_Frost.state as Number

Example with var:

rule "Mail Frost"

when
  Time cron "0 7 16 * * ?"
 
then
        var Temp = Temp_Frost.state as Number
	if(Temp < 4) {
  sendMail("Your_Email_Address", "Achtung Frost!", "This is the message.")
  sendTelegram("bot1", "Achtung Frost!")
 }
end
1 Like

@H102

Thanks, that was the solution. Works like a charm now!

Good please mark the thread as solved by ticking the post that gave you the solution
hc_292