OH2.2, error in rule declared as "Ambiguous binary operation"

Dear all

I’m cleaning up my OH1.x for further usage in OH2.2. VS is reporting an error that I don’t understand

Ambiguous binary operation.The operator declarations operator_equals(Number, Number) in NumberExtensions and operator_equals(Type, Number) in NumberExtensions both match.

for the following rule

 rule "Status Meldung"
    when
        System started
        or
        Item Lueftung_Fehlermeldung changed
        or
        Item Lueftung_FilterfehlerI changed
        or
        Item Lueftung_FilterfehlerE changed
    then
        var String msg = ""

        if( (Lueftung_FilterfehlerI.state instanceof DecimalType) && (Lueftung_FilterfehlerE.state instanceof DecimalType) && (Lueftung_Fehlermeldung.state instanceof StringType) ){

            if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 || (Lueftung_FilterfehlerE.state as DecimalType) == 1 ){
                if( msg.length > 0 ) msg = msg + ", "
                msg = msg + "Filter: "
                if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 ) msg = msg + "I"
                if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 && (Lueftung_FilterfehlerE.state as DecimalType) == 1) msg = msg + " & "
                if( (Lueftung_FilterfehlerE.state as DecimalType) == 1 ) msg = msg + "E"
            }
            if( (Lueftung_Fehlermeldung.state as StringType) != "Ok" ){
                if( msg.length > 0 ) msg = msg + ", "
                msg = msg + "Error: " + (Lueftung_Fehlermeldung.state as StringType)
            }
        }

        if( msg.length == 0 ){

            msg = "Alles in Ordnung"
        }

        postUpdate(Lueftung_Status_Message,msg)
    end

in particular for this part, everywhere I’m using the ==

  if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 || (Lueftung_FilterfehlerE.state as DecimalType) == 1 ){
                if( msg.length > 0 ) msg = msg + ", "
                msg = msg + "Filter: "
                if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 ) msg = msg + "I"
                if( (Lueftung_FilterfehlerI.state as DecimalType) == 1 && (Lueftung_FilterfehlerE.state as DecimalType) == 1) msg = msg + " & "
                if( (Lueftung_FilterfehlerE.state as DecimalType) == 1 ) msg = msg + "E"
            }

I’m not a rule-pro - can anyone please tell my how to fix this?

Thanks & regards
John

openHAB complains about two matching functions, openHAB can’t decide which one to use. Try to either use

(Lueftung_FilterfehlerI.state as DecimalType).intValue == 1

or this

(Lueftung_FilterfehlerI.state as Number) == 1
4 Likes

That solved my problem.

Thanks a lot @Udo_Hartmann

Any idea on this one: I 'm getting an error with these 3 lines?

if (Washingmachine_Power.averageSince(now.minusMinutes(2)) < 0.2) Washingmachine_OpState.postUpdate(MODE_OFF)
    else if (Washingmachine_Power.averageSince(now.minusMinutes(2))> 10) Washingmachine_OpState.postUpdate(MODE_ACTIVE)
    else if (Washingmachine_Power.averageSince(now.minusMinutes(2))< 5) {

Ambiguous binary operation.
The operator declarations
	operator_lessThan(Number, Number) in NumberExtensions and
	operator_lessThan(Type, Number) in NumberExtensions
both match.```

As the value is tested three times, please try this instead (should also solve the problem)

val Number nAvg = Washingmachine_Power.averageSince(now.minusMinutes(2)) as Number
if(nAvg < 0.2) Washingmachine_OpState.postUpdate(MODE_OFF)
else if(nAvg > 10) Washingmachine_OpState.postUpdate(MODE_ACTIVE)
else if(nAvg < 5) {

Thanks, I’ll give it a try tonight, and It did get rid of the error.

Okay

I tried the following over the weekend and got no notifications?

Here are my Items:


// Laundry Room
Switch tplinksmarthome_hs110_B1AFF9_switch             "Dryer"              (BF_LaundryRoom , GetPower)
Number tplinksmarthome_hs110_B1AFF9_power               "Dryer Power"       (BF_LaundryRoom , GetPower)
Number plinksmarthome_hs110_B1AFF9_energyUsag           "Dryer Usage"       (BF_LaundryRoom , GetPower)
Number tplinksmarthome_hs110_B1AFF9_current             "Dryer Current"     (BF_LaundryRoom , GetPower)


Switch tplinksmarthome_hs110_B16E5F_switch            "Washing Machine"            (BF_LaundryRoom , GetPower)
Number tplinksmarthome_hs110_B16E5F_power       "Washing Machine Power"         (BF_LaundryRoom , GetPower)
Number tplinksmarthome_hs110_B16E5F_energyUsage  "Washing Machine Usage"        (BF_LaundryRoom , GetPower)
Number tplinksmarthome_hs110_B16E5F_current       "Washing Machine Current"      (BF_LaundryRoom , GetPower)


Number Washingmachine_OpState           "Washing Machine State"
Number Dryer_OpState                    "Dryer State"

Number MODE_OFF         "Mode Off"             (BF_LaundryRoom)
Number MODE_STANDBY     "Mode Standby"          (BF_LaundryRoom)
Number MODE_ACTIVE      "Mode Active"             (BF_LaundryRoom)
Number MODE_FINISHED    "Mode Finished"         (BF_LaundryRoom)

And here are the Rules:

rule "Washingmachine Consumption State Machine"
when
    Item tplinksmarthome_hs110_B16E5F_power changed
then
    val Number WnAvg = tplinksmarthome_hs110_B16E5F_power.averageSince(now.minusMinutes(2)) as Number
    
        if(WnAvg < 2) Washingmachine_OpState.postUpdate(MODE_OFF)
        else if(WnAvg > 10) Washingmachine_OpState.postUpdate(MODE_ACTIVE)
        else if(WnAvg < 5)
    {
        if (Washingmachine_OpState.state == MODE_OFF) Washingmachine_OpState.postUpdate(MODE_STANDBY)
        else if (Washingmachine_OpState.state == MODE_ACTIVE) Washingmachine_OpState.postUpdate(MODE_FINISHED)
    } 
end 
 

rule "Washingmachine Notifications"
when
    Item Washingmachine_OpState changed
then
    if (Washingmachine_OpState.state == MODE_FINISHED) {
        sendBroadcastNotification("Washingmachine finished")
        logInfo("Washingmachine ", "finished!")
    }
end```


Here is the raw data for the run time..
I assumed at 5:38 AM the average would have be below 2 and It should have fired the notification?
Any Ideas?


```csv
|12/8/2018 4:33:11 AM|1.67554|
|---|---|
|12/8/2018 4:33:41 AM|1.709435|
|12/8/2018 4:34:11 AM|1.691103|
|12/8/2018 4:34:41 AM|1.687014|
|12/8/2018 4:35:11 AM|1.710029|
|12/8/2018 4:35:41 AM|1.715305|
|12/8/2018 4:36:11 AM|1.672572|
|12/8/2018 4:36:41 AM|1.642039|
|12/8/2018 4:37:12 AM|1.690377|
|12/8/2018 4:37:42 AM|1.658064|
|12/8/2018 4:38:12 AM|1.684508|
|12/8/2018 4:38:42 AM|1.708182|
|12/8/2018 4:39:12 AM|1.706468|
|12/8/2018 4:39:42 AM|1.706138|
|12/8/2018 4:40:12 AM|1.690047|
|12/8/2018 4:40:42 AM|1.699346|
|12/8/2018 4:41:12 AM|1.704226|
|12/8/2018 4:41:42 AM|1.693081|
|12/8/2018 4:42:12 AM|1.655294|
|12/8/2018 4:42:42 AM|1.686882|
|12/8/2018 4:43:12 AM|1.714315|
|12/8/2018 4:43:43 AM|1.724603|
|12/8/2018 4:44:13 AM|1.707325|
|12/8/2018 4:44:43 AM|1.669275|
|12/8/2018 4:45:13 AM|1.708182|
|12/8/2018 4:45:43 AM|2.57576|
|12/8/2018 4:46:13 AM|2.514101|
|12/8/2018 4:46:43 AM|2.511133|
|12/8/2018 4:47:13 AM|2.409775|
|12/8/2018 4:47:43 AM|18.835641|
|12/8/2018 4:48:13 AM|38.481883|
|12/8/2018 4:48:43 AM|27.391919|
|12/8/2018 4:49:14 AM|41.932473|
|12/8/2018 4:49:44 AM|7.845189|
|12/8/2018 4:50:14 AM|23.785499|
|12/8/2018 4:50:44 AM|48.442598|
|12/8/2018 4:51:14 AM|4.839663|
|12/8/2018 4:51:44 AM|16.202971|
|12/8/2018 4:52:14 AM|29.864474|
|12/8/2018 4:52:44 AM|2.607413|
|12/8/2018 4:53:14 AM|27.38361|
|12/8/2018 4:53:44 AM|13.631102|
|12/8/2018 4:54:14 AM|24.94528|
|12/8/2018 4:54:45 AM|2.547601|
|12/8/2018 4:55:15 AM|9.268949|
|12/8/2018 4:55:45 AM|20.093879|
|12/8/2018 4:56:15 AM|48.103112|
|12/8/2018 4:56:45 AM|38.760568|
|12/8/2018 4:57:15 AM|7.779705|
|12/8/2018 4:57:45 AM|20.493573|
|12/8/2018 4:58:15 AM|2.557031|
|12/8/2018 4:58:45 AM|39.115288|
|12/8/2018 4:59:15 AM|61.103315|
|12/8/2018 4:59:45 AM|39.923316|
|12/8/2018 5:00:16 AM|60.891103|
|12/8/2018 5:00:46 AM|40.441053|
|12/8/2018 5:01:16 AM|40.544851|
|12/8/2018 5:01:46 AM|13.419418|
|12/8/2018 5:02:16 AM|20.398084|
|12/8/2018 5:02:46 AM|15.128128|
|12/8/2018 5:03:16 AM|24.584427|
|12/8/2018 5:03:46 AM|16.569297|
|12/8/2018 5:04:16 AM|182.301837|
|12/8/2018 5:04:46 AM|204.583189|
|12/8/2018 5:05:16 AM|165.432093|
|12/8/2018 5:05:46 AM|153.907483|
|12/8/2018 5:06:17 AM|150.99626|
|12/8/2018 5:06:47 AM|129.374823|
|12/8/2018 5:07:17 AM|170.656811|
|12/8/2018 5:07:47 AM|201.033153|
|12/8/2018 5:08:17 AM|149.385545|
|12/8/2018 5:08:47 AM|177.948653|
|12/8/2018 5:09:17 AM|174.842561|
|12/8/2018 5:09:47 AM|137.327305|
|12/8/2018 5:10:17 AM|2.718399|
|12/8/2018 5:10:47 AM|41.271569|
|12/8/2018 5:11:18 AM|175.228275|
|12/8/2018 5:11:48 AM|216.529388|
|12/8/2018 5:12:18 AM|184.471571|
|12/8/2018 5:12:48 AM|217.819477|
|12/8/2018 5:13:18 AM|179.226608|
|12/8/2018 5:13:48 AM|123.56484|
|12/8/2018 5:14:18 AM|74.280449|
|12/8/2018 5:14:48 AM|5.22551|
|12/8/2018 5:15:18 AM|63.284589|
|12/8/2018 5:15:48 AM|43.200009|
|12/8/2018 5:16:18 AM|61.223005|
|12/8/2018 5:16:49 AM|97.507721|
|12/8/2018 5:17:19 AM|112.823529|
|12/8/2018 5:17:49 AM|113.293917|
|12/8/2018 5:18:19 AM|68.329277|
|12/8/2018 5:18:49 AM|78.317162|
|12/8/2018 5:19:19 AM|72.307826|
|12/8/2018 5:19:49 AM|77.594203|
|12/8/2018 5:20:19 AM|67.023625|
|12/8/2018 5:20:49 AM|67.438025|
|12/8/2018 5:21:19 AM|72.243331|
|12/8/2018 5:21:50 AM|107.247783|
|12/8/2018 5:22:20 AM|2.497021|
|12/8/2018 5:22:50 AM|13.035418|
|12/8/2018 5:23:20 AM|2.523333|
|12/8/2018 5:23:50 AM|13.154713|
|12/8/2018 5:24:20 AM|15.319831|
|12/8/2018 5:24:50 AM|2.518717|
|12/8/2018 5:25:20 AM|2.526564|
|12/8/2018 5:25:50 AM|101.113679|
|12/8/2018 5:26:20 AM|44.057035|
|12/8/2018 5:26:50 AM|36.844723|
|12/8/2018 5:27:20 AM|13.276712|
|12/8/2018 5:27:51 AM|68.769792|
|12/8/2018 5:28:21 AM|98.529148|
|12/8/2018 5:28:51 AM|108.675896|
|12/8/2018 5:29:21 AM|100.256983|
|12/8/2018 5:29:51 AM|69.37451|
|12/8/2018 5:30:21 AM|16.899881|
|12/8/2018 5:30:51 AM|33.294753|
|12/8/2018 5:31:21 AM|156.275119|
|12/8/2018 5:31:51 AM|255.716556|
|12/8/2018 5:32:21 AM|178.844586|
|12/8/2018 5:32:52 AM|200.320943|
|12/8/2018 5:33:22 AM|175.331216|
|12/8/2018 5:33:52 AM|174.548576|
|12/8/2018 5:34:22 AM|199.371528|
|12/8/2018 5:34:52 AM|217.044091|
|12/8/2018 5:35:22 AM|219.299356|
|12/8/2018 5:35:52 AM|228.273332|
|12/8/2018 5:36:22 AM|254.927256|
|12/8/2018 5:36:52 AM|35.870249|
|12/8/2018 5:37:22 AM|13.109804|
|12/8/2018 5:37:52 AM|1.671451|
|12/8/2018 5:38:23 AM|1.681409|
|12/8/2018 5:38:53 AM|1.729153|
|12/8/2018 5:39:23 AM|1.722097|
|12/8/2018 5:39:53 AM|1.717217|
|12/8/2018 5:40:23 AM|1.746695|
|12/8/2018 5:40:53 AM|1.73344|
|12/8/2018 5:41:23 AM|1.6944|
|12/8/2018 5:41:53 AM|1.69928|

I just restarted the OH service and I got the following errors:???


018-12-12 10:05:39.530 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Washingmachine Consumption State Machine': The name 'tplinksmarthome_hs110_B16E5F_power' cannot be resolved to an item or type; line 39, column 24, length 34

2018-12-12 10:05:39.532 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Dryer Consumption State Machine': The name 'tplinksmarthome_hs110_B1AFF9_power' cannot be resolved to an item or type; line 124, column 24, length 34

To be honest, I’m a bit confused by the MODE_OFF (and the others) status, as this is no status. Either use a Number (0 Off, 1 Standby, 2 active, 3 finished)or use a String Item. I don’t know if this error will have impact to the trailing line. I would do it like this:
items:

Number Washingmachine_OpState           "Washing Machine State [MAP(wmachine.map):%s]"

wmachine.map

0 = OFF
1 = Standby
2 = Active
3 = finished
NULL = -
rule "Washingmachine Consumption State Machine"
when
    Item tplinksmarthome_hs110_B16E5F_power changed
then
    val Number WnAvg = tplinksmarthome_hs110_B16E5F_power.averageSince(now.minusMinutes(2)) as Number
    if(WnAvg < 2)
        Washingmachine_OpState.postUpdate(0)
    else if(WnAvg > 10)
        Washingmachine_OpState.postUpdate(2)
    else if(WnAvg < 5) {
        if ((Washingmachine_OpState.state as Number) == 0)
            Washingmachine_OpState.postUpdate(1)
        else if ((Washingmachine_OpState.state as Number) == 2) {
            Washingmachine_OpState.postUpdate(3)
            sendBroadcastNotification("Washingmachine finished")
            logInfo("wmachine ", "Washingmachine finished!")
        }
    } 
end 

Which persistence service did you use? Is it the default persistence service?

jdbc.persist

And Yes its Default…

image

And when I tried your suggestion I got the following errors in VSC?

I found the issue

        else if (Washingmachine_OpState.state as Number) == 2) {

Needed an extra “(”
I will test tonight…

        else if ((Washingmachine_OpState.state as Number) == 2) {

Jep. I did a correction above, just for reference…

So I did a couple of loads yesterday and I didn’t have any errors, but I never got a notification when the load was finished? Any Ideas?

rule "Washingmachine Consumption State Machine"
when
    Item tplinksmarthome_hs110_B16E5F_power changed
then
   val Number WnAvg = tplinksmarthome_hs110_B16E5F_power.averageSince(now.minusMinutes(2)) as Number
                    
    if(WnAvg < 2)
        Washingmachine_OpState.postUpdate(0)
    else if(WnAvg > 10)
        Washingmachine_OpState.postUpdate(2) 
    else if(WnAvg < 5) {
        if ((Washingmachine_OpState.state as Number) == 0)
            Washingmachine_OpState.postUpdate(1)
        else if ((Washingmachine_OpState.state as Number) == 2) {
            Washingmachine_OpState.postUpdate(3)
            sendBroadcastNotification("Washingmachine finished")
            logInfo("wmachine ", "Washingmachine finished!")
        }
    } 
end 

Maybe do a little more logging:

rule "Washingmachine Consumption State Machine"
when
    Item tplinksmarthome_hs110_B16E5F_power changed
then
   logInfo("wmachine ", "Rule started!")
   val Number WnAvg = tplinksmarthome_hs110_B16E5F_power.averageSince(now.minusMinutes(2)) as Number
   logInfo("wmachine ", "Power avarage is {}",WnAvg)
                    
    if(WnAvg < 2) {
        logInfo("wmachine ", "Setting OpState to 0")
        Washingmachine_OpState.postUpdate(0)
    }
    else if(WnAvg > 10) {
        logInfo("wmachine ", "Setting OpState to 2")
        Washingmachine_OpState.postUpdate(2) 
    }
    else if(WnAvg < 5) {
        logInfo("wmachine ", "Current OpState is {}",Washingmachine_OpState.state.toString)
        if ((Washingmachine_OpState.state as Number) == 0) {
            logInfo("wmachine ", "Setting OpState to 1")
            Washingmachine_OpState.postUpdate(1)
        }
        else if ((Washingmachine_OpState.state as Number) == 2) {
            logInfo("wmachine ", "Setting OpState to 3")
            Washingmachine_OpState.postUpdate(3)
            sendBroadcastNotification("Washingmachine finished")
            logInfo("wmachine ", "Washingmachine finished!")
        }
    } 
end 

Thanks,

I’ll add the logging and try again.

Hi , i have same problem i thing and this problem stop some other rules can you help ? thanks in advance .Here is whats cause problem in a rule

if (EnergyGenCuisiniereFullSum.averageSince (now.minusMinutes(1), "influxdb")  < 20)                                     
                                         
    {
     EnergyGenCuisiniereFullStatus.postUpdate(MODE_OFF)
    }

the “<” gave me error in Visula Studio Code
here is what i have

" Ambiguous binary operation.

The operator declarations

operator_lessThan(Number, Number) in NumberExtensions and

operator_lessThan(Type, Number) in NumberExtensions

both match.(org.eclipse.xtext.xbase.validation.IssueCodes.ambiguous_feature_call) "

and block other Rules , i try to convert

EnergyGenCuisiniereFullSum.averageSince(now.minusMinutes(1)) as Number

but in that case i have persistence problem

thanks for helping me

You did not cast to Number :smiling_imp:

Change the code to

if ((EnergyGenCuisiniereFullSum.averageSince(now.minusMinutes(1),"influxdb") as Number) < 20)

thanksssss a lot !! i learn but still have issue whith syntax as you can see, again thanks ! Also if u have a link or anything can help to learn java and or python especialy for openhab scripting a take it ! :+1: