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:
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.
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.
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)
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.
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
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")
}
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