Working with Number:Temperature item type

Does this mean the following would not work anymore?
if (Weather_MaxTemp_0.state > 23) {

Is it mandatory to use
Number:Termperature instead of Number items?

No it should still work. It does for me.

Is there any way to do math in line of an if statement ?

ex:

	if ( atticTemperature.state < (atticSetpoint.state as QuantityType<Temperature> + "0.5 °F" ) )

I’ve tried a dozen different variations and they all fail with something along :

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'attic test something something': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_lessThan(org.eclipse.smarthome.core.types.Type,java.lang.Number) on instance: null

the closest I got with no errors (but didn’t seem to work anyway was:

rule "attic test something something"
when
	Item atticSetpoint changed
then
	if ( atticTemperature.state > (atticSetpoint.state as QuantityType<Temperature> + 0.5 ) )
	logInfo("success","addition")
end

but i never got the success logging. i also don’t get any other errors…so…progress? hah!

rule "attic test something something"
when
	Item atticSetpoint changed
then
	if ( atticTemperature.state > ((atticSetpoint.state as Number) + 0.5 ) )
	logInfo("success","addition")
end
1 Like

hey all,
how can i make this rule work with this?
items

Number:Temperature		Weather_Temperature				"Temperatuur buiten [%.1f %unit%]"							<temperature>	(gTemperatures, gWeather) 	{ channel="openweathermap:weather:api:local:current#temperature" }
Number					Weather_Temp_Min				"Temp. buiten Min [%.1f °C]"								<temperature>	(gWeather)
Number					Weather_Temp_Max				"Temp. buiten Max [%.1f °C]"								<temperature>	(gWeather)

rules

rule "Set daily max and min temperature"
when
	Item Weather_Temperature changed or
	Time cron "0 0 0 * * ?" or
	System started
then
	val max = Weather_Temperature.maximumSince(now.withTimeAtStartOfDay)
	val min = Weather_Temperature.minimumSince(now.withTimeAtStartOfDay)
	logInfo("rules.weather", "Temperatuur is " + Weather_Temperature.state)
	if( max !== null && min !== null) {
		postUpdate(Weather_Temp_Max, max.state)
		postUpdate(Weather_Temp_Min, min.state)
		logInfo("rules.weather", "Max Temperatuur is " + max.state)
		logInfo("rules.weather", "Min Temperatuur is " + min.state)
	}
end

What not working right now?

it wasn’t updating Weather_Temp_Max and Weather_Temp_Min, but i changed it to this, and that works so far now.

rule "Set daily max and min temperature"
when
	Item Weather_Temperature changed or
	Time cron "0 0 0 * * ?" or
	System started
then
	var Number CurrentValue = (Weather_Temperature.state as QuantityType<Number>).doubleValue
	postUpdate(Weather_Temp, CurrentValue)
	val max = Weather_Temp.maximumSince(now.withTimeAtStartOfDay)
	val min = Weather_Temp.minimumSince(now.withTimeAtStartOfDay)
	logInfo("rules.weather", "Temperatuur is " + CurrentValue)
	if( max !== null && min !== null) {
		postUpdate(Weather_Temp_Max, max.state)
		postUpdate(Weather_Temp_Min, min.state)
		logInfo("rules.weather", "Max Temperatuur is " + max.state)
		logInfo("rules.weather", "Min Temperatuur is " + min.state)
	}
end

You need to include one missing definition. At the top of your rules file, add:

import org.eclipse.smarthome.core.library.unit.SIUnits

I believe this missing include will be automatically added at a certain point in time.

2 Likes

Thank you @Lolodomo!

Just used your syntax for the DarkSky binding to remove the UNIT value so I could use it else where.

rule "Remove UNITS from Temperature and Round Numbers for Alexa"
	when
		Item FIOTemp received update or
		Item FIOTemp_Min0 received update or
		Item FIOTemp_Max0 received update or
		Item FIOTemp_Min1 received update or
		Item FIOTemp_Max1 received update or
		Item FIOTemp_Min2 received update or
		Item FIOTemp_Max2 received update or
		Item FIOTemp_Min3 received update or
		Item FIOTemp_Max3 received update or	
		Item FIOTemp_Min4 received update or
		Item FIOTemp_Max4 received update			
	then

		if (systemStarted.state != ON && FIOTemp.state != NULL && FIOTemp.state !== null && FIOTemp.state != UNDEF) {

			FIOTemp_Number.postUpdate((FIOTemp.state as QuantityType<Number>).doubleValue)
			logInfo("FIO" , "FIOTemp_Number postUpdate is at " + FIOTemp_Number.state)

			// Used for Alexa Speaking

			val roundedNumber1 = (Math::round((FIOTemp_Number.state as DecimalType).floatValue()* 10)).floatValue() / 10
			FIOTemp_Rounded.postUpdate(roundedNumber1)
		}