I wrote a script to test if I can get access to the script associated with a rule (8e5cd6e905 in my set of rules).
Using jq, I can get access to the script using the following command:
/usr/bin/jq ‘.“8e5cd6e905”.value.actions | . | .configuration.script’ automation_rules.json
I was forced to use “” with the uid to make it to work.
I tried to do it within a script:
var String uidtest = "\"8e5cd6e905\"" + ".value.actions | . | .configuration.script"
var String jqresult_script = executeCommandLine(Duration.ofSeconds(1),"/usr/bin/jq", uidtest, "/openhab/userdata/jsondb/automation_rules.json")
Unfortunately, I got the following error:
2021-03-19 10:59:08.337 [INFO ] [org.openhab.core.model.script.exec ] - jq: error (at /openhab/userdata/jsondb/automation_rules.json:1532): Cannot index string with string "value"
Do you have any idea why I got this error ?
If I solve this issue then the following script can iterate over the set rules:
var String jqresult_uid = executeCommandLine(Duration.ofSeconds(1), "/usr/bin/jq", ". | .value.uid", "/openhab/userdata/jsondb/automation_rules.json")
var String listuid = jqresult_uid.replace('"\n', ',').replace('"','')
val arrayuid = listuid.split(',')
// iterate over the list of rules - just display the uid in the log
arrayuid.forEach[ num | logInfo("exec", "" + num + "") ]
Thanks in advance