I am trying to eliminate outliers in my temperature measurements. I am taking 5 measurements and storing each in an ArrayList. I am trying to get the median value which should be a simple matter with Collections.sort but designer marks it as “Couldn’t resolve reference to JvmIdentifiableElement ‘Collections’.” and the code does not work at runtime. Here’s the rule:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import java.lang.Math
import java.util.List
import java.util.ArrayList
import java.util.Collections.*
import org.openhab.core.library.types.DecimalType.*
var ArrayList<Number> theArray = new ArrayList<Number>()
var int place=0
rule "Convert_Input1_To_Temp"
when
Item Input1 received update
then
var Number output
var Number temp1
var raw1 = (Input1.state as DecimalType).doubleValue
raw1 = (raw1 + ((indexInput1.state as DecimalType) * 255)).doubleValue
temp1 = Math::log((10000*(860/raw1 - 1)).doubleValue)
temp1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp1 * temp1 ))* temp1 )
temp1 = temp1 - 273.15 // Convert Kelvin to Celcius
postUpdate(SolarTemp, temp1)
if(place<5){
theArray.add(place, temp1)
postUpdate(Place, place)
place = place+1}
else{
place = 0
var ArrayList<Number> arraySorted = new ArrayList<Number>()
arraySorted = Collections.sort(theArray)
output=arraySorted.get(2)
postUpdate(Var1, output)
postUpdate(Place, place)
}
Do rules not support this method?