Comparing temps

  • Platform information: 2.5.11

How does one compare “temperatures” in a rule?
I have a rule I cannot get to run:
It essentially will not fall into this statement:
if (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state > PreviousLaundryTemp.state)

The states of these items look like this(something puts a ?F in there:

Is that stopping the compare?

What i keep doing is manually updating the item state to a higher temp to get it to meet the criteria(to test it), but it keeps skipping that if statement all together.

Thanks

See especially “comparisons” in -

It’s probably that part that is going wrong, don’t update these Items with just a number. But what type of Item PreviousLaundryTemp is, is also important.

Thanks; any idea what this means in the log:

‘toBigDecimal’ is not a member of ‘java.lang.Number’; line 17,

var NetEquipCurrentTempVar = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as Number).toBigDecimal

I’ve tried this too:
val NetEquipCurrentTempVar = new BigDecimal(ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state.toString)
val PrevLaundTempVar = new BigDecimal(PreviousLaundryTemp.state.toString)
val runtime_desiredCoolVar = new BigDecimal(runtime_desiredCool.state.toString)

Without even doing anything with these(comparision), just trying to log their states i get an error:
An error occurred during the script execution: null

val NetEquipCurrentTempVar = new BigDecimal(ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state.toString)
val PrevLaundTempVar = new BigDecimal(PreviousLaundryTemp.state.toString)
val runtime_desiredCoolVar = new BigDecimal(runtime_desiredCool.state.toString)
logInfo(“Temperature.Rules”, "Test: " + NetEquipCurrentTempVar.state)
logInfo(“Temperature.Rules”, "Test: " + PrevLaundTempVar.state)
logInfo(“Temperature.Rules”, "Test: " + runtime_desiredCoolVar.state)

The items are not null(that I’m trying to cast to the string); i can see them in the rest items:

image

Getting stuff as strings isn’t going to help for comparisons.

What rules language are you working in?

I have no idea LOL; I am not an engineer; i dabble enough with this to be dangerous.

I’ve recently stumbled across trying this:
val NetEquipCurrentTempVar = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as QuantityType<Number>).intValue

if (NetEquipCurrentTempVar > (PreviousLaundryTemp.state as number)) {
		logInfo("Temperature.Rules", "Entering first IF")
	}

and i get this:
Could not cast 82 to void; line 42, column 32, length 35

I’ve also tried comparing it like this

		if (NetEquipCurrentTempVar > (PreviousLaundryTemp.state )) {
		logInfo("Temperature.Rules", "Entering first IF")
	}

That also fails

I’ve also tried:

if (NetEquipCurrentTempVar > (PreviousLaundryTemp)) {
		logInfo("Temperature.Rules", "Entering first IF")
	}

That also fails

I’ve pretty much run the gammit on every example i’ve seen throughout the forums, and nothing seems to work.

Last ditch effort:

All i need is a way to compare two temperatures; it seems like i need to convert them to a similar “type”.
So what is the best way to take a temperature.state item and put it into a type that i can compare to another item.state; it seems when i try to take a temp.state item and a number.state item and tr to convert them both to a double; it doesn’t like that either


var NetEquipCurrentTempVar = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as QuantityType<Number>).doubleValue
	var PrevLaundTempVar = (PreviousLaundryTemp.state as QuantityType<Number>).doubleValue
	var runtime_desiredCoolVar = (EcobeeThermostatMiltysbee_Runtime_DesiredCool.state as QuantityType<Number>).doubleValue
logInfo(“Temperature.Rules”, "NetEquipCurrentTempVar: " + NetEquipCurrentTempVar)
||logInfo("Temperature.Rules", "runtime_desiredCoolVar: " + runtime_desiredCoolVar)|
||logInfo("Temperature.Rules", "upperThreshold: " + upperThreshold)|

Could not cast 83 to org.eclipse.smarthome.core.library.types.QuantityType; line 21, column 26, length 49

I’m actually quite shocked I can’t find a similar complaint with similar things in the forum; everything I’ve tried off of examples fails as well…totally lost here.

That was an error on my part, weird how you test everything when doing a write-up and still muff it up.
You can get BigDecimal of Quantity, not Number -

var NetEquipCurrentTempVar = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as QuantityType<Number>).toBigDecimal

Case is important. as Number

Demo

// This Item is a Quantity type, a Number:Temperature
logInfo ("test", "Sensor state "+ ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state.toString)
// The units are part of the value

// This Item is a plain Number type
logInfo ("test", "Prev state "+ PreviousLaundryTemp.state.toString)
// it has no units

// That's apples and oranges- so you can't compare directly

// You need to get the numeric value of your sensor, in F
val sensornum = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as QuantityType<Temperature>).toUnit("°F").toBigDecimal
// thats the bulletproof way to do it without knowing original units
logInfo ("test", "extracted "+ sensornum.toString)


if (sensornum > PreviousLaundryTemp.state as Number) {
   logInfo ("test", "higher")
} else {
   logInfo ("test", "lower")
}

Doesn’t seem to have worked:

2021-03-02 19:48:46.543 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Send mail when temperature over 80’: Could not cast 83 to void; line 34, column 31, length 35


var Number upperThreshold = 80
var Number lowerThreshold = 50
var Number EmailThreshold = 10
var Number EmailCounter = 0
var Number EmailResetCounter = 0

rule "Send mail when temperature over 80"
when
	Item ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature changed
	
then


	logInfo("Temperature.Rules", "Entering Rule") 

	val NetEquipCurrentTempVar = (ZWaveNode_ZSE40V24In1SensorLaundNetEquip_SensorTemperature.state as QuantityType<Temperature>).toUnit("°F").toBigDecimal
	val runtime_desiredCoolVar = (EcobeeThermostatMiltysbee_Runtime_DesiredCool.state as QuantityType<Temperature>).toUnit("°F").toBigDecimal
	
	
	logInfo("Temperature.Rules", "NetEquipCurrentTempVar: " + NetEquipCurrentTempVar)
	logInfo("Temperature.Rules", "PrevLaundTempVar: " + PreviousLaundryTemp.state)
	logInfo("Temperature.Rules", "runtime_desiredCoolVar: " + runtime_desiredCoolVar)
	logInfo("Temperature.Rules", "upperThreshold: " + upperThreshold)

	
	if (NetEquipCurrentTempVar > PreviousLaundryTemp.state as Number) {
		logInfo("Temperature.Rules", "Entering first IF")
	}

end

As a side note; PreviousLaundryTempis a number item that is set to a number in rest

image

This might actually be working; still changing some things; more to come.

Yes, that worked; I didn’t capitalize the N in number; i appreciate your help!

Thanks so much!