Restore Habpanel settings from files

The habpanel documentation here explains how to setup a dashboard from the GUI.
Is there a programmatic way to setup the dashboard?
For example, after openhab upgrade, I want to restore the habpanel configuration from file using the command line (instead of clicking buttons from habpanel GUI to import the json file)
Is there a plain file that stores the habpanel dashboard information that I can backup and restore from?

Thanks,
Avner

I have found 2 (don’t ask me why 2… maybe something is wrong with my setup… they have different file size also… i will compare them :slight_smile: )

/var/lib/openhab2/config/org/openhab/habpanel.config
/var/lib/openhab2/config/org/openhab/ui/habpanel.config

edit: this one seems to be the correct one: /var/lib/openhab2/config/org/openhab/habpanel.config
the other one (ui/) in my system must be a left over from a previous snapshot installation (dating back to Jan 2017)

I have these files too.
Indeed, the file /var/lib/openhab2/config/org/openhab/habpanel.config contains the information, but in cryptic format (see note1 below). The habpanel was generated from a human readable json file that was imported via the GUI.
For restore purposes, is there a way to feed this human readable json file, without having to re-import through the GUI?


note1 - the file habpanel.config stores the habpanel configuration is stored in cryptic format

panelsRegistry="{\n\ \ \ \ \"Moshkovitz1take1\":\ {\n\ \ \ \ \ \ \ \ \"updatedTime\":\ \"2017-04-05T02:46:20.816Z\",\n\ \ \ \ \ \ \ \ \"dashboards\":\ [\n\ \ \ \ \ \ \ \ \ \ \ \ {\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"id\":\ \"Moshkovitz1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"name\":\ \"Moshkovitz1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"widgets\":\ [\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"name\":\ \"Main\ Floor1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeX\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeY\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"type\":\ \"button\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"row\":\ 0,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"col\":\ 0,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"action_type\":\ \"navigate\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"navigate_dashboard\":\ \"MainFloor\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"backdrop_iconset\":\ \"freepik-household\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"iconset\":\ \"freepik-household\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ },\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"name\":\ \"Basement1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeX\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeY\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"item\":\ null,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"type\":\ \"button\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"row\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"col\":\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ },\n\ \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\ \"menucolumns\":\ 5,\n\ \ \ \ \ \ \ \ \"settings\":\ {\n\ \ \ \ \ \ \ \ \ \ \ \ \"theme\":\ \"default\"\n\ \ \ \ \ \ \ \ },\n\ \ \ \ \ \ \ \ \"customwidgets\":\ {}\n\ \ \ \ },\n\ \ \ \ \"test1\":\ {\n\ \ \ \ \ \ \ \ \"updatedTime\":\ \"2017-07-16T02:00:37.340Z\",\n\ \ \ \ \ \ \ \ \"dashboards\":\ [\n\ \ \ \ \ \ \ \ \ \ \ \ {\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"id\":\ \"Moshkovitz1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"name\":\ \"Moshkovitz1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"widgets\":\ [\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"name\":\ \"Main\ Floor1\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeX\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"sizeY\":\ 1,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"type\":\ \"button\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"row\":\ 0,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"col\":\ 0,\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"action_type\":\ \"navigate\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"navigate_dashboard\":\ \"MainFloor\",\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \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 \ \ \ \ \ \"menucolumns\":\ 5,\n\ \ \ \ \ \ \ \ \"settings\":\ {\n\ \ \ \ \ \ \ \ \ \ \ \ \"theme\":\ \"default\",\n\ \ \ \ \ \ \ \ \ \ \ \ \"additional_stylesheet_url\":\ \"/static/theme.css\",\n\ \ \ \ \ \ \ \ \ \ \ \ \"panel_name\":\ \"test3\"\n\ \ \ \ \ \ \ \ },\n\ \ \ \ \ \ \ \ \"customwidgets\":\ {}\n\ \ \ \ }\n}"
service.pid="org.openhab.habpanel"

I think that the information “flow” is something like this:

json->HABPanel import->Karaf HashMap? table -> storage in habpanel.config

if you look at the openHAB console:

config:list "(service.pid=org.openhab.habpanel)"

you will see the stored config.
Maybe this config should be handled by the jsonDB storage engine also (so we get a json file) :stuck_out_tongue:

I don’t know how to feed the json into the HABPanel config by using a script… for sure there can be a solution (maybe via the console?) :slight_smile:

In theory, if you place the restored config file in the new system, it should work (I haven’t tested this)

Yes, it does. :ok_hand:

1 Like

Thanks for the explanation.

@gersilex suggested here to access the json data directly. e.g.

http://openhab:8080/static/habpanel/web/?config=http://my-central-storage/dashboards/livingroom.json6

This is more like what I’m thinking, so that the habpanel configuration can be restored automatically from the human readable json file, but I don’t know if this is possible.

I have another habpanel related question. I’m just starting with habpanel and saw this post, do you know where should the dashboard code be placed? I’m trying to figure the file structure (I asked a simialr question here but did not see any answer). If the dashboard related code does not go into file, do you know where I should insert it in the habpanel GUI?

Thanks,
Avner

aha! I got an idea :checkered_flag: … try to use the REST API… this may be able to do the job: http://<OH2_IP>:8080/doc/index.html#!/services
PUT /services/{serviceId}/config

I think in a template widget in HABPanel

See more here:

Ok, I was able to copy paste the code (e.g. Outdoor Dashboard) into the HABPanel GUI and save it into a new widget (named outdoorDashboard). When I export the configuration, I see the reference to “outdoorDashboard” in the exported habpanel-config.json file, but where should the widget information gets stored? (in case I want to backup this information)

the widget config is included in the entire habpanel config
they are not kept separate.

You can export/import the widget code individually from the template config screen:

it will come out as html :slight_smile:

More info on custom widgets also here:

I started fresh. Imported habpanel from file (habpanel-config.json)
I added a widget (via Custom Widgets → Manage → New Widget, and pasted the code in the “Code” pane)
the went back to the dashboard, added the widget and saved.
Then from “Settings → Local panel configuration Editor”, exported into file (habpanel-config2.json)
The exported file (habpanel-config2.json) and the original file (habpanel-config.json) differ only in that the second mentions the new widget, but I can’t find the actual code for the widget in habpanel-config2.json

I am able to export the widget code individually into a json file, as you mentioned (but at this point it is not tied into the exported habpanel-config)

Back to my original question re restoring openhab configuration:
I can paste all the regular config files via script, e.g. the .sitemap, .items, rules files, etc. (basically everything that is in /etc/openhab2) so that after e.g. an upgrade openhab keeps the original configuration.
But how do I do that for habpanel, so that the habpanel setting is picked up, without having to go through the GUI and re-import?

openHAB always keeps the original configuration (if done through the official docs), no need to use any scripts.
Unfortunately HABPanel does not keep server side settings in /userdata, but in the file mentioned above (habpanel.config).
So actually it’s easy after an upgrade: save the config to the server once, copy the habpanel.config from your backup back to to the upgraded system, that’s it.

Actually the config file is in userdata so the update scripts for Linux packages and manual installations should not delete or overwrite them when upgrading.
For backup purposes you can backup the entirety of userdata and HABPanel’s config will be included.

1 Like

Sorry, you are right, it is stored in /userdata/config/org/openhab and I forgot that I always delete my /userdata/config folder during upgrading because of this open issue:

1 Like