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.
Items:
Number setpoint_temperature
Number measured_temperature
Switch valve
Rules:
rule "Temperature control"
when
Item setpoint_temperature changed or
Item measured_temperature received update
then
if ((measured_temperature.state < (setpoint_temperature.state) as DecimalType) && (valve.state == OFF)) {
valve.sendCommand(ON)
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.
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.
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