Temperature related rule trigger doesn't work

Hello guys

I work on my heating rules.
My idea: If either the temperature sensor or the setpoint changes, the rule checks the state of the termostat and activates or deactives it.

My items:
Number Temp_Kinderzimmer “Temperatur [%.1f °C]” (gKinderzimmer,gTemperatures) {zwave=“2:command=sensor_multilevel,sensor_type=1”}

Number SollTemp_Kinderzimmer “Soll-Temperatur [%.1f °C]” (gKinderzimmer,gSetpoints)

My rule:
rule “Kinderzimmer heizen”
Item SollTemp_Kinderzimmer changed or
Item Temp_kinderzimmer received update
if (SollTemp_Kinderzimmer.state == Uninitialized) {
if ((Temp_Kinderzimmer.state < (SollTemp_Kinderzimmer.state) as DecimalType) && (Heizung_Kinderzimmer.state == OFF)) {
logInfo(“Heating”, "Heizung im Kinderzimmer wurde eingeschalten, die Temperatur liegt bei " +Temp_Kinderzimmer.state)

if ((Temp_Kinderzimmer.state > (SollTemp_Kinderzimmer.state) as DecimalType) && (Heizung_Kinderzimmer.state == ON)) {
	logInfo("Heating", "Heizung im Kinderzimmer wurde ausgeschalten, die Temperatur liegt bei " +Temp_Kinderzimmer.state)


When I Change my setpoint, the rule get triggered, but not if the temperature changes.

I’ve also tried “Item Temp_Kinderzimmer changed”

Any ideas?

Thank you

Is the check for the setpoint change necessary? If this is a thermostat, does it not automatically get set? It is a z-wave device, so does it not report back to OpenHAB if the setpoint changes?

Hello Jim

The setpoint is used to control the Should-Temperature. I have also a Setpoint for High and Low (Day and night). I set the different setpoints via cron-jobs. So I have the Need to check the setpoint.
The termostat is a simple power relay (Fibaro FGRS)

additionally, I have a similar rule, but don’t use the as DecimalType as the temperature is already numeric. I am not sure that makes any difference though.

my rule:

rule "detached temperature trigger"
	Item detached_Temperature changed
	logInfo("detached", "detached thermostat temperature changed.  Temperature: "+detached_Temperature.state+" Outlet: "+ChargerOutlet.state)
	if (detached_Temperature.state < 45 && ChargerOutlet.state == OFF ) {
			logInfo("detached", "found outlet OFF and Temperature below 45F. Turning outlet ON")
			sendCommand(ChargerOutlet, ON)
			sendXMPP("myemail@gmail.com", "detached garage outlet changed to "+ChargerOutlet.state +"  temperature: "+detached_Temperature.state)
	else {
		if (detached_Temperature.state >= 48 && ChargerOutlet.state == ON ) {
				logInfo("detached", "found outlet ON and Temperature above 48F. Turning outlet OFF")
				sendCommand(ChargerOutlet, OFF)
				sendXMPP("myemail@gmail.com", "detached garage outlet switched off.  Temperature: "+detached_Temperature.state)

I am using a thermostat to control two different things. The first is the directly attached to the thermostat unit, and then if the temps are outside of bounds I set, to also trigger an outlet to turn on / off. The only things I see differently though are the DecimalType and the format of the if checks around the number of parenthesis used. I am using Item changed, and it is working well for me.

I had similiar problems, so maybe this will help you.

First there was a “hidden bug” that lead to leaving the rule prematurely without any notice - only logging statements made me aware that part of the rule never executed. Reason for this were the cast statements.


var Number setValue = set.state as Number
var Number actValue = act.state as Number

instead of

var Number setValue = set.state as DecimalType
var Number actValue = act.state as DecimalType

made the rule work always. I don’t know whats the reason.

Second, the comparision seemed to work sometimes, sometimes not. The cause for this was unexpected behavior in automatic type casting of the compare operation. When one of the operands was integer, the other was casted to integer. Without the fractional part, everything was equal…

So i use

if (setValue.floatValue < actValue.floatValue - 0.1) {
	// valve is normally open: ON -> close valve
	sendCommand(valve, ON)
	logDebug("wbfRule.tempControl", "valve {} -> ON", valve)
} else if (setValue.floatValue > actValue.floatValue) {
	// valve is normally open: OFF -> open valve
	sendCommand(valve, OFF)
	logDebug("wbfRule.tempControl", "valve {} -> OFF", valve)
} else {
	logDebug("wbfRule.tempControl", "valve {} -> do nothing", valve)

to force float compare.


Thanks for your replies.
If my rule get triggered, it works fine as it is. My Problem is, that the only Trigger is the Change of the setpoint.
But I Need the Trigger Temperature Change also :frowning:

Hey Guys

I found the bug:

The item is named “Temp_Kinderzimmer”
and in the rule i checked for "Temp_kinderzimmer "

Case sensitive tricked me out…