How to update the configuration using the REST API?

I’m trying to programatically (using Puppet/Ansible) update the configuration. In this specific case I’m trying to set the default/initial HABPanel (initialPanelConfig) and the panel configuration (panelsRegistry) using the API. Unfortunately the openHAB REST API only has GET methods for /config-descriptions, no documented settings methods.

Anyone knows how to modify/update the configuration using the REST API?

I can’t help with your specific problem but am curious how you are using Ansible and Puppet together.

I’m not using them together :wink:
That was just to point out that I’m trying to automate the openHAB installation.
In my case it’s Ansible, but Puppet will work equally, as will other automation tools.

In that case I would use backup and restore instead. I use Ansible so will use Ansible nomenclature.

So first I would get everything set up in openHAB. Then run the backup script in OH’s. Take the resultant tar file and copy it to the files directory if the Ansible playbook. This will encapsulate everything you’ve configured in OH.

Then your task will involve installing OH, copy the backup file to the host to the same location you copied it from in the first place. Then run the restore script.

As part of your backup process, make sure you have steps to run the backup script and replace the tar file in the install role. I’d include these in your upgrade role as well.

Was thinking about this way, but it’s really painful and implied that nothing changed in the setup. Also I need to remember to take regular backups and hope that nothing changes inbetween … No UI, GUI, config changes, no setup changes, nothing.

For these reasons I prefer to find a way how to change the config he Ansible way: idempotent.

Config descriptions are not what you are looking for: you can however update service configurations with the PUT /rest/services/{serviceId}/config endpoint, and a JSON object in the body - in fact that’s what the HABPanel UI itself uses to persist its config.


PUT /rest/services/org.openhab.habpanel/config

  "initialPanelConfig": "abc",
  "panelsRegistry": "<JSON encoded as a string>"

If you need the JSON body and have a current config just use
GET /rest/services/org.openhab.habpanel/config
to retrieve it.

Hope this helps!

More painful than trying to code the setup, which itself is code, programmaticaly in Ansible or Puppet scripts?

I’ve been there. Writing code to write code is about as painful as it gets.

You need to take regular backups anyway.

And the backup script captures all the changes to your OH config. If there are changes in between then those changes are saved in the backup.

You will be hard pressed to convince me that taking regular backups (which you need to do anyway, and which can be automated with Ansible or Puppet as well) and just dropping that backup tar file in the files folder of your Ansible role is going to be more complex than adding tasks to configure each and every little setting and configuration file of your entire OH.

OH is complicated enough already. Why make it so much more complicated by only interacting with it though Ansible or Puppet?

And this approach can very easily be made idempotent. You just need to check the name of the backup file in the files folder and check the names of the backup files on the host. If there is a match you don’t do the task. If there is a newer backup on the host you error out. You can do it lots of other ways as well.

But it’s your time. If you want to do it the hard way that’s your business.

Sure, I have to take backups anyway, and I’m going to automate this as well.

For a home automation system, openHAB is awful non-automatic, but relies a lot on manual input all the time.

If you see things that can be automated we would welcome the PR.