Get thing from UI based javascript rule

Hi,

I have a UI based javascript rule (OH 3.4.0), it’s triggered by multiple things status event. I would like to access the thing who had triggered the rule withing the javascript.

The event object does output the thing uid when I push it to console.log, but the UI nor the documentation gives me options to get the thing uid from a nested variable/method.

console.log("Event : ", event);

Outputs:

2022-07-05 11:35:47.839 [INFO ] [nhab.automation.script.ui.f54bdfba1d] - Event :  Thing 'mqtt:topic:3fa3357405:ea520bfbcd' updated: UNINITIALIZED

But how to get the thing uid?

Thanks!

The event Object is inadequately documented for sure. For now, I think the best source for that is at Event Object Attributes — openHAB Helper Libraries documentation.

You don’t say what the event triggers are though so there are a couple of options. event.thingUID should have the UID for Thing changed triggers. However, if it’s a Channel trigger event, what’s there depends on the binding.

If you ever want to really see what’s in an Object, it’s even better to use utils.dumpObject(event). This will interrogate the Object and dump out all the data members and I think functions too (there are not functions on the event Object though) as well as some additional useful info.

I don’t think utils.dumpObject() is documented in the JS Scripting API docs for some reason. There’s lots of good stuff in utils so I should look into that.