Lots of error messages and system crash while migrating a rule from OH2.5 to 3.2

Hi there,

I’m in the process of migrating my rules from OH2.5 to 3.2.

Unfortunately one of the rules almost crashes the whole system by producing a lot of errors:


ERROR] [xbase.resource.BatchLinkableResource] - resolution of uriFragment '|::0.2.1.2.0.0.1.0.0.2.0::0::/1' failed.
java.lang.UnsupportedOperationException: Missing type computation for expression type: QuantityLiteral / ExpressionTypeComputationState: ExpressionAwareStackedResolvedTypes: [
  parent: [
    parent: [
      parent: [
        expressionTypes:
          org.eclipse.xtext.xbase.impl.XCastedExpressionImpl@17f2797 ->
            TypeData [expectation=TypeExpectation [expectation=Number], type=Number, flags=[UNCHECKED], returnType=false]
        featureLinking:
          <XCastedExpressionImpl> >= <XUnaryOperationImplCustom> ->  [>=:org.openhab.core.model.script.lib.NumberExtensions.operator_greaterEqualsThan(java.lang.Number,java.lang.Number) [key: operator_greaterEqualsThan(java.lang.Number,java.lang.Number)+]]
        parent: [
          expressionTypes:
            EG_ku_s_XiaomiTemperatursensorA_Temperature ->
              TypeData [expectation=TypeExpectation [expectation=NumberItem], type=NumberItem, flags=[UNCHECKED], returnType=false]
            <XFeatureCallImplCustom>.state ->
              TypeData [expectation=TypeExpectation [expectation=<void not allowed>], type=State, flags=[UNCHECKED], returnType=false]
            org.eclipse.xtext.xbase.impl.XCastedExpressionImpl@17f2797 ->
              TypeData [expectation=TypeExpectation [expectation=<void not allowed>], type=Number, flags=[UNCHECKED], returnType=false]
          featureLinking:
            EG_ku_s_XiaomiTemperatursensorA_Temperature -> FeatureLinkingCandidate [EG_ku_s_XiaomiTemperatursensorA_Temperature:Tmp_kuehlschrankRules.EG_ku_s_XiaomiTemperatursensorA_Temperature [key: EG_ku_s_XiaomiTemperatursensorA_Temperature+]]
            <XFeatureCallImplCustom>.state ->  [state:org.openhab.core.items.GenericItem.getState() [key: getState()+]]
          parent: [
            parent: [
              parent: [
                propagatedTypes:
                  {
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@9a72a6 (conditionalExpression: false)
}
                parent: [
                  parent: [
                    expressionTypes:
                      EG_ku_s_XiaomiTemperatursensorA_Temperature ->
                        TypeData [expectation=TypeExpectation [expectation=NumberItem], type=NumberItem, flags=[UNCHECKED], returnType=false]
                      <XFeatureCallImplCustom>.state ->
                        TypeData [expectation=TypeExpectation [expectation=Object], type=State, flags=[UNCHECKED], returnType=false]
                      org.eclipse.xtext.xbase.impl.XInstanceOfExpressionImpl@2b99b2 ->
                        TypeData [expectation=TypeExpectation [expectation=boolean], type=boolean, flags=[UNCHECKED], returnType=false]
                    featureLinking:
                      EG_ku_s_XiaomiTemperatursensorA_Temperature -> FeatureLinkingCandidate [EG_ku_s_XiaomiTemperatursensorA_Temperature:Tmp_kuehlschrankRules.EG_ku_s_XiaomiTemperatursensorA_Temperature [key: EG_ku_s_XiaomiTemperatursensorA_Temperature+]]
                      <XFeatureCallImplCustom>.state ->  [state:org.openhab.core.items.GenericItem.getState() [key: getState()+]]
                    propagatedTypes:
                      org.eclipse.xtext.xbase.impl.XIfExpressionImpl@174d641 (conditionalExpression: false)
                    parent: [
                      parent: [
                        types:
                          JvmOperation: Tmp_kuehlschrankRules._Temperaturwarnung Tiefkuehler(org.openhab.core.items.Item,java.lang.String,org.openhab.core.types.State,org.openhab.core.types.State) (visibility: PUBLIC, simpleName: _Temperaturwarnung Tiefkuehler, identifier: Tmp_kuehlschrankRules._Temperaturwarnung Tiefkuehler(org.openhab.core.items.Item,java.lang.String,org.openhab.core.types.State,org.openhab.core.types.State), deprecated: <unset>) (varArgs: false) (static: true, final: false, abstract: false, synchronized: false, default: false, native: false, strictFloatingPoint: false) -> void
                        declaredTypeParameters:


This is the rule (that worked fine on OH2.5):

// https://knx-user-forum.de/forum/supportforen/openhab/1036627-rule-aktion-bei-temperatur-größer-gleich-einem-bestimmten-wert?p=1307171#post1307171

// Variablen für Timer
var Timer   tTTemp = null       // Tiefkuehler
var Timer   tKTemp = null       // Kühlschrank


// Temperaturüberwachung im Tiefkühler
rule "Temperaturwarnung Tiefkuehler"
when
    Item EG_ku_s_XiaomiTemperatursensorA_Temperature changed
then
    if(EG_ku_s_XiaomiTemperatursensorA_Temperature.state instanceof Number) {
        if((EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number) >= -17 | "°C") {
            if(tTTemp === null)
                tTTemp = createTimer (now, [|
                    // sendTelegram("openHABBot", String::format("Die Temperatur im Netzwerkschrank beträgt %.1f°C!",(EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number).floatValue))
                    logInfo("KUEHLSCHRANK", "--> Temperaturwarnung: Tiefkühler >= -17°C / A_Temperature: "+ (EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number))
                    // sendPushoverMessage(pushoverBuilder("Temperaturwarnung: Tiefkühler >= -17°C").withPriority(1).withSound("spacealarm"))
                    tTTemp.reschedule(now.plusMinutes(15))
               ])
        } else if((EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number) < -17.2 | "°C") {
            tTTemp?.cancel      //  tTTemp.cancel()
            tTTemp = null
        }
    }
end


// Temperaturüberwachung im Kühlschrank
rule "Temperaturwarnung Kuehlschrank"
when
    Item EG_ku_s_XiaomiTemperatursensorB_Temperature changed
then
    if(EG_ku_s_XiaomiTemperatursensorB_Temperature.state instanceof Number) {
        if((EG_ku_s_XiaomiTemperatursensorB_Temperature.state as Number) >= 8.5 | "°C") {
            if(tKTemp === null)
                tKTemp = createTimer (now, [|
                    // sendTelegram("openHABBot", String::format("Die Temperatur im Netzwerkschrank beträgt %.1f°C!",(EG_ku_s_XiaomiTemperatursensorB_Temperature.state as Number).floatValue))
                    logInfo("KUEHLSCHRANK", "--> Temperaturwarnung: Kühlschrank >= 8.5°C / B_Temperature: "+ (EG_ku_s_XiaomiTemperatursensorB_Temperature.state as Number))
                    // sendPushoverMessage(pushoverBuilder("Temperaturwarnung: Kühlschrank >= 8.5°C").withPriority(1).withSound("spacealarm"))
                    tKTemp.reschedule(now.plusMinutes(20))
               ])
        } else if((EG_ku_s_XiaomiTemperatursensorB_Temperature.state as Number) < 8.2 | "°C") {
            tKTemp?.cancel      //  tKTemp.cancel()
            tKTemp = null
        }
    }
end




// Alarmsignal für Tiefkühler
    // https://www.freeformatter.com/cron-expression-generator-quartz.html
rule "Temperaturalarm Tiefkühler"
when
    Time cron "0 */10 * ? * *" // 	Every 10 minutes
then
    if((VxTempAlarmnotifications.state==ON && (EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number) >= -13 | "°C")) {
        VxTempFreezer.sendCommand(ON)
        logInfo("KUEHLSCHRANK", "--> Temperaturalarm: Tiefkühler >= -13°C / A_Temperature: "+ (EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number))
                EG_az_Echo_TTS_Volume.sendCommand(30)
                Thread::sleep(100)
                EG_az_Echo_TTS.sendCommand('Temperaturalarm: Tiefkühler')
        sendPushoverMessage(pushoverBuilder("Temperaturalarm: Tiefkühler >= -13°C").withPriority(1).withSound("gamelan"))
        Thread::sleep(100)
        sendTelegram("karin","Temperaturalarm: Tiefkühler >= -13°C") 
        Thread::sleep(100)
        sendCommand(EG_flurm_xgateway_soundvolume, 9)
        sendCommand(EG_flurm_xgateway_sound, 3) // sound: countdown
        createTimer(now.plusSeconds(5), [|
            sendCommand(EG_flurm_xgateway_sound, 10000)
            sendCommand(EG_flurm_xgateway_soundvolume, 0)
            ])
        
        }
    else if((EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number) < -13.2 | "°C") {
        VxTempFreezer.sendCommand(OFF)
        }
end


I really appreciate any help you can provide.

You’ve posted more than one rule here. It’s hard to say which one is causing the problem. The error actually provides a whole lot of information.

It says you have an unsupported operation.

The error involves a call to EG_ku_s_XiaomiTemperatursensorA_Temperature.state and appears to be related to the attempt to cast the state to a Number.

So the question is this Item NULL, UNDEF, or does it have Units (e.g. is a Number:Temperature)? In all of these cases you cannot cast the state to a Number.

Many bindings started using units of measurement in the move to OH 3.

Sorry for my late reply.

The item is defined as follows:

Number:Temperature     EG_ku_s_XiaomiTemperatursensorA_Temperature    "Kitchen Freezer"   <dtempfreezer>            (gM,gR,gI,Gxiaomi2,Gsensor,Gku,Gkuehlung)             {channel="mihome:sensor_weather_v1:xxxxxx:yyyyyy:temperature"}

As I understand I have to alter this part of the rule:

(EG_ku_s_XiaomiTemperatursensorA_Temperature.state as Number)

Could you please help me in which state it should be translated?

A QuantityType isn’t a Number. It’s a value that carries units. If you want to compare or do math with a QuantityType, you have to do it using another QuantityType that is using compatible units. This one is a temperature so you can use | °C (note now quotes around the units) to convert a constant number to a number with units.

if(EG_ku_s_XiaomiTemperaturesensorA_Temperature.state > 17 | °C)
2 Likes