Averaging temperature

I made a rule which is pretty simple, still it gives me some problems…

It triggers on Sonoff_4CH_86_temp, and then uses that value to calculate the average temperature from the old readings.

rule "Work room temp averaging"
	Item Sonoff_4CH_86_temp received update
	var Number newValue = Sonoff_4CH_86_temp.state as DecimalType
	var Number oldValue = Sonoff_4CH_86_tempAvg.state as DecimalType
	var Number avgValue = 0

	if(Sonoff_4CH_86_tempAvg.state instanceof DecimalType)
		avgValue = (newValue.floatValue * 0.1) + (oldValue.floatValue * 0.9)
		oldValue = newValue as DecimalType
		avgValue = oldValue

	sendUpdate(Sonoff_4CH_86_tempAvg, avgValue)

but I am getting this error in the log file

[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Work room temp averaging': org.eclipse.smarthome.core.library.types.DecimalType

Am I doing the value types wrong, or what is going wrong in my calculation?

1 Like