HABApp - Easy automation with openHAB

Hi Seb, I do not think HABapp supports event like this in Xtend ah?

Item PARTITION1_ARM_MODE received command 1

Is it a limitation of the OH REST API?

Of course it’s possible with HABApp.
It’s even possible to listen to any part of the event and combine them as desired (see second part of events description).

For the most common events I have created convenience filters that provide type hints.
E.g.

  • ValueUpdateEventFilter and ValueChangeEventFilter
  • MqttValueUpdateEventFilter and MqttValueChangeEventFilter
  • ItemStateEventFilter and ItemStateChangedEventFilter

@Spaceman_Spiff Thanks, i am learning from every post :slight_smile:

What do you think about the idea to create example how to move DSL condition like received Command to HABApp? I think that will make it mich easier to move over.

I think it’s a great idea!
Maybe we can start a thread and you guys post rule samples and we transfer them to HABApp. Once we have a couple of examples I can add it to the docs.
Unfortunately I can’t do it myself since I haven’t been writing DSL rules since OH1.7 :smiley:
What do you think? Would you (guys) be willing to contribute?

Hopefully i will manage to start a thread this evening.

2 Likes

It is done! See the following Post [wiki] HABAPP - A journey to start - Rules triggers - Apps & Services / 3rd Party - openHAB Community is the first post to collect HABApp informations

Hello,

I have an issue with importing a python module and am a bit confused.

I installed the module requests with pip and it shows up correctly. I can use it with a regular python .py.

But in the HABapp.log I get this:

$
[2021-03-08 21:09:13,417] [             HABApp.Rules]    ERROR | Error "No module named 'requests'" in load:
[2021-03-08 21:09:13,418] [             HABApp.Rules]    ERROR | Could not load /etc/openhab/habapp/rules/myfirstrule.py!
[2021-03-08 21:09:13,418] [             HABApp.Rules]    ERROR | File "/opt/habapp/lib/python3.7/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
[2021-03-08 21:09:13,419] [             HABApp.Rules]    ERROR |     self.create_rules(created_rules)
[2021-03-08 21:09:13,421] [             HABApp.Rules]    ERROR | File "/opt/habapp/lib/python3.7/site-packages/HABApp/rule_manager/rule_file.py", line 68, in crea$
[2021-03-08 21:09:13,421] [             HABApp.Rules]    ERROR |     '__HABAPP__RULES': created_rules,
[2021-03-08 21:09:13,422] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 263, in run_path
[2021-03-08 21:09:13,422] [             HABApp.Rules]    ERROR |     pkg_name=pkg_name, script_name=fname)
[2021-03-08 21:09:13,424] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
[2021-03-08 21:09:13,425] [             HABApp.Rules]    ERROR |     mod_name, mod_spec, pkg_name, script_name)
[2021-03-08 21:09:13,426] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
[2021-03-08 21:09:13,427] [             HABApp.Rules]    ERROR |     exec(code, run_globals)
[2021-03-08 21:09:13,427] [             HABApp.Rules]    ERROR | File "/etc/openhab/habapp/rules/myfirstrule.py", line 4, in myfirstrule.py
[2021-03-08 21:09:13,428] [             HABApp.Rules]    ERROR |     1    import datetime
[2021-03-08 21:09:13,428] [             HABApp.Rules]    ERROR |     2    import time
[2021-03-08 21:09:13,429] [             HABApp.Rules]    ERROR |     3
[2021-03-08 21:09:13,429] [             HABApp.Rules]    ERROR | --> 4    import requests
[2021-03-08 21:09:13,430] [             HABApp.Rules]    ERROR |     5    import json
[2021-03-08 21:09:13,431] [             HABApp.Rules]    ERROR |     ..................................................
[2021-03-08 21:09:13,431] [             HABApp.Rules]    ERROR |      datetime = <module 'datetime' from '/usr/lib/python3.7/datetime.py'>
[2021-03-08 21:09:13,431] [             HABApp.Rules]    ERROR |      time = <module 'time' (built-in)>
[2021-03-08 21:09:13,432] [             HABApp.Rules]    ERROR |     ..................................................
[2021-03-08 21:09:13,432] [             HABApp.Rules]    ERROR |
[2021-03-08 21:09:13,432] [             HABApp.Rules]    ERROR | ModuleNotFoundError: No module named 'requests'

What am I doing wrong?

Thanks for any help!

If you install additional packages you have to restart HABApp to pick up the changes in the virtual environment.

I’ve done a full reboot now, but still get the same error.

How can I check that it is available to the python in the virtual environment?

openhabian@openhab:~ $ pip show requests
Name: requests
Version: 2.25.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /usr/local/lib/python3.7/dist-packages
Requires: urllib3, idna, certifi, chardet
Required-by:

I’m on openhabian and installed HABapp through the openhabian menu.

You are installing the requests package in the system wide python and not in the virtual environment of HABApp.

You have to activate the virtual environment first to install into it.
Follow the steps in installation, except step 2, 6 and 7 (since everything is already available).
Then do
python3 -m pip install requests
and restart HABApp

OK, understand. However now I’m getting an error

(habapp) openhabian@openhab:/opt/habapp $ python3 -m pip install  requests
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting requests
  Using cached https://www.piwheels.org/simple/requests/requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting idna<3,>=2.5
  Using cached https://www.piwheels.org/simple/idna/idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached https://www.piwheels.org/simple/urllib3/urllib3-1.26.3-py2.py3-none-any.whl (137 kB)
Collecting certifi>=2017.4.17
  Using cached https://www.piwheels.org/simple/certifi/certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Requirement already satisfied: chardet<5,>=3.0.2 in ./lib/python3.7/site-packages (from requests) (3.0.4)
Installing collected packages: urllib3, idna, certifi, requests
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/opt/habapp/lib/python3.7/site-packages/urllib3'
Consider using the `--user` option or check the permissions.

Hmm, this seems to be a permission error.
Try “sudo python3 -m pip install requests”

Then it goes back out of the virtual env?

(habapp) openhabian@openhab:/opt/habapp $ sudo python3 -m pip install requests
[sudo] password for openhabian:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (2.25.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests) (2018.8.24)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3/dist-packages (from requests) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3/dist-packages (from requests) (2.6)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3/dist-packages (from requests) (1.24.1)

What happens if you restart HABApp now?

Somewhat related, and mybe flawed;
Because my head is teflon coated and polished, I made a script to handle the venv stuff.
I do not know venv good enuogh to say it is a good idea, but I hope I can get some feedback if not :wink:

nils@xps13:~/habapp$ cat upgrade.sh 
#!/bin/bash
source bin/activate
pip install -r lokallibs.txt
python3 -m pip install --upgrade habapp
deactivate

nils@xps13:~/habapp$

It installs/upgrades the libs listed in
lokallibs.txt before it upgrades HABApp.
I run the script as the user HABApp is running as.

This might be the key! Could you show the call as an example?

Still the same unfortunately.

On my laptop, where I work on the rules, HABApp is running as me:

cd habapp
./upgrade.sh

For my OpenHAB server:

  • I ssh into On my OpenHAB machine as “habapp” (The user HABApp is running as)

  • Stop the systemd service “habapp”

  • cd into the directory where HABApp is installed.

  • Run the update script

  • If everything is OK, start the systemd service “habapp”

Where can I find the password? I don’t think I’ve ever seen or chosen it.

I think you are running HABApp as the user “openhab” since you installed through openhabian.
Could you try installing requests while being in the folder /opt/habapp/bin ?
It seems to not pick up the venv :confused: