[SOLVED] Comparing Temperature (or Lux) Value with SetPoints

Hello Community
I’ve run OH 2.1 for a year and now I did (3 days ago) an update to OH 2.3

  • Platform information:

    • Hardware: Intel x64, 8GB RAM, 128GB SSD
    • OS: Ubuntu 16.04 LTS
    • Java Runtime Environment: Raspbian Install
    • openHAB version: 2.3 stable
  • Issue of the topic:
    I have different rules, which compare the measured temperature with a Setpoint value. Depending on that, I open / close the valves of my climate ceilling.


Number setpoint_temperature 
Number measured_temperature
Switch valve


rule "Temperature control"
    Item setpoint_temperature changed or
    Item measured_temperature received update
if ((measured_temperature.state < (setpoint_temperature.state) as DecimalType) && (valve.state == OFF)) {

The value of “measured_temperature” is a Decimal value with 2 digits (eg 24.75).
These rules have worked in OH 2.1 but seem not to work anymore with OH 2.3

I’ve read many topics about using using (measured_temperature).floatvalue…but I like to know whats the correct way of doing this.

Tank you in advance.

Are you getting errors in the logs?

I don’t think you need the decimaltype portion as they’re both defined as numbers…

and if that’s the complete rule you’re missing the closing bracket ( } ) and “end”

Hey Scott

No, I dont get errors. I only see, that the valves dont get open/closed ==> so I assume the if condition wont trigger.

This is only a shortend sample, the {} and “end” is there in the original rule(s).

OK, I’ll try to remove the “as DecimalType” and try it, only comparing the original values.


I use the as DT when doing math in-line but i’ve never had to use it just comparing a number.state to another number.state

if ( tempPx.state <= (setpointPx.state as DecimalType - 0.5) ) {

Like Michael said, you probably don’t need the as DecimalType but sometimes you do need to cast it. And if you DO need to cast it, you will need to cast both Item states. And I recommend casting to Number instead of DecimalType.

if((measured_temperature.state as Number < setpoint_temperature.state as Number) && (valve.state == OFF)) {

Also, I recommend checking that both measured_temperature and setpoint_temperature are not NULL. This is an error that crops up sometimes when upgrading. When we wrote the Rule both measured_temperature and setpoint_temperature already had a value and always had a value. Then we upgrade or make some other change and our Items get reinitialized to NULL and our rules fail.

1 Like

Hey Rick

Thanks for the hint. I’ve read this today in another post so it seems to be really important :wink:

if(measured_temperature.state == NULL)) return;

Something like this?

regards Michael

that’ll dump out of the rule but you’ll still not know why. you may want a loginfo before returning so you know why

Isn’t there something about = NULL and having to use 3? if === NULL?

Is it? :smile:

BTW I found the error in my rule…
It was one level higher… There I check if my overall mode is automatic or not…And what do you think, that it was? I vorgot that value to be stored in the persistance-DB…Update --> restart --> Value === NULL. Overall :smile:

Thank you guys…

1 Like

You will know that measured_temperature.state is NULL meaning that Item is uninitialized.

Not quite. If you have null you need to use === or !==. If you have NULL you only use == or !=. NULL and null are not the same thing.