Number:Temperature Problems with IF/IF Else

(Vini) #1

I’m running openHAB 2.5.0 Build #1590 on a Pi3. No issues.

I’m struggling to get a rule to fire based on a Number:Temperature item, which is a Hue Motion Sensor.

I’m trying to trigger an “alarm” when the temperature exceeds XX degrees. The item is, as below.

This triggers an Event;

2019-05-15 13:41:00.588 [vent.ItemStateChangedEvent] - HueLoftTemperatureSensor_Temperature changed from 32.87 °C to 33.01 °C

Now… my rule;

rule "Loft Temperature over 25 Degrees"
when
    Item HueLoftTemperatureSensor_Temperature changed
then
	var LoftTemp = HueLoftTemperatureSensor_Temperature.state as Number
	if (LoftTemp>25.00)
	//if (Double::parseDouble(HueLoftTemperatureSensor_Temperature.state.toString) > 25.0)
	//if ((HueLoftTemperatureSensor_Temperature.state as Number) > 25.00)
		{
			sendMail("blah@pomail.net", "Loft Temperature Over 25", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)
			logInfo("EXTRA", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)
		}
	else if (LoftTemp<25.00)
	{
			sendMail("blah@pomail.net", "Loft Temperature Below 25", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)	
			logInfo("EXTRA", "Loft Temperature is currently " +HueLoftTemperatureSensor_Temperature.state)
	}
end

I’ve tried many variations. But what is not happening, is that the rule is not understanding < or >, and just triggering regardless. So I’m being told the item is over 25’c, when actually its not.

image

Any ideas?

0 Likes

(Jürgen Baginski) #2

What does the logInfo tell about the state of the item?

0 Likes

(Vini) #3

Hi @opus,

Is that this?

2019-05-15 13:41:00.588 [vent.ItemStateChangedEvent] - HueLoftTemperatureSensor_Temperature changed from 32.87 °C to 33.01 °C

I dn’t know if the degrees C symbol is breaking things, or if its the decimal. Its hurting my head though!

0 Likes

(Rossko57) #4
1 Like

(Jürgen Baginski) #5

As @rossko57 posted, your item has UoM, you can see that in the received mail, the state is reported with the unit “°C”.
In the log you should also see the output of the logInfo line of your rule.

0 Likes

(Vini) #6

Thank you guys! I tried a few variations late last night, I knew I could rely on the community!

rule "Loft Temperature over 35 Degrees"
when
    Item HueLoftTemperatureSensor_Temperature changed
then
	if(HueLoftTemperatureSensor_Temperature.state >= 35 | "°C" )
		{
			sendMail("blah@pomail.net", "Loft Temperature Over 35", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)
			logInfo("EXTRA", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)
		}
	else if(HueLoftTemperatureSensor_Temperature.state < 35 | "°C" )
	{
			sendMail("blah@pomail.net", "Loft Temperature Below 35", "Loft Temperature is currently "+HueLoftTemperatureSensor_Temperature.state)	
			logInfo("EXTRA", "Loft Temperature is currently " +HueLoftTemperatureSensor_Temperature.state)
	}
end
0 Likes