Items not recognized inside rules

Hello!

I’m trying to execute simple rule, which will post update to an item when motion is detected (item with sensor_binary value received update), but neither ESH Designer nor OpenHAB 2 recognize the item I’m trying to post update to. The rule is triggered correctly every time, but after triggering the rule, it raises an exception in the log file:

2016-10-15 23:28:00.399 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Sensors - Multisensor - Lobby - Motion - Value changed’: An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null

The item I’m trying to update has the following definition:

String TestItem

and the rule is:

rule "Sensors - Multisensor - Lobby - Motion - Value changed"
when
Item Sensors_Multisensor_Lobby_Motion_Value received update
then
TestItem.postUpdate(“It works!”)
end

In the Designer it raises error “The method or field TestItem is undefined”. I’ve tried using old syntax too (postUpdate(TestItem, “It works!”) but it’s not working either. I’ve also tried using other items, even the one in the trigger, but it always shows the same error, both, in Desinger and it the log. Anyone has an idea of what is going on here, and why rules engine doesn’t recognize my items?

Best regards,
Davor

Hi Davor, two ideas:

  1. do you have this item on your sitemap?
  2. are you sure, name and/or lower/upper case is written the same way in all your definitions?

Hello!

  1. I haven’t tried putting it on the sitemap, because it wasn’t working at all. I’ll try putting it on sitemap to see if that helps.
  2. Every item name I’ve tried using within rules I’ve copied from the items file, so the spelling or case are not the problem.

Thank you for your help.

Best regards,
Davor

Hello!

I’ve just tried putting the item, I’m trying to post to from rule, to the sitemap, but it still shows it as undefined in Designer and raises an exception when the rule is triggered.

Best regards,
Davor

1 Like

Hi,
this is a working rule:

rule UpdateRaspberryTemp
	when 
	    Time cron "0 0/1 * * * ?"   // every minute
	then
        val String results = executeCommandLine("/etc/openhab2/scripts/rbptemp.sh", 5000)
        RaspberryTemp.postUpdate(results)
        logInfo("RULE:UpdateRaspberryTemp", "Reading system temperature from raspberry")
        logInfo("RULE:UpdateRaspberryTemp", results)
	end

The main difference I see is, I’m posting a variable - and no fixed string between quotes. Maybe this leads to some wrong interptetation by the formatter or whatever.

Maybe you try to define a variable, assign a value to this variable - and try to post the variable to the item.

Btw…ignore the error in the designer; I get the same (wrong) highlighted errors, but the rule works. Just replace the exec-part by some fixed value.

Hello!

I’ve tried using various combinations of item and variable types, but still can’t make it work. Since I’m new to OH2 I was wondering if there is some binding/action/something that has to be installed to make rules work? I’ve installed Astro and Z-Wave binding, RRD4J persistence, Classic, Basic, HABMin and Paper UI, MAP transformation, my.Openhab and REST documentation (via Paper UI interface). Is there anything else that should be installed this way? Or, is there some setting in .cfg that will make OH2 “see” items inside rules and make postUpdate and sendCommand actions work with those items?

Best regards,
Davor

There is currently an open issue in Designer. The current version is broken and cannot recognize your Items. My rules are one big mass of red underlines as a result. So right now you cannot rely upon the errors reported in Designer in this case.

There isn’t. Rules are there by default.

When you put TestItem on your sitemap were there any errors or warnings in the logs indicating that it can’t find TestItem? If so my first guess would be that you have a hidden character or syntax error in your .items file which is preventing TestItem from being parsed and created as an Item inside OH.

Hello!

@Boby, @rlkoshak, thank you for your help. Main problem was pretty misleading error message in the log. The designer was showing items as undefined, so I assumed that this error message was the result of the same problem. As it turns out, using the real item before I’ve tried the rule with simple String item, a problem was incompatible data types. After trying to use String, TestItem.postUpdate(“It works”) was not working because rules were not refreshed, even though I’ve restarted OH.

Once again, thank you both for your help.

Best regards,
Davor