Search function over all rules and their script contents

Upgrading to OH3, I now use the UI based definition for rules instead of the rules files as I did with OH2.

Previously in OH2 I could simply search all the files in Visual Studio Code to determine which items are used in which rules.

Is there a way to search all rules in the OH3 UI based rules to determine, for example, in which rules a certain item is used?

So far I have not found a search function on the rules for such a usage list of the items.

Such a search function could be possible but it’s not been implemented yet. I’m not sure if an issue has been created yet or not but it would be useful.

In the mean time if you want to search by hand you can do what I do. Everything saved in the UI is saved as text so all the usual command line tools for searching through and viewing text work.

  • To see what types of entities an Item is used in use grep <name of Item> *.json from the $OH_USERDATA/jsondb folder (usually /var/lib/openhab/jsondb). For example
rich@argus:/s/o/u/jsondb (main) ✗ 👁️  grep BasementSensors_Humidity *.json
org.openhab.core.items.Item.json:  "BasementSensors_Humidity": {
org.openhab.core.items.Metadata.json:  "stateDescription:BasementSensors_Humidity": {
org.openhab.core.items.Metadata.json:          "BasementSensors_Humidity"
org.openhab.core.items.Metadata.json:        "uid": "stateDescription:BasementSensors_Humidity"
org.openhab.core.items.Metadata.json:  "listWidget:BasementSensors_Humidity": {
org.openhab.core.items.Metadata.json:          "BasementSensors_Humidity"
org.openhab.core.items.Metadata.json:        "uid": "listWidget:BasementSensors_Humidity"
org.openhab.core.thing.link.ItemChannelLink.json:  "BasementSensors_Humidity -\u003e mqtt:topic:mosquitto:basement_sensors:humi": {
org.openhab.core.thing.link.ItemChannelLink.json:      "itemName": "BasementSensors_Humidity"

That shows that the Item exists, it has some Item metadata, and it’s linked to a Channel.

If the Item shows up in automation_rules.json you know that the Item is used in rules. However, you’ll have to open the file and search for the Item name to figure out which rule it’s used in because grep will only show you the line it occurs on which does not include the rule’s ID or description.

But, here’s a challenge. No search like this is going to be comprehensive. For example, that humidity Item doesn’t show up in automation_rules.json in the search at all but I’ve several rules that use that Item. That’s because those rules are triggered by a Group and the Item is never actually referenced by name. Dealing with that case is going to be the major challenge.

A proper search function would use the REST API. It would need to basically do the same things I just demonstrated above using the results returned by the REST API which might be a little easier since it can use some JSON processing tools.