Script to find errors in items, rules and sitemap files

When an openHAB installation grows to many things, items, rules and sitemap files, openHAB lacks the ability to check for errors in those files, especially errors in rules files are reported only during execution of rules and there is no way to check a DSL rule without executing it.

The script here reads things, items, rules and sitemap files from the openHAB-conf folder and reports any errors which are detected. This functionality should be available in openHAB as a standard function:

Probably the script does not cover all situations, but it helps.

OH does do some of these checks. For example a Link that is missing the Channel or vise versa is reported. There’s are other checks too that your script doesn’t do yet that OH does like checking rule triggers, persistence configs and such. But your script does include some checks that OH doesn’t report.

My installation has grown over the years and I have over 2000 items covering 5 locations.

This script detected many issues that i had in rules undetected. The main problem is that wrong item names in rules are not reported before the rule is actually executed and by having rules that are only executed on January 1 or having rules that set values and should only fire once every day this is definitely a problem because such rules cannot be easily tested.

Over the years names of items change and a check similar to the one of the script would be a great functionality for every openHAB installation.

Another functionality that is not in openHAB and is causing more items than are actually necessary is a way to define for every item that a received update should be sent to mqtt automatically without having to use a rule for that.

Lots of ways you can handle this without extra Items.

One approach could be to put all the Items into a Group and trigger a rule that uses the publish MQTT action to send the message. No need for a separate Item.

If these Items are linked to something else you can use the follow profile to cause updates sent as commands to the MQTT channels.

If the topics published to are flexible, you can use the MQTT EventBus rule template (can be installed from the Add-on store in MainUI).

You might be able to use a Script profile if the follow profile doesn’t quite do what you need.

There really isn’t enough detail to be more concrete than that but I do know that you don’t need extra Items to do this.

Thanks for taking the time to answer, i will look into it in detail.

Lately there are more and more new projects on GitHub called xyz_to_mqtt which convert proprietary device protocols to mqtt, for example solaredge2mqt, zigbee2mqtt was one of the early ones. Probably everybody likes having all data on mqtt without having to search for ways how to get the data to mqtt.

openHAB can read data from a huge number of devices through bindings and it would really be a nice feature to get that data easily on mqtt.

Most of those tools support either the Home Assistant MQTT standard or the Homie MQTT standard. OH has plugins for both (and others) which enable automatic discovery and creation of the Things needed to interact with them. ZWave2MQTT even has a dedicated OH add-on.

You are always looking at this as “one openHAB instance”. In my scenario my brother has his own instance of openHAB and there is another openHAB instance in the office which collects temperature data and powers down equipment at 6PM. They all work even when there is no internet.

The only link that we have between all openHABs is that local mosquittos are interconnected through a bridge. To share data the easiest way is to put everything on the MQTT branch that is bridged and provide a things/items file which the other openHAB instance needs to use that data.

For example: openHAB collects data through a local modbus binding (heatpump, solar inverter, …). To provide this data on MQTT today a rule is required and I think that modbus data is something openHAB should be able to mirror to MQTT without any rules.

Without further information what am I supposed to assume? But none of the suggestions above are limited to running only one instance. I’ve run up to four instances of OH at the same time, each linked to the others. Nothing I describe above excludes that use case and much of it ius driven by that use case.

Which is the exact use case that caused me to write the MQTT EventBus in the first place.

But the “official” way to do this would be to use the Remote openHAB add-on through myopenhab.org. Each instance would have their own account on myopenhab.org. You’d create a Thing for each remote instance providing the credentials for each one on each OH instance. I would set up a special account for the Remote openHAB addon to use rather than your regualr account.

The Thing will create a Channel for each Item on that remote OH instance which you can link to a local Item. The local Item will receive the same updates and commands as the remote Item does.

No MQTT and bridged brokers are required. Just OH instances talking directly to each other using the native OH APIs.

A rule you don’t have to write though. You can install it like any binding. But a rule is not required either even when using MQTT.

Using a rule, you can find a rule template here: MQTT Event Bus [4.0.0.0;5.9.9.9]. I don’t have telemetry on it but based on views and downloads it’s been installed thousands of times.

It requiresthe JS Scripting add-on as it’s written in JS and I think it requires OHRT which can be installed through openhabian-conf or through a separate rule tempalte or manually using npm. See the post for details on how it works and prerequisites and such.

You install it from MainUI → Add-on store → Automation. Once installed create a new rule from MainUI → Rules → + and choose MQTT EventBus from the list of templates to base it on. Fill out the properties based on what you want (you’ll need two Groups and the Broker Thing) and you are done. The rule will publish commands and updates to <what ever you choose as the root topic>/<item name>/command and <what ever you choose as the root topic>/<item name>/state based on membership to the two Groups.

The rule subscribes to those topics. For example, if a message is posted to richsoh/MyItem/state and the rule template is configure to listen on richsoh and MyItem exists locally, MyItem will be updated based on the contents of the message. Commands are handled the same way. Publishing is based on Group membership but it’s easy to change the rule trigger to trigger on all Items updates and commands.

And this is what the follow profile is for and how you can do this still using MQTT without any rules. The MQTT channel follows what the modbus channel is publishing. So when the modbus channel posts an update, that gets sent to the MQTT Channel and published to the topic configured on the MQTT Channel. No rule involved.

But having this all work without any work on your part is never going to happen. There is no one-size-fits-all approach that will work for all users. But in summary, OH offers the following to solve this use case:

Thank you for the exact explanation. Don’t worry, i am typing since 40 years and that is why i like using things and items files. But now I have a new friend “Claude” who does a lot of typing for me :smiley:

Still for me the common thing that i think that makes things work together is mqtt. Then i can connect anything to it, python scripts. probably HA (which I never even tried) and my own software. I could base everything on openHAB but I like open protocols and the power of python scripts running independently. I have a raspi zero playing music in the garden and i trigger it through mqtt and there is only one python script running on it.

I will try your suggestions next weekend! Thank you!

I am quite astonished that my raspi4 still manages to run openHAB with more than 2000 items and lots of rules without any problems. openHAB really does it’s job very well!

I don’t see why the frequency of the rule makes a difference. Rules can be manually triggered at any time in the UI regardless of the details of the trigger. If they set values that you want to unset, you can do that using the Rest API.

On January 1 at midnight i run a rule which reads the current value of all energy meters and stores the values in retained mqtt topics. I use these values to calculate consumed and produced energy since January 1 and display them in sitemap at any time during the year.

If I run the rule on April 5 then I lose the values which were stored on January 1 because energy meter values increment constantly.

Retained mqtt values work for me because i have 4 bridged mosquittos and even if i reinstall one the other ones still contain retained values.