Problems getting triggeringItem.name in a rule

Hi, i am using OH 3 on a Win 10 64 Bit system.

I have problems with a rule when i try to get “triggeringItem.name”.
Here is my rule:

rule "Get Item Name"
when
  Member of gEneTotal changed 

then
          logInfo("TEST", "+++++++++ GET triggeringItem.name  +++++++ : "  + triggeringItem.name)
          logInfo("TEST", "+++++++++ GET triggeringItem.state+++++++ : "  + triggeringItem.state)
          logInfo("TEST", "+++++++++ GET triggeringItem.label+++++++ : "  + triggeringItem.label)
end

I remeber that it was possible in OH 2.5.
Since i moved to 3.2.0.M2 - Milestone Build i tried several times and different ways to get the name from the item that triggered the rule.

Here is the output from logging:

2021-10-19 13:07:04.521 [INFO ] [org.openhab.core.model.script.TEST  ] - +++++++++ GET triggeringItem.state+++++++ : 121.114
2021-10-19 13:07:04.522 [INFO ] [org.openhab.core.model.script.TEST  ] - +++++++++ GET triggeringItem.label+++++++ : Energie Total

I need the triggeritem.name to execute some SQL querys.
Would be very appreciated for help.

This is interesting.
There have been changes in this area for OH3.

Implicit variable triggeringItem now only exists when there is a Member of xx rule trigger (in OH2 it existed under some other circumstances as well).
That’s okay, you do have a Member of type trigger.
And you can prove it works with triggeringItem.state etc.

There is also a new implicit variable triggeringItemName which isn’t limited to Member of rule triggers. This one is just a string, the name only.

So you can try triggeringItemName in your rule, just as a sanity test.

You might also try the less commonly used .getName() synonym.

         logInfo("TEST", "+++++++++ GET triggeringItemName  +++++++ : "  + triggeringItemName)
         logInfo("TEST", "+++++++++ GET triggeringItem.getName()  +++++++ : "  + triggeringItem.getName())
         logInfo("TEST", "+++++++++ GET triggeringItem.name  +++++++ : "  + triggeringItem.name)

but of course triggeringItem.name should be working.
It’s just possible a bug was introduced with the new change, but if so it is a very weird kind of bug.

From what you’ve shown us your logInfo() for .name neither throws an error nor produces any output, I’ve no idea how that could happen. Sure your edited rules file has been saved and read correctly? Sure you are looking at complete log entries?

Hi Rossko57,
this is a very weird behavior.
I tested also

rule "Get Item Name"
when
  Member of gEneTotal changed or
  Member of gEneTotal received update  

then
val membername = triggeringItem.name.split("_").get(1) //Schlaf, TV, Trock, etc.

          logInfo("TEST", "+++++++++ GET membername+++++++ : "  + membername)
          logInfo("TEST", "+++++++++ GET triggeringItemName+++++++ : "  + triggeringItemName)
          logInfo("TEST", "+++++++++ GET triggeringItem.state+++++++ : "  +  triggeringItem.name)
          logInfo("TEST", "+++++++++ GET triggeringItem.state+++++++ : "  + triggeringItem.state)
          logInfo("TEST", "+++++++++ GET triggeringItem.label+++++++ : "  + triggeringItem.label)

end


and the output is the following:

2021-10-19 15:24:44.170 [INFO ] [org.openhab.core.model.script.TEST  ] - +++++++++ GET membername+++++++ : Desk
2021-10-19 15:24:44.173 [INFO ] [org.openhab.core.model.script.TEST  ] - +++++++++ GET triggeringItem.state+++++++ : 121.114
2021-10-19 15:24:44.174 [INFO ] [org.openhab.core.model.script.TEST  ] - +++++++++ GET triggeringItem.label+++++++ : Energie Total


As you can see from the logs there is no output or error for:

triggeringItemName
triggeringItem.name

the rest works like expected.
The strange thing is that i can get a part of the itemname with split

I looked at an old backup from OH2.5 and i am pretty sure it worked before.
I had a similar rule.

Any other advices?

This is absolutely strange behavior. What ever the problem is it’s with the logger action.

What happens if you just flat out save the name to a local variable and log it? Both as a var and a val.

val iNameVal = triggeringItem.name
var iNameVar = triggeringItem.name

Also trigger the rule with an Item you know head of time (this Desk Item I would use) and log the name that way.

logInfo(Something_Desk.name)

What we want to do is figure out whether it’s a problem specific to that Item, specific to triggeringItem, or something else entirely.

I reckon there’s a filter on the logging.

1 Like

OK. Thanks
This was the solution.
I did not write it in my documentation. (Now updated)

When i changed the logging from org.ops4j.pax.logging.cfg to log4j2.xml
i wrote a filter for testing purposes and never jused it again.

Thanks for the hint and your help. Now it works as expected :slight_smile: :relaxed:

Hi,
I do have do have the similar issue after moving from OH 2.5 to OH 3.2.
This my current system:

Release = Debian GNU/Linux 11 (bullseye)

Kernel = Linux 5.10.0-10-amd64

Platform = QEMU Standard PC (i440FX + PIIX, 1996)

Uptime = 0 day(s). 0:36:6

CPU Usage = 6.44% avg over 4 cpu(s) (2 core(s) x 1 socket(s))

CPU Load = 1m: 0.24, 5m: 0.13, 15m: 0.10

Memory = Free: 2.80GB (73%), Used: 1.03GB (27%), Total: 3.83GB

Swap = Free: 0.95GB (100%), Used: 0.00GB (0%), Total: 0.95GB

Root = Free: 25.50GB (88%), Used: 3.31GB (12%), Total: 30.38GB

Updates = 0 apt updates available.

I haven’t changed something on the logging but get this faults:

2022-01-02 16:35:30.090 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘12_light-8’ failed: cannot invoke method public abstract java.lang.String org.openhab.core.items.Item.getName() on null in 12_light

when I am using “+ triggeringItem.name” within a logInfo() call in a rule. If I use the instead “triggeringItemName” everything works fine.

Well, it would be easy to replace those strings, but I want to understand whats going wrong, especially because I do have a lot more problems with my rules in OH3.

Regards
Ronny

That is an announced breaking change between OH 2 and OH 3. triggeringItem only exists for rules triggered by a Member of trigger. All other Item triggered rules have triggeringItemName only.

THX for that clarification.
Is there a summary of all breaking changes between OH 2 and 3? This would be very helpful for a novice :wink:

1 Like