HABApp - Easy automation with openHAB

Good news everyone - I released a new version today.

The main feature is the possibility to specify metadata when using textual thing configuration.
Now it is possible to do anything with the textual configuration which is possible through the UI and/or items file.

- type: Number
  name: '{thing_label, :(.+)$}_Temperature'
  label: '{thing_label, :(.+)$} Temperature [%d %%]'
  icon: battery
  metadata:
    autoupdate: 'false'
    homekit: 'TemperatureSensor'

0.15.3

  • Added possibility to set metadata when using textual thing configuration
  • Fixed a race condition which resulted in item.watch... not working properly
  • added multiline support for the log_functions
  • Shutdown should not hang any more if no items exist on the oh side
  • Fixes for z-wave config entries with bitmasks and without bitmask (#168)
  • Added things to the documentation
1 Like

And then something miraculous happened why not

Sorry - I don’t understand :confused:

Futurama. Are you not quoting Professor Farnsworth every time you post a new version?

1 Like

Yes of yourse! I just thought you were referencing the metadata creation so it made little sense to me :slight_smile:

Well yes, the addition of metadata is quite handy. My comment was off the cuff and sans context though.

Thank you for your development of this! It appears it will be quite handy.

I have HABApp up and running in a Docker container, along with the rest of my install. I have a specific use case where I need a rule to SSH into another box and run a command. Since my openHAB2 install is in a container, the exec binding can no longer handle this for me.

I was hoping to use ssh2-python to be able to do this, but I am not sure how to add Python modules into HABApp for use. I’ve reviewed the documentation and either I am missing this, or perhaps this isn’t something that’s meant to be done easily.

Any suggestions would be appreciated!

You will have to create your own dockerfile and “extend” the one provided by me:

FROM spacemanspiff2007/habapp

RUN python -m pip install ssh2-python

After a rebuilding you image you should be able to use the additional libraries.
Please give me a heads up if this works so I can add it to the docs.

@Spaceman_Spiff what about adding a mount point for external libs and putting it in PYTHONPATH permanently?

I don’t have the command handy, but pip cam be told where to install to and to get all requirements and put them in that same folder.

Alternatively there might be a way to add a list of packages to install as an environment variable in the docker compose file that would get installed either before launching HABApp or by HABApp.

I can test these methods when I have time, hopefully next weekend at the latest.

For user specific libraries there already is the option to specify a lib folder in the config. Everything that is copied there can be loaded in a rule.

This could be a solution, similar to the “sleep” arg that can be passed to delay startup.
But it would have to be a good solution so we don’t upgrade to incompatible versions of used libraries.

Nonetheless I firmly believe that everything that is required to run should be in the container and extending the dockerfile seems like the most elegant solution to me and ensures that all file versions are properly build and match the environment.

Maybe if I provide a docker compose and a sample dockerfile in the docs it shouldn’t be too hard.

1 Like

In the doc, perhaps link to the file you use. Much easier to manage for any changes.

I had tried the prior before posting - and admittedly
I’m still a Docker novice, but I ran into build errors with missing cmake and skbuild that I couldn’t figure out how to get past. Does this work for you?

Are you running your container on arm? It seems builds for arm are not included.
Maybe you can use paramiko (pure python so it doesn’t depent on c libs) as an alternative?

Otherwise try these lines

RUN apk add cmake cmake-doc extra-cmake-modules extra-cmake-modules-doc
RUN python -m pip install ssh2-python

No, I am on Intel x64 (RancherOS on ESXi to be exact). Paramiko follows a similar path of build dependency errors. I’m sure the issue is my Docker knowledge, but Google hasn’t helped me troubleshoot why I can’t get either package into this Docker image. I even tried taking your Dockerfile for building and adding the libraries there via pip before the HABApp install, and it fails to build.

Maybe the libssh has to be installed seperately:

RUN apk add libssh2 cmake cmake-doc extra-cmake-modules extra-cmake-modules-doc

But without a proper error message I am out of luck guessing :wink:.

As a last straw you can swap out the alpine base image with an ubuntu or python image based on debian, since many more libraries are included there

FROM python:3.8.6-buster

Hah, fair enough!

Using either a Dockerfile that simply extends the habapp image or adding these into the appropriate locations in the Dockerfile for the image build that you’ve published, I get the same error:

  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i8knhx1r/ssh2-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i8knhx1r/ssh2-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7zivw8wc
       cwd: /tmp/pip-install-i8knhx1r/ssh2-python/
  Complete output (13 lines):
  CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  See also "/tmp/pip-install-i8knhx1r/ssh2-python/src/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-i8knhx1r/ssh2-python/setup.py", line 34, in <module>
      build_ssh2()
    File "/tmp/pip-install-i8knhx1r/ssh2-python/_setup_libssh2.py", line 24, in build_ssh2
      shell=True, env=os.environ)
    File "/usr/local/lib/python3.7/subprocess.py", line 363, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command 'cmake ../libssh2 -DBUILD_SHARED_LIBS=ON     -DENABLE_ZLIB_COMPRESSION=ON -DENABLE_CRYPT_NONE=ON     -DENABLE_MAC_NONE=ON -DCRYPTO_BACKEND=OpenSSL' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for ssh2-python

Based on my research the issue is that something like g++ isn’t installed, but I see that it actually is installed as one of the original dependencies in the image build.

When installing paramiko, I get a build error that boils down to:
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory

This does seem to work. Here’s my complete Dockerfile in case anyone else needs it:

FROM python:3.8.6-buster

VOLUME [ "/config"]

# Install required dependencies
RUN apt install -y \
# Support for Timezones
    tzdata \
# ujson won't compile without these libs
    g++ 

# Always use latest versions
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .

RUN python -m pip install ssh2-python

# Install
RUN pip3 install git+https://github.com/spacemanspiff2007/HABApp.git

CMD [ "python", "-m", "HABApp", "--config", "/config" ]

Thank you for your help in figuring this out!

1 Like

just a hint, you can use

RUN pip3 install HABApp

It should be mostly the same, but yours will also install from the git branch even if it is not yet available on pypi.

Good news everyone!

I drafted a new release - it’s mostly a bugfix one.

0.15.4

  • Reworked items file creation, made the file nicer and fixed a crash
  • Changing an item through the rest api new gets properly reflected in HABApp
  • Added some tests and modified the build pipeline

First of all thanks for this wounderfull piece of software. I’m using OpenHAB since almost 5 years and this was always the missing piece.
I have a question how you deal with items created from HABApp or other scripting. I like the idea of automatically create items based on things or any other custom auto discovery. However I have no good idea so far how to do cleanup. The generated items will remain in the openhab item registry for every (or until manual deletion)
Any thoughts? Is anyone creating items from HABApp?

Dominik

1 Like

Thank you for your kind words - they really mean a lot to me!

If you use the textual thing configuration from HABApp there is already a cleanup built in.
Imho it should be flexible enough to cater to all your use cases, if not then maybe we can build something that does. Have you tried it out already?

I tried creating items from rules in the beginning, but I really like the possibility to look in the items file and quickly see what kind of items are existing and also structure them in a certain way.
If they are just in the database I always have to fire up the UI and search for the item (and not find it because I renamed it with my last change). Also I think it’s nice to have a differentiation between items and item logic.

I am providing the api endpoint because I think of HABApp as the python reference implementation for openhab, but dealing with items is really messy and has lots of quirks.
So while it will work, I am definately not recommending it (at least not without trying everything out on a test instance first).