Linage for thing usage in items and rules

As my openhab system grows, I do sometimrs loose oversight where do i used a certain switch. I have played around with naming conentions, file search splitted versus consolidated rule files. All of that doesn’t really satisfied me in the end.

I am in the Business Intelligence space for around 25 years and there linage is key to be able to manage solutions. Because content is mostly created by someone else.

My thought is that a design pattern like linage will truly make life easier for any oh user. This especially will be true, when you only changing things from time to time and may forgot about how you build your workflows with items and rules.

What is Your opinion about this?

Thank You

Markus

Could you please help me out and tell me what “linage” is? Maybe a link or two for people who are not in the BI business?

1 Like

I’ve moved the post from Development as that category is for issues related to the development of OH itself, not the development of your configuration.

I think it would be a hell of a lot of work and ultimately not be all that useful for most users. And even if it were, there are more appropriate tools/approaches from the realm of software engineering than BI Lineage.

Stuff doesn’t move around like it does in BI. The graphs will be very flat. Thing’s Channels can only be linked to Items. Items can only be used in Rules, Sitemaps/HABPanel, and Persistence. That’s it. From any entity to any other entity there’s only three levels in the graph with Things/Channels always on the left, Items always in the middle, and Rules/Sitemaps/HABPanel/Persistence on the Right. And of the things on the right, the only one that has place where an Item will be used in more than a couple of places is Rules.

And there are ways to get the information you are after using standard Linux tools or tools built into IDEs like VSCode.

In my experience, tools like BI Lineage and Ontologies and stuff like that only make sense when you have lots of people working on massive amounts of information or really large projects. When you try to apply it to something at the scale of an individual OH instance, it’s not worth the effort to both learn and apply and it ultimately leads to no actually useful information or insights that couldn’t be found out in some much more direct and simple manner.

But that’s just my opinion. If you want to give it a try, by all means do so and post your results.

In the mean time there are Linux command line tools you can use to answer a lot of the sorts of questions you would have about your configuration.

Want to see where an Item is used in a .rules?

grep -R vTimeOfDay 

I use Python rules and subfolders so am using the recursive flag. For Rules DSL, run from the rules folder, get rid of the -R and add *.rules to the end of the command.

christmas.py:@when("Item vTimeOfDay changed to EVENING")
christmas.py:@when("Item vTimeOfDay changed to NIGHT")
media/roku.py:@when("Item vTimeOfDay changed to 'BED'")
entry/door_reminder.py:    return (items["vTimeOfDay"] == StringType("NIGHT")
entry/door_reminder.py:                or items["vTimeOfDay"] == StringType("BED"))
lights/lights_control.py:@when("Item vTimeOfDay changed")
lights/lights_control.py:    offGroupName = "gLights_OFF_{}".format(items["vTimeOfDay"])
lights/lights_control.py:    onGroupName  = "gLights_ON_{}".format(items["vTimeOfDay"])
lights/lights_control.py:    tod_lights.log.info("Turning off the lights for {}".format(items["vTimeOfDay"]))
lights/lights_control.py:    tod_lights.log.info("Turning on the lights for {}".format(items["vTimeOfDay"]))
lights/weather_lights.py:@when("Item vTimeOfDay changed")
lights/weather_lights.py:    if (items["vTimeOfDay"] != StringType("DAY") or
lights/weather_lights.py:    if event.itemName == "vTimeOfDay":
lights/weather_lights.py:                           .format(items["vTimeOfDay"], items["vIsCloudy"]))
lights/weather_lights.py:    # Wait a minute before reacting after vTimeOfDay changes, ignore all other
lights/weather_lights.py:    if (items["vTimeOfDay"] != StringType("DAY") or
lights/weather_lights.py:        (PersistenceExtensions.lastUpdate(ir.getItem("vTimeOfDay"), "mapdb")
lights/weather_lights.py:@when("Item vTimeOfDay changed")

Want the line numbers it occurs in each file?

grep -Rn vTimeOfDay
christmas.py:8:@when("Item vTimeOfDay changed to EVENING")
christmas.py:9:@when("Item vTimeOfDay changed to NIGHT")
media/roku.py:11:@when("Item vTimeOfDay changed to 'BED'")
entry/door_reminder.py:31:    return (items["vTimeOfDay"] == StringType("NIGHT")
entry/door_reminder.py:32:                or items["vTimeOfDay"] == StringType("BED"))
lights/lights_control.py:5:@when("Item vTimeOfDay changed")
lights/lights_control.py:7:    offGroupName = "gLights_OFF_{}".format(items["vTimeOfDay"])
lights/lights_control.py:8:    onGroupName  = "gLights_ON_{}".format(items["vTimeOfDay"])
lights/lights_control.py:10:    tod_lights.log.info("Turning off the lights for {}".format(items["vTimeOfDay"]))
lights/lights_control.py:13:    tod_lights.log.info("Turning on the lights for {}".format(items["vTimeOfDay"]))
lights/weather_lights.py:12:@when("Item vTimeOfDay changed")
lights/weather_lights.py:15:    if (items["vTimeOfDay"] != StringType("DAY") or
lights/weather_lights.py:25:    if event.itemName == "vTimeOfDay":
lights/weather_lights.py:29:                           .format(items["vTimeOfDay"], items["vIsCloudy"]))
lights/weather_lights.py:43:    # Wait a minute before reacting after vTimeOfDay changes, ignore all other
lights/weather_lights.py:45:    if (items["vTimeOfDay"] != StringType("DAY") or
lights/weather_lights.py:46:        (PersistenceExtensions.lastUpdate(ir.getItem("vTimeOfDay"), "mapdb")
lights/weather_lights.py:61:@when("Item vTimeOfDay changed")

Want how many times it appears in each file?

grep -Rc vTimeOfDay
hvac/fan.py:0
hvac/humidity.py:0
hvac/nest_chart.py:0
alarms/alarms.py:0
christmas.py:2
utilities/estimate_powerbill.py:0
utilities/reset_powermeter.py:0
dp/todo.txt:0
dp/tod_ephemeris.py:0
dp/item_init.py:0
dp/expire.py:0
weather/condicon.py:0
weather/cloudy.py:0
nightscout/nightscout.py:0
admin/offline_alert.py:0
admin/device_offline.py:0
admin/reset_expire.py:0
admin/get_latest.py:0
admin/charting.py:0
admin/ups.py:0
media/roku.py:1
eventbus/eventbus_sub.py:0
entry/door_reminder.py:2
entry/garage_openers.py:0
presence/update_nest.py:0
presence/reset_presence.py:0
presence/presence.py:0
presence/manticore.py:0
dad/motiontimer.py:0
lights/lights_control.py:5
lights/weather_lights.py:8
README.md:0

Want to know how many times the Item is used across all your rules files?

grep -R vTimeOfDay | wc -l

18

Want just a list of the files that the Item is used in at least once?

grep -Rl vTimeOfDay
christmas.py
media/roku.py
entry/door_reminder.py
lights/lights_control.py
lights/weather_lights.py

Want to see which files it appears in across ALL of your files?

grep -Rl vTimeOfDay

Run from the $OH_CONF folder

automation/jsr223/python/personal/christmas.py
automation/jsr223/python/personal/media/roku.py
automation/jsr223/python/personal/entry/door_reminder.py
automation/jsr223/python/personal/lights/lights_control.py
automation/jsr223/python/personal/lights/weather_lights.py
automation/lib/python/configuration.py
automation/lib/python/personal/util.py
automation/lib/python/personal/util$py.class
automation/lib/python/configuration$py.class
sitemaps/wh.sitemap
items/weather.items

You might need to run additional queries if you have the Item as a member of a Group. And if you use managed Items, Things, and Rules you might need to include the jsondb folder in your grep. If you use HABPanel you need to include userdata/conf/org/openhab/habpanel.conf in your grep.

I refering to meta data linage like here https://powerbi.microsoft.com/en-us/blog/introducing-power-bi-lineage-view/ in Power BI. I must admit that on first hand it might look a little to less beneficial and there are good command line tools that retrieve that info. On the other hand especially users with no or little experience will struggle to use them and keep their things, items and rules organized. Ie. being aware what causes a certain powerplug to switch, when you use item groups and multiple rules.

I am in prep for a sample visualization of the item - > rule relations with Power BI (because it is free available), that everyone can use and modify to its needs. I will do a post here as soon as it is ready.