How to get the name of a rule from it's id with jsr223 / Jython rules?

jsr223.log reports errors running a script like this:

 Failed to execute rule '747f6553-7ef1-4ff4-bdbc-0a085443d8df': Fail to execute action: 1

My current modus operandi is to open paperUi/rules section and then search for that id which is somewhat frustrating. Is there a way to get the name of a failing rule listed along with the id?
or a command line query to get the name from the rule registry?

There is a feature request from a long time ago requesting this. I half implemented it before the ESH reintegration and build system change, which screwed up several of my development environments, including the one with those changes. The local repos are still there, so it shouldn’t be lost. I expect that some day this will get merged in.

Until then, you can get the name of the rule by searching for the UID in Paper UI> Rules. This could also be done in a script…

rule_name = [rule for rule in rules.getAll() if rule.UID == "747f6553-7ef1-4ff4-bdbc-0a085443d8df"][0].name

Edit: Here is the feature request, which has not been copied over from the ESH repo…

1 Like

You can go to the karaf console
openhab> smarthome:automation listRules

1 Like

so, answering my own question thanks to your input, here is the bash one-liner, wrapped into a script for easy insertion of the parameter, which returns the name of a rule by it’s id:

echo `ssh -p 8101 openhab@localhost smarthome:automation listRules|grep  $1| awk  '{print $3}'`

(to avoid the password dialog I configured private/public key access to karaf following Remove openhab password )

Why not do it directly with the example I provided?

your line of code looks elegant but I failed to understand how to implement it.

And ‘directly’ is a relative measure. I see the error message in a tab of konsole (KDE) and have a bash script that allows me to find the script name right there with

$ f522c593-4b5a-45af-bda7-ec612e8347fa

in the same window, w/o the need to find the browser instance/tab with paperUi running - it is direct in a way.

Just put it in a script and save…

from core.log import logging, LOG_PREFIX#, log_traceback
LOG = logging.getLogger("{}.TEST".format(LOG_PREFIX))
rule_name = [rule for rule in rules.getAll() if rule.UID == "03706a59-b008-45c2-b13e-da32efdd8bd6"][0].name

I always have VS Code and a screen tailing the log file though.

Not at all… a scripted automation can directly access the rule engine. Your shell script uses the REST API to communicate with the rule engine.

1 Like