Error during invoke method - on instance: null?

Hi there,

I’m having a weird error that I don’t know how to interpret.
This is my rule:

rule "Washingmachine Consumption State Machine"                                                                                                                
when                                                                                                                                                           
        Item homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER changed                                                                             
then                                                                                                                                                           
        logInfo("wmspwr", homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.state)                                                                 
        logInfo("wms", "test") 

And this is what I have in the output (openhab.log):

2019-06-10 21:51:42.289 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Washingmachine Consumption State Machine': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

what does this mean?
After all the rule is triggered by a change to exactly this item, so why can it be null?
The same happens with:
logInfo(“wm:avg”, homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)))

I see log entries in events.log with:
homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER changed from 5.37 W to 116.96 W

It means the action (loginfo) is expecting a string
The item’s state is not a string
Try myitem.state.toString

Ah right, my mistake - however, with this rule:

rule "Washingmachine Consumption State Machine"                                                                                                                                                                     
when                                                                                                                                                                                                                
        Item homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER changed                                                                                                                                  
then                                                                                                                                                                                                                
  //logInfo("wm:avg", homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)))                                                                                              
        wm_avg.postUpdate(homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)))                                                                                          
        var Number pwr = (homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.state as QuantityType<Number>).doubleValue                                                                                  
        if(wm_state.state == "OFF" && pwr > 0) {                                                                                                                                                                    
                wm_state.postUpdate("STANDBY")                                                                                                                                                                      
                wm_trigger.postUpdate(OFF)                                                                                                                                                                          
        }                                                                                                                                                                                                           
                                                                                                                                                                                                                    
        if (pwr > 10) {                                                                                                                                                                                             
                wm_state.postUpdate("ACTIVE")                                                                                                                                                                       
                wm_trigger.postUpdate(OFF)                                                                                                                                                                          
        }                                                                                                                                                                                                           
                                                                                                                                                                                                                    
        if (homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)) < 50) {                                                                                                 
                wm_trigger.postUpdate(ON)                                                                                                                                                                           
        }                                                                                                                                                                                                           
                                                                                                                                                                                                                    
        if (homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)) < 5) {                                                                                                  
                wm_state.postUpdate("STANDBY")                                                                                                                                                                      
        }                                                                                                                                                                                                           
                                                                                                                                                                                                                    
                                                                                                                                                                                                                    
        if(wm_state.state == "STANDBY" && pwr < 1) {                                                                                                                                                                
                wm_state.postUpdate("OFF")                                                                                                                                                                          
        }                                                                                                                                                                                                           
                                                                                                                                                                                                                    
end 

I’m now getting:
2019-06-10 22:55:51.358 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Washingmachine Consumption State Machine’: The argument ‘state’ must not be null.

What causes this?

The items are:
String wm_state “Washingmachine State [%d]”
Switch wm_trigger { expire=“1m,command=OFF” }

Top tip: sprinkle logInfo() in your suspect rules to find out how far it gets before throwing the error, and to show the values of variables that might be involved.

I’ll take a guess, as the error complains about argument, that the error arises from
wm_avg.postUpdate(homematic_HG_HM_ES_PMSw1_Pl_DN_R1_17b78d3e_OEQ1545405_2_POWER.averageSince(now.minusMinutes(2)))

postUpdate() expects a valid Item state as an argument. Maybe the averageSince is not returning what you expect. Is this Item persisted?
There’s a useful looking logInfo commented out, that seems unwise while you are fault finding.