Just a quick question that I haven’t found a good answer to despite a few hours forum search.
I’m running OH3 and do semi-regular openhab-cli backups making the xxx.zip files.
All my 40+ rule bodies must certainly be part of these backup files, and my question is simply:
Is there a way to extract a particular rule body from an older backup file?
Reason is, I need to gain access to an earlier version of a complex rule.
Yes. Managed rules are stored in
Note, there are limitations with JSON which means your code is going to be a bit ugly in the raw JSON. You might need to do some formatting of it to make it human readable or, my recommendation, insert the rule temporarily using the REST API and you’ll be able to see everything in MainUI.
I’m not entirely certain what you mean by “body” and am assuming you mean the Script Actions.
Here’s an example of what it’ll look like:
You’ll find the “code” under “actions” and “conditions”.
What you will notice is that certain characters are replaced with the unicode encoding (e.g.
= converts to
\u003d) and newlines are replaced with
Rich, you’re good! I found my old rule. Thanks a million!!
A more general question on this if I may:
I started my OH journey with OH2 files only, MS Code, WinSCP and an RPi.
So, off-line file build, edit, access, save, archiving and subsequent transfer to prod unit. (Very easy and transparent off-line file and system management!).
On OH3 I find this not equally easy. The only historical transparency option seems to be “openhab-cli backup” unless I go the files only route and accept the file locking, which may not be all that bad.
But I’m just a user now, so how do you professionals go about to make it easy for yourself when you need to dive into past?
I’m doing it as you described. I use file based configuration and have all files in a versioning system.
That way I can go back and forth in time. Most of the time I remember e.g. in which file the change was because they are named accordingly. That way I find the change (most of the time) very quickly.
I have been playing with OH3 for almost a year now and I still find myself missing the OH2 files only concept.
I guess I have a rather small system with 150+ Items and 40+ Rules, but there are times when I feel that the OH3 GUI gets too fragmented (40 rules vs 1 rule file), and searching and updating gets less efficient when two or more rules are communicating via Items.
Just my thoughts, and yes, I’m considering returning to files only.
But, I wonder what others feel and do ?
I check all my configs into
git. I run GitLab at home but there are lighter weight options like Gitea or Gogs or you can use a publicly hosted service like Github (most of these support private repos). But you can even just set git up without a nice web front end.
Everything configured through MainUI gets reflected in the files under userdata/jsondb (almost everything), userdata/etc (logging configs mainly), and jsondb/config (which addons are installed, regional settings, etc).
I try to commit (sometimes fail) any changes I’ve made with reasonable messages so it’s easy to back track and compare between versions.
I can compare changes between versions usually pretty easily as well.
Obviously it’s not perfect. Because JSON doesn’t support newlines the whole script gets merged into one line so you have to do a little bit of mental parsing to see the differences, but the actual changed bits are highlighted so it’s not hard by any means.
Usually people want to separate their rules into multiple files.
Definitely explore the developer sidebar. It has a search and pin feature so that you can collect all the Things, Items, Widgets, and Rules you are working on in one list and easily navigate between them and manipulate them. You can also search for Items with a given Item metadata and I think I saw a PR recently to find which Things and Links use a given transformation.
If those rules mention those Items by name, searching for the Item Name will give you everywhere that Item is used. It does a plain text search inside the rule.
For example, I was working on integrating Virtual Solar Light Sensor [18.104.22.168;22.214.171.124] into my system. So I pinned all the relevant Items, Things, and Rules:
As you can see, I can navigate to any of these by clicking the pencil icon. Those Items that are configured to be editable I can click the > to bring up the widget to edit it (e.g. toggle a Switch, great for testing). I can enable/disable Rules and Things and manually run rules, all from that sidebar.
With the sidebar I’m able to be more productive than I ever was with text files because it’s all right there. (Note, that’s just one of the tabs in the sidebar, the other three are just as useful).
Very enlightening as usual. Will give it a try.