Getting started with habapp failing

I am trying to get habapp working and not having any luck.
system: Raspberry Pi, running buster, openhab 3.1 and python 3.7.3

I am troubleshooting my problem as though it is an authentication issue but I am out of ideas. I have a username and password in my /etc/openhab/habapp/comfig.yml file. Habapp is running.

root@zippy:/home/chris# service habapp status
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-09-29 13:28:11 PDT; 2s ago
     Docs: https://habapp.readthedocs.io
 Main PID: 6896 (habapp)
    Tasks: 1 (limit: 2059)
   CGroup: /system.slice/habapp.service
           └─6896 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /etc/openhab/habapp

Sep 29 13:28:11 zippy systemd[1]: Started HABApp.

My /var/log/openhab/HABapp.log is

root@zippy:/home/chris# cat /var/log/openhab/HABApp.log
[2021-09-29 13:28:15,308] [                   HABApp]     INFO | HABApp Version 0.30.3
[2021-09-29 13:28:15,315] [   HABApp.mqtt.connection]     INFO | MQTT disabled
[2021-09-29 13:28:15,317] [     HABApp.openhab.thing]     INFO | Config folder does not exist - textual thing config disabled!
[2021-09-29 13:28:15,318] [    HABApp.RuleParameters]     INFO | Parameter files disabled: Folder /etc/openhab/habapp/params does not exist!
[2021-09-29 13:28:20,513] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/
[2021-09-29 13:28:20,515] [HABApp.openhab.connection]     INFO | ... offline!
[2021-09-29 13:28:26,568] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/
[2021-09-29 13:28:26,569] [HABApp.openhab.connection]     INFO | ... offline!
[2021-09-29 13:28:33,611] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/
[2021-09-29 13:28:33,612] [HABApp.openhab.connection]     INFO | ... offline!
[2021-09-29 13:28:42,638] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/
[2021-09-29 13:28:42,639] [HABApp.openhab.connection]     INFO | ... offline!
[2021-09-29 13:28:55,667] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/
[2021-09-29 13:28:55,669] [HABApp.openhab.connection]     INFO | ... offline!
[2021-09-29 13:29:16,698] [HABApp.openhab.connection]  WARNING | Status 403 for GET http://localhost:8080/rest/uuid/

Allow Basic Authentication is turned on, though I have tried switch off.
I tried purging my openhab installation and starting over, but no matter what I do, I can’t get this resolved. The documentation for this app is so good, I am sure I am just missing something. Please help.
Thanks,
Chris

The UUID should work even without authentication so this looks really strange.
When you replace localhost with the IP of the device does it work in your browser?

Can you check if “implicit user role” is enabled (should be) under api-security in the openhab settings?

Thanks for your response. I tried replacing the local host with the IP, but same results. That lead me to look more into API Security on my openhab installations. There are parameters missing under the advanced settings. I will look into that more.

Thanks
Chris

Hm - strange. Does the API-Explorer in your installation work?

Yes, the explorer works, like I think it should. However if i browse on my laptop to http://zippy:8080/rest/uuid/ (my openhab server) I get

error	
message	"Authentication required"
http-code	401

This is with “basic authentication” turned off and" Implicit user role for unauthenticated requests" off. The cache setting is missing.

Can you enable the “implicit user role”? Are you on 3.1 release or on a earlier milestone?

I enabled “implicit user role” got the same authentication required. Openhab is at 3.1 stable release.

It seeks like basic authentication mode is not changing.

Are you sure?

If the cache setting is missing it seems you are running an earlier version.
Have you checked “advanced settings” so you see all options?

That’s how 3.1.0 - Release Build should look like.

No, I thought it was 3.1. I checked help and about and it is openHAB 3.0.2. Darn, I am sorry. I will upgrade and check again and get back to you.

Things are looking better with the update to openhab 3.1. I had mistakenly thought my test instance of openhab was at the same level as my production instance.

Now I have “Basic Authentication” and “Implicit User Role” enabled. My logs are looking better, but there still seems to be a problem with connecting to the “rest/things”, but it is a warning and maybe not an issue.

root@zippy:/home/chris# cat /var/log/openhab/HABApp.log 
[2021-09-30 13:47:13,226] [                   HABApp]     INFO | HABApp Version 0.30.3
[2021-09-30 13:47:13,233] [   HABApp.mqtt.connection]     INFO | Connecting to 192.168.92.208:8883
[2021-09-30 13:47:13,237] [     HABApp.openhab.thing]     INFO | Config folder does not exist - textual thing config disabled!
[2021-09-30 13:47:13,238] [    HABApp.RuleParameters]     INFO | Parameter files disabled: Folder /etc/openhab/habapp/params does not exist!
[2021-09-30 13:47:13,707] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 13:47:13,708] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 13:47:13,853] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 13:47:13,875] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 401 for /rest/things/
[2021-09-30 13:47:15,213] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 13:47:15,214] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 13:47:15,326] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 13:47:15,348] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 401 for /rest/things/
[2021-09-30 13:47:17,694] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 13:47:17,695] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 13:47:17,807] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 13:47:17,835] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 401 for /rest/things/
[2021-09-30 13:47:18,922] [              HABApp.Rule]  WARNING | /opt/habapp/lib/python3.7/site-packages/HABApp/rule/rule.py:245: DeprecationWarning:self.run_soon is deprecated. Please use self.run.soon
[2021-09-30 13:47:18,931] [             HABApp.Rules]     INFO | Added rule "MyFirstRule" from rules/easy2.py
[2021-09-30 13:47:19,021] [             HABApp.Rules]     INFO | Added rule "MyRule" from rules/sched.py
[2021-09-30 13:47:22,240] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 13:47:22,241] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 13:47:22,355] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 13:47:22,380] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 401 for /rest/things/
[2021-09-30 13:47:30,710] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 13:47:30,711] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 13:47:30,845] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 13:47:30,868] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 401 for /rest/things/

It does look like habapp is working, but I am pretty much a novice at Python3. Test rules that I copied from examples are running.

Thanks,
Chris

It is! It’s still 401 unauthorized. Maybe you have a typo in your openhab user/password?

I am pretty sure it isn’t a typo. To verify, I edited my config.yml file with a new username and password. I had tried it before with the username and password values at ‘’. That gave 401 errors. Then I added the new credentials with the karaf console. For good measure, I changed the cache expiration time to 0. Errors went from 401 errors to 403.

[2021-09-30 20:48:14,798] [            HABApp.Worker]    ERROR | 
[2021-09-30 20:48:14,798] [            HABApp.Worker]    ERROR | UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 37: invalid start byte
[2021-09-30 20:48:14,812] [HABApp.openhab.connection]  WARNING | Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
[2021-09-30 20:48:15,117] [             HABApp.Rules]  WARNING | Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/._easy2.py
[2021-09-30 20:48:15,132] [              HABApp.Rule]  WARNING | /opt/habapp/lib/python3.7/site-packages/HABApp/rule/rule.py:245: DeprecationWarning:self.run_soon is deprecated. Please use self.run.soon
[2021-09-30 20:48:15,138] [             HABApp.Rules]     INFO | Added rule "MyFirstRule" from rules/easy2.py
[2021-09-30 20:48:15,176] [             HABApp.Rules]     INFO | Added rule "MyHolidayRule" from rules/holiday.py
[2021-09-30 20:48:15,237] [             HABApp.Rules]     INFO | Added rule "MyRule" from rules/sched.py
[2021-09-30 20:48:16,397] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 403 for /rest/things/
[2021-09-30 20:49:22,911] [HABApp.openhab.connection]     INFO | Connected to OpenHAB instance f91f5793-29c0-4821-aa32-88e452bd22f1
[2021-09-30 20:49:22,913] [HABApp.openhab.connection]     INFO | OpenHAB version 3.1.0 (Release Build)
[2021-09-30 20:49:28,121] [     HABApp.openhab.items]     INFO | Updated 10 Items
[2021-09-30 20:49:31,187] [HABApp.openhab.connection]  WARNING | Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
[2021-09-30 20:49:33,215] [HABApp.openhab.connection]  WARNING | Disconnected! Expected success but got status 403 for /rest/things/

I noticed a new status 404 warning that I had not noticed before.

I am running on very low sleep for the past few days, and could have messed something up. Probably about time to give it up for the evening.

Thanks
Chris

Don’t do that - 6h is good!

It’s the openhab ping you configured in your config.yml.


You can always check if the auth settings are correct by manually executing the get command in the browser:
http://user:password@YOUR_OPENHAB_IP:8080/rest/things

I suggest you make that work first before trying anything else.
It’s still an auth issue - even if it’s not clear atm why.

Thanks for the response. The syntax for the url address is a great help. I will troubleshoot going down that path.

I changed the user to and an administrator, and now habapp seems to be working.

Thanks,
Chris

1 Like

Hi I’m getting from one mistake to another.

(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $ sudo systemctl status habapp.service
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-12-12 19:19:34 CET; 2s ago
     Docs: https://habapp.readthedocs.io
 Main PID: 2635 (habapp)
    Tasks: 7 (limit: 4454)
   CGroup: /system.slice/habapp.service
           └─2635 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp

Dec 12 19:19:36 openhabian habapp[2635]:     self._context.run(self._callback, *self._args)
Dec 12 19:19:36 openhabian habapp[2635]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_handler/http_connection.py", line 375, in try_uuid
Dec 12 19:19:36 openhabian habapp[2635]:     ON_CONNECTED()
Dec 12 19:19:36 openhabian habapp[2635]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_logic/_plugin.py", line 58, in on_connect
Dec 12 19:19:36 openhabian habapp[2635]:     p.on_connect()
Dec 12 19:19:36 openhabian habapp[2635]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_logic/_plugin.py", line 40, in on_connect
Dec 12 19:19:36 openhabian habapp[2635]:     self.fut = asyncio.create_task(self.on_connect_function())
Dec 12 19:19:36 openhabian habapp[2635]:   File "/usr/lib/python3.7/asyncio/tasks.py", line 325, in create_task
Dec 12 19:19:36 openhabian habapp[2635]:     return loop.create_task(coro)
Dec 12 19:19:36 openhabian habapp[2635]: concurrent.futures._base.CancelledError
(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $

If i change in the config file the username and password Im getting this error:

(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $ sudo systemctl status habapp.service
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-12-12 19:24:44 CET; 1s ago
     Docs: https://habapp.readthedocs.io
 Main PID: 2764 (habapp)
    Tasks: 7 (limit: 4454)
   CGroup: /system.slice/habapp.service
           └─2764 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp

Dec 12 19:24:44 openhabian systemd[1]: Started HABApp.
Dec 12 19:24:45 openhabian habapp[2764]: Error loading logging config: Unable to configure handler 'EventFile'
Dec 12 19:24:45 openhabian habapp[2764]: Executing <Task pending coro=<Runtime.start() running at /opt/habapp/lib/python3.7/site-packages/HABApp/runtime/runtime.py:61> created at /opt/habapp/lib/python3.7/site-pa
lines 1-12/12 (END)

I had also the Errors 401 and 403 time ago.
Don’t know what I did wrong.
Seems helpless for me, but hopefully waiting for help…

Have you modified the logging file? Can you remove the logging.yml so it will get recreated?

I tried several times to renew the config and logging files.

(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $ sudo systemctl status habapp.service
[sudo] password for openhabian:
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-12-12 21:42:09 CET; 21h ago
     Docs: https://habapp.readthedocs.io
 Main PID: 780 (habapp)
    Tasks: 11 (limit: 4454)
   CGroup: /system.slice/habapp.service
           └─780 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp

Dec 13 19:27:10 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:16 openhabian habapp[780]: Error loading logging config: Unable to configure handler 'EventFile'
Dec 13 19:27:16 openhabian habapp[780]: Executing <Handle <TaskWakeupMethWrapper object at 0xb3780d50>(<Future fini
Dec 13 19:27:20 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:30 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:40 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:50 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:00 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:10 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:20 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
lines 1-19/19 (END)...skipping...
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-12-12 21:42:09 CET; 21h ago
     Docs: https://habapp.readthedocs.io
 Main PID: 780 (habapp)
    Tasks: 11 (limit: 4454)
   CGroup: /system.slice/habapp.service
           └─780 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp

Dec 13 19:27:10 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:16 openhabian habapp[780]: Error loading logging config: Unable to configure handler 'EventFile'
Dec 13 19:27:16 openhabian habapp[780]: Executing <Handle <TaskWakeupMethWrapper object at 0xb3780d50>(<Future finis...events.py:396>) cr
Dec 13 19:27:20 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:30 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:40 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:27:50 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:00 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:10 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
Dec 13 19:28:20 openhabian habapp[780]: Status 404 for PUT http://localhost:8080/rest/items/HABApp_Ping/state/ NULL
~

Thats the latest try

(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $ sudo systemctl restart habapp.service
(habapp) openhabian@openhabian:/opt/openhab/conf/habapp $ sudo systemctl status habapp.service
● habapp.service - HABApp
   Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-12-13 19:32:46 CET; 1s ago
     Docs: https://habapp.readthedocs.io
 Main PID: 2930 (habapp)
    Tasks: 7 (limit: 4454)
   CGroup: /system.slice/habapp.service
           └─2930 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /opt/openhab/conf/habapp

Dec 13 19:32:47 openhabian habapp[2930]:     self._context.run(self._callback, *self._args)
Dec 13 19:32:47 openhabian habapp[2930]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_handler/http_connectio
Dec 13 19:32:47 openhabian habapp[2930]:     ON_CONNECTED()
Dec 13 19:32:47 openhabian habapp[2930]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_logic/_plugin.py", lin
Dec 13 19:32:47 openhabian habapp[2930]:     p.on_connect()
Dec 13 19:32:47 openhabian habapp[2930]:   File "/opt/habapp/lib/python3.7/site-packages/HABApp/openhab/connection_logic/_plugin.py", lin
Dec 13 19:32:47 openhabian habapp[2930]:     self.fut = asyncio.create_task(self.on_connect_function())
Dec 13 19:32:47 openhabian habapp[2930]:   File "/usr/lib/python3.7/asyncio/tasks.py", line 325, in create_task
Dec 13 19:32:47 openhabian habapp[2930]:     return loop.create_task(coro)
Dec 13 19:32:47 openhabian habapp[2930]: concurrent.futures._base.CancelledError

Could you post the contents of the HABApp.log please?

021-12-14 06:33:14.160 [INFO ] [HABApp                              ] - HABApp Version 0.31.1
2021-12-14 06:33:14.165 [INFO ] [HABApp.openhab.thing                ] - Config folder does not exist - textual thing config disabled!
2021-12-14 06:33:14.166 [INFO ] [HABApp.RuleParameters               ] - Parameter files disabled: Folder /opt/openhab/conf/habapp/params does not exist!
2021-12-14 06:33:14.169 [INFO ] [HABApp.mqtt.connection              ] - MQTT disabled
2021-12-14 06:33:14.270 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB instance 096fc1b7-d9e5-4bc7-b28c-0d49815db3d4
2021-12-14 06:33:14.270 [INFO ] [HABApp.openhab.connection           ] - OpenHAB version 3.1.0 (Release Build)
2021-12-14 06:33:14.299 [INFO ] [HABApp.openhab.items                ] - Updated 0 Items
2021-12-14 06:33:14.306 [WARN ] [HABApp.openhab.connection           ] - Disconnected! Expected success but got status 401 for /rest/things/
2021-12-14 06:33:15.411 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB instance 096fc1b7-d9e5-4bc7-b28c-0d49815db3d4
2021-12-14 06:33:15.411 [INFO ] [HABApp.openhab.connection           ] - OpenHAB version 3.1.0 (Release Build)
2021-12-14 06:33:15.435 [INFO ] [HABApp.openhab.items                ] - Updated 0 Items
2021-12-14 06:33:15.445 [WARN ] [HABApp.openhab.connection           ] - Disconnected! Expected success but got status 401 for /rest/things/
2021-12-14 06:33:17.543 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB instance 096fc1b7-d9e5-4bc7-b28c-0d49815db3d4
2021-12-14 06:33:17.543 [INFO ] [HABApp.openhab.connection           ] - OpenHAB version 3.1.0 (Release Build)
2021-12-14 06:33:17.567 [INFO ] [HABApp.openhab.items                ] - Updated 0 Items
2021-12-14 06:33:17.575 [WARN ] [HABApp.openhab.connection           ] - Disconnected! Expected success but got status 401 for /rest/things/
2021-12-14 06:33:21.600 [WARN ] [HABApp.Rule                         ] - /usr/lib/python3.7/logging/handlers.py:1326: ResourceWarning:unclosed file <_io.TextIOWrapper name='/var/log/openhab/HABApp_events.$