Recently I started looking into Home Automation, using a Raspberry Pi and the openHAB as platform. The website provides ready-to-go images based on Debian, named openHABian. Me being me, I decided to install the image, let it boot up for the first time, and then take it from there using Ansible as automation tool. That’s a bit more effort in the beginning, but ensures that I can always just wipe the SDcard, and start over from the beginning. Especially useful if I screw up at some point during testing.
One of the first steps to do is to decide which bindings, or extensions, are needed. Bindings provide openHAB with information about what kind of hardware and input sources are available out there. The list of available bindings is long, and one can use the UI to click and install bindings, before starting to configure and link them. That process is not idempotent, but luckily openHAB also provides an API which can be used to execute the same steps, just faster and automated.
The following Playbook uses the API to receive a list of available extensions/bindings, and then installs a number of extensions if they are not yet installed. Additionally a new filter
byattr filter is required, based on this solution here. In my case I did not use
filter_plugins/core.py but instead placed the plugin in
debug statement dumps the entire extension list including all the other data. The second
debug just dumps a list of available extensions, making it somewhat easier to read. Both debug options are commented out, but left there for convenience.
This Playbook installs a few additional packages, mainly jinja2 templates which are not preinstalled on the openHABian image, and a small tool named
jq which I’m not directly using with Ansible, but in combination with curl to debug the API JSON output:
curl line above fetches all available things from openHAB, pretty prints the output and lists everything in
Now that all extensions are installed, it’s time to rescan and rediscover new inbox items. Again that’s possible using the API:
Fetch a list of all available discoveries, and then force openHAB to rediscover all of them - just in case. That’s all wrapped in a block, and only run if the list of extensions changed. Otherwise it’s not necessary to rediscover items.