Rule Error - cannot be resolved to an item or type


I’m having trouble understanding what the cause of the following error is:

[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Energy Totals: An error occured during the script execution: The name 'Energy_Day_Consumed' cannot be resolved to an item or type.


rule "Energy Totals"
	Time cron "0 0 0 ? * * *"
	var Double d1 = ((Energy_Sum_Consumed.deltaSince(now.minusDays(1))) as DecimalType).doubleValue
	var Double d2 = ((Energy_Sum_Produced.deltaSince(now.minusDays(1))) as DecimalType).doubleValue
	var Double d3 = ((Energy_Buy.deltaSince(now.minusDays(1))) as DecimalType).doubleValue
	var Double d4 = ((Energy_Sell.deltaSince(now.minusDays(1))) as DecimalType).doubleValue
	var Double d5 = ((Energy_Account_Balance.deltaSince(now.minusDays(1))) as DecimalType).doubleValue

    logInfo("Energy_Day_Consumed: ", d1.toString)
    logInfo("Energy_Day_Produced: ", d2.toString)
    logInfo("Energy_Day_Buy: ", d3.toString)
    logInfo("Energy_Day_Sell: ", d4.toString)
    logInfo("Energy_Day_Balance: ", d5.toString)

	postUpdate(Energy_Day_Consumed, d1)
	postUpdate(Energy_Day_Produced, d2)
	postUpdate(Energy_Day_Buy, d3)
	postUpdate(Energy_Day_Sell, d4)
	postUpdate(Energy_Day_Balance, d5)



Number Power_PV               "PV Power [%.0f]"                  <sun>        (power)       { http="<[inverter:1000:JSONPATH($.Body.Data.Site.P_PV)]" }
Number Power_PV_MPPT1_S       "MPPT1 DC Power Scaled [%d]"       <solarplant> (power)       { modbus="mppt1:2" }
Number Power_PV_MPPT2_S       "MPPT2 DC Power Scaled [%d]"       <solarplant> (power)       { modbus="mppt2:2" }
Number Power_PV_MPPT1         "MPPT1 DC Power [%d]"              <solarplant> (power)
Number Power_PV_MPPT2         "MPPT2 DC Power [%d]"              <solarplant> (power)

Number Power_Grid             "Grid Power [%.0f]"                <energy>     (power)       { http="<[inverter:1000:JSONPATH($.Body.Data.Site.P_Grid)]" }
Number Power_Load             "Consumption [%.0f]"               <energy>     (power)       { http="<[inverter:1000:JSONPATH($.Body.Data.Site.P_Load)]" }
Number Power_Import           "Grid Power Imported [%.0f]"       <energy>     (power)
Number Power_Self_Consumed    "Solar Power Consumed [%.0f]"      <energy>     (power)
Number Power_Export           "Solar Power Exported [%.0f]"      <energy>     (power)
Number Power_Consumption      "Consumption [%.0f W]"               <energy>     (power)

Number Energy_Day             "Energy Total [%d]"                <energy>     (energy_day)  { http="<[inverter:1000:JSONPATH($.Body.Data.Site.E_Day)]" }
Number Energy_Day_Consumed    "Energy Consumed [%d]"             <energy>     (energy_day)
Number Energy_Day_Produced    "Energy Produced [%d]"             <energy>     (energy_day)
Number Energy_Day_Buy         "Energy Purchase Cost [%.2f]"      <piggybank>  (energy_day)
Number Energy_Day_Sell        "Energy Sell Credit [%.2f]"        <piggybank>  (energy_day)
Number Energy_Day_Balance     "Energy Account Balance [%.2f]"    <piggybank>  (energy_day)
Number Energy_Day_Total_Load  "Total Load [%d]"                  <energy>     (energy_day)
Number Energy_Day_SelfCon     "Energy Self Consumed [%d]"        <energy>     (energy_day)

Number Energy_Sum_Consumed    "Energy Consumed [%.0f W]"          <energy>      (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.EnergyReal_WAC_Sum_Consumed)]" }
Number Energy_Sum_Produced    "Energy Produced [%.0f W]"          <energy>      (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.EnergyReal_WAC_Sum_Produced)]" }

Number Energy_Buy             "Energy Purchase Cost [$ %.2f]"     <piggybank>   (energy)
Number Energy_Sell            "Energy Sell Credit [$ %.2f]"       <piggybank>   (energy)
Number Energy_Daily_Charge    "Energy Daily Charge Cost [$ %.2f]" <piggybank>   (energy)
Number Energy_Account_Balance "Energy Account Balance [$ %.2f]"   <piggybank>   (energy)

Number Meter_Power_P1         "Power Phase 1 [%.0f W]"            <flow>        (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.PowerReal_P_Phase_1)]" }
Number Meter_Power_P2         "Power Phase 2 [%.0f W]"            <flow>        (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.PowerReal_P_Phase_2)]" }
Number Meter_Power_P3         "Power Phase 3 [%.0f W]"            <flow>        (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.PowerReal_P_Phase_3)]" }
Number Meter_Power_Total      "Power Total [%.0f W]"              <flow>        (energy)      { http="<[meter:1000:JSONPATH($.Body.Data.0.PowerReal_P_Sum)]" }

String Power_Source             "Power Source"                    <switch>      (power)

Logfile output:

2017-09-28 20:43:41.148 [INFO ] [e.model.script.Energy_Day_Consumed: ] - 19322.0
2017-09-28 20:43:41.170 [INFO ] [e.model.script.Energy_Day_Produced: ] - 60555.0
2017-09-28 20:43:41.201 [INFO ] [rthome.model.script.Energy_Day_Buy: ] - 4.888466000000024
2017-09-28 20:43:41.227 [INFO ] [thome.model.script.Energy_Day_Sell: ] - 7.327154999999994
2017-09-28 20:43:41.228 [INFO ] [me.model.script.Energy_Day_Balance: ] - -1.3496889999999824
2017-09-28 20:43:41.234 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Energy Totals: An error occured during the script execution: The name 'Energy_Day_Consumed' cannot be resolved to an item or type.

I’m hoping someone might be able to point out what is causing the error?

Running openhab 2 on qnap nas.


Try to import

import org.openhab.core.library.types.*

What happens if you try

logInfo("[DEBUG]: ",

That is not needed and furthermore, they would need to import org.eclipse.smarthome.core.library.types.NumberItem if it were.

On its face, it is saying that Energy_Day_Consumed does not exist as an Item.

When faced with errors like this the first thing you should do is load your config into ESH Designer and see if it identifies any syntax errors.

Are there any errors in the logs when OH loads your .items file?

Now, something else that could be the problem is the fact that you are using the postUpdate Action instead of the postUpdate method. The Action only takes two Strings are arguments and the Rules Engine notoriously has difficulty recognizing that it can easily convert a Number into a String like it should. This is one of the main reasons why I insist that one should always use the methods wherever possible.

So either use Energy_Day_Consumed.postUpdate(d1) or postUpdate(Energy_Day_Consumed, d1.toString).

Finally, and this is more of a matter of style than anything, you would probably be better off not forcing d1 et al to a Double. At a minimum I’d use:

var d1 = Energy_Sum_Consumed.deltaSince(now.minusDays(1)) as Number

In this case, the Rules Engine is usually smarter about managing the types of numeric values using BigDecimal than you are so it is better to let it handle those sorts of conversions for you. In fact, had you used the above to populate d1, I think your original postUpdates would have worked, though I wouldn’t bet on that.

Firstly - thanks for the responses!.

Following Rich’s advice, I did a more thorough check of the log files and identified the following error:

[ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file '/share/openhab/items/solar.items': null.

As far as I could tell, the primary issue here was that the items were not being created, and therefore couldn’t be updated with the postUpdate. A reboot caused the entire system to fail - no items, no sitemaps etc (all failing for the same issue).

I’ve since reinstalled openhab 2 on the QNAP nas, updated to 2.2 snapshot and re-written the config files from scratch.
I’ve followed the recommended syntax from Rich:

var d1 = Energy_Sum_Consumed.deltaSince(now.minusDays(1)) as Number

And all is now working fine.

Thanks guys!