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?
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.
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.
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?
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.
@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.