Has anybody tried HABApp with openHAB 3?
I haven’t tried it (yet) but most if not all of it should work because there haven’t been fundamental changes to the rest api.
I am currently unsure when it’ll be a good time to shift development efforts to oh3.
I believe the REST API has expanded but I think things are still quite fluid. I am sure there will be some sort of release this year but I personally am not confident on its usability for many users.
My first try says it is currently not compatible with OH3.
HABApp tries to access http://localhost:8080/rest/uuid/
This is what is returned, by default.
{"error":{"message":"User is not authenticated","http-code":401}}
Some parts of the API seem to be protected by user/password.
In the openhab config there is a possibility to specify user and password.
Have you entered the correct “admin” credentials there?
Edit:
Where do you download oh3? I can’t seem to find a link so I can test myself.
I think this is the guide most are using:
I used apt to install. The official download is here for other methods.
I have not tried that but it appears the API is using some sort of OAuth2 token based authentication.
"/auth/token":{"post":{
"tags":["auth"],
"summary":"Get access and refresh tokens.",
"operationId":"getToken",
"parameters":[{"name":"useCookie","in":"query","schema":{"type":"boolean"}}],
"requestBody":{"content":{
"application/x-www-form-urlencoded":{"schema":{
"type":"object",
"properties":{
"grant_type":{"type":"string"},
"code":{"type":"string"},
"redirect_uri":{"type":"string"},
"client_id":{"type":"string"},
"refresh_token":{"type":"string"},
"code_verifier":{"type":"string"}
}}}
}},
"responses":{"200":{"description":"OK"}}
}},
I just started testing with a clean OH 2.5.9 install on my test Pi with HABApp 0.15.2
& Python 3.7.3
. The first simple rule in the docs gives an error.
(habapp) root@raspberrypi:/opt/habapp/config/rules# python first.py
Traceback (most recent call last):
File "first.py", line 16, in <module>
MyFirstRule()
File "first.py", line 6, in __init__
super().__init__()
File "/opt/habapp/lib/python3.7/site-packages/HABApp/rule/rule.py", line 43, in __init__
__vars = sys._getframe(depth).f_globals
ValueError: call stack is not deep enough
(habapp) root@raspberrypi:/opt/habapp/config/rules#
If you have made the installation you have to start HABApp, not execute the rule directly.
HABApp will automatically load the rule.
You can observe this in the logs accordingly.
HABApp was running. Does it need to be restarted to pick up new rules?
Is this primarily for rules or to replace other text files such as Items and sitemaps?
If HABApp is started it will automatically load and execute the rules located in the rules
folder (which is configured in the config.yml
and typically a different folder than the rules folder from openhab) You just drop or edit the files in the folder - that’s it.
In the HABApp.log
you can observe how things are loaded/unloaded.
There is no possibility to create sitemaps, but you can replace many *.items
files and definitely all rule files with it.
It is mainly intended as a python rule engine, item and thing interaction is just a bonus.
Example with default configuration:
I started HABApp with /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp
.
Now my rules are in /opt/openhab/conf/habapp/rules
(and subfolders).
I just edit or copy them into the folder and they get picked up automatically as soon as they are changed.
In /opt/openhab/conf/habapp/log
I can find all relevant log files and observe what is happening.
Thanks.
It appears when starting with systemd it is starting but the logs are not updating. The config path is correct.
Troubleshooting now. Likely a local issue.
Make sure the /opt/habapp/bin/habapp
is existing before the start because it will not get created.
But if it doesn’t exist HABApp will throw an error message and not start.
Look into the created config.yml
and logging.yml
to make sure the folder entries are correct.
It initially ran from the CLI with --config
instead of -c and logged properly
.
The switches -c
and --config
are interchangeable so this doesn’t matter.
Maybe the user you are running it with does not have write access to the folders?
I am running from CLI as root. It is again logging but no entry for my rule
Rule:
import HABApp
# Rules are classes that inherit from HABApp.Rule
class MyFirstRule(HABApp.Rule):
def __init__(self):
super().__init__()
# Use run_soon to schedule things directly after instantiation,
# don't do blocking things in __init__
self.run_soon(self.say_something)
def say_something(self):
print('That was easy!')
# Rules
MyFirstRule()
log:
[2020-10-04 08:50:52,627] [ HABApp] INFO | HABApp Version 0.15.2
[2020-10-04 08:50:52,627] [ HABApp.mqtt.connection] INFO | MQTT disabled
[2020-10-04 08:50:52,628] [ HABApp.RuleParameters] INFO | Parameter files disabled: Folder /opt/habapp/config/param does not exist!
[2020-10-04 08:50:53,326] [HABApp.openhab.connection] INFO | Connected to OpenHAB instance 0254c3b7-dc4b-43e7-8840-4a184596aa46
[2020-10-04 08:50:53,423] [ HABApp.openhab.items] INFO | Updated 0 Items
[2020-10-04 08:50:53,534] [ HABApp.openhab.items] INFO | Updated 2 Things
[2020-10-04 08:51:53,517] [ HABApp.openhab.things] INFO | +----------------------------------------------------------------+
[2020-10-04 08:51:53,517] [ HABApp.openhab.things] INFO | | Things |
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | +--------+------------+----------+------------+------------------+
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | | Status | Label | Location | Thing type | Thing UID |
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | +--------+------------+----------+------------+------------------+
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | | ONLINE | Local Moon | | astro:moon | astro:moon:local |
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | | ONLINE | Local Sun | | astro:sun | astro:sun:local |
[2020-10-04 08:51:53,518] [ HABApp.openhab.things] INFO | +--------+------------+----------+------------+------------------+
logging.yml
is the default and config.yml
is only lightly customized.
EDI:
BTW, the documentation has no information on what definition is expected for the default HABApp_Ping
Item.
Set the wait_for_openhab
in the config.yml
to false or create an *.items
file with an arbitrary item.
general:
listen_only: False # If True HABApp will not change any value on the openhab instance.
# Useful for testing rules from another machine.
wait_for_openhab: False # If True HABApp will wait for items from the openHAB instance
# before loading any rules on startup
It’s NumberItem, I’ll add it right away.
Log now shows the rule added & text printed on the console, not in the log.
I recommend people only start habapp
from the CLI for the first rules so there is a console to display the output. Either that or have it output to a log file.
Perhaps have it added by default if it does not exist?
Also, the default waits for Items to load but shutdown hangs of there are no Items to load.
@Spaceman_Spiff
There appears to be a shutdown error. I currently only have 2 Things with no items or rules on OH.
(habapp) root@raspberrypi:/opt/habapp/config/log# fg
habapp --config /opt/habapp/config (wd: /opt/habapp)
Shutting down ...
Exception ignored in: <function ClientSession.__del__ at 0x75175e88>
Traceback (most recent call last):
File "/opt/habapp/lib/python3.7/site-packages/aiohttp/client.py", line 309, in __del__
TypeError: 'NoneType' object is not callable
Exception ignored in: <function BaseConnector.__del__ at 0x7513f858>
Traceback (most recent call last):
File "/opt/habapp/lib/python3.7/site-packages/aiohttp/connector.py", line 276, in __del__
TypeError: 'NoneType' object is not callable