HABApp Beta for openHAB 4.0

OpenHAB 4.0 introduces some changes which HABApp has to adapt to.
To identify these changes and to discuss the new features I’ve created this topic.
To try out the latest version you can install HABApp from the Develop branch.
The docs for the Develop branch are here.
As of now there are no braking changes so should be possible to switch back and forth between OH3 and OH4 without having to modify the HABApp rules.

Currently openHAB 4.0 is not yet fully supported because of the many behavioral changes.
However if you’re adventurous and want to give feedback this is the place.

@bastler
I have implemented some fixes for OH4 so there should be no more warning for unknown events.

4 Likes

just trying to install. because i got weired permission errors with “wheels” - sorry did not note it, i uninstalled not only habapp but deleted the complete env and created new. then installation went without errors.

now wenn starting habapp i recieve this error continuously for my rules that import GroupItemStateChangedEvent

Exception in load: cannot import name 'GroupItemStateChangedEvent' from 'HABApp.openhab.events' (/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/events/__init__.py)
Could not load /etc/openhab/habapp/rules/_basic.py!
File "/etc/openhab/habapp/rules/_basic.py", line 33 in _basic.py
--------------------------------------------------------------------------------
     30 | from HABApp.core.items import Item
     31 | from HABApp.openhab.items import Thing, DimmerItem, SwitchItem, NumberItem, StringItem, ContactItem, DatetimeItem, OpenhabItem, GroupItem
     32 | from HABApp.core.events import EventFilter, ValueUpdateEvent, ValueUpdateEventFilter, ValueChangeEvent, ValueChangeEventFilter, ItemNoChangeEvent
-->  33 | from HABApp.openhab.events import ItemStateChangedEvent, ItemStateChangedEventFilter, ChannelTriggeredEvent, ItemCommandEvent, ItemCommandEventFilter, GroupItemStateChangedEvent
     34 | from HABApp.util import EventListenerGroup
   ------------------------------------------------------------
     logging.DEBUG = 10
   ------------------------------------------------------------

--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/habapp/lib/python3.9/site-packages/HABApp/rule_manager/rule_file.py", line 78, in load
    self.create_rules(created_rules)
  File "/opt/habapp/lib/python3.9/site-packages/HABApp/rule_manager/rule_file.py", line 68, in create_rules
    runpy.run_path(str(self.path), run_name=str(self.path), init_globals=rule_hook.in_dict())
  File "/usr/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/etc/openhab/habapp/rules/_basic.py", line 33, in _basic.py
    from HABApp.openhab.events import ItemStateChangedEvent, ItemStateChangedEventFilter, ChannelTriggeredEvent, ItemCommandEvent, ItemCommandEventFilter, GroupItemStateChangedEvent
ImportError: cannot import name 'GroupItemStateChangedEvent' from 'HABApp.openhab.events' (/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/events/__init__.py)

and if typing sudo systemctl status habapp
i recieve an attribute error (dont know if relevant):

habapp.service - HABApp
     Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-05-12 11:08:18 CEST; 2min 9s ago
       Docs: https://habapp.readthedocs.io
   Main PID: 6097 (habapp)
      Tasks: 20 (limit: 4531)
        CPU: 1min 45.550s
     CGroup: /system.slice/habapp.service
             └─6097 /opt/habapp/bin/python3 /opt/habapp/bin/habapp -c /etc/openhab/habapp

Mai 12 11:10:26 openhabian habapp[6097]:     callback = wrap_func(callback, context=self._habapp_rule_ctx)
Mai 12 11:10:26 openhabian habapp[6097]:   File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/internals/wrapped_function/wrapper.py", line >
Mai 12 11:10:26 openhabian habapp[6097]:     return SYNC_CLS(func, warn_too_long=warn_too_long, name=name, logger=logger, context=context)
Mai 12 11:10:26 openhabian habapp[6097]:   File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/internals/wrapped_function/wrapped_thread.py">
Mai 12 11:10:26 openhabian habapp[6097]:     super().__init__(name=name, func=func, logger=logger, context=context)
Mai 12 11:10:26 openhabian habapp[6097]:   File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/internals/wrapped_function/base.py", line 25,>
Mai 12 11:10:26 openhabian habapp[6097]:     name = self._habapp_ctx.get_callback_name(func)
Mai 12 11:10:26 openhabian habapp[6097]:   File "/opt/habapp/lib/python3.9/site-packages/HABApp/rule_ctx/rule_ctx.py", line 22, in get_callback_na>
Mai 12 11:10:26 openhabian habapp[6097]:     return f'{self.rule.rule_name}.{callback.__name__}' if self.rule.rule_name else None
Mai 12 11:10:26 openhabian habapp[6097]: AttributeError: 'NoneType' object has no attribute 'rule_name'

Can you try GroupStateChangedEvent ?
I guess it’s not as backwards compatible as I thought :rofl: :wink:

thanks for the help. i still could not try it, because it seems all my rules get coninuously loaded again and again and after some time habapp stops working (i see because all habapp logfiles end at this time).

in tha habapp_events.log i see:

[2023-05-12 15:54:31,044] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Abzug.py>
[2023-05-12 15:54:31,045] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/BtManager.py>
[2023-05-12 15:54:31,046] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/FirstInit.py>
[2023-05-12 15:54:31,046] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/HofGarage.py>
[2023-05-12 15:54:31,047] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/ItemTimer.py>
[2023-05-12 15:54:31,047] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/MultifunctionSwitches.py>
[2023-05-12 15:54:31,047] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/NightLight.py>
[2023-05-12 15:54:31,048] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Shellys.py>
[2023-05-12 15:54:31,048] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Squeezes.py>
[2023-05-12 15:54:31,049] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Steca.py>
[2023-05-12 15:54:31,049] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Stove.py>
[2023-05-12 15:54:31,050] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Technik.py>
[2023-05-12 15:54:31,097] [          HABApp.EventBus]     INFO |        iOwTemp_FbhVL: <ItemStateUpdatedEvent name: iOwTemp_FbhVL, value: 28.5 °C>
[2023-05-12 15:54:31,098] [          HABApp.EventBus]     INFO |        iOwTemp_FbhVL: <ItemStateChangedEvent name: iOwTemp_FbhVL, value: 28.5 °C, old_value: 28.75 °C>
[2023-05-12 15:54:31,260] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemCommandEvent name: iEWoK_Abzug_State, value: 0>
[2023-05-12 15:54:31,261] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemStateUpdatedEvent name: iEWoK_Abzug_State, value: 0>
[2023-05-12 15:54:31,261] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemStateChangedEvent name: iEWoK_Abzug_State, value: 0, old_value: 2>
[2023-05-12 15:54:31,277] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemCommandEvent name: iEWoK_Abzug_State, value: 2>
[2023-05-12 15:54:31,279] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemStateUpdatedEvent name: iEWoK_Abzug_State, value: 2>
[2023-05-12 15:54:31,280] [          HABApp.EventBus]     INFO |    iEWoK_Abzug_State: <ItemStateChangedEvent name: iEWoK_Abzug_State, value: 2, old_value: 0>
[2023-05-12 15:54:31,287] [          HABApp.EventBus]     INFO |     iViEWoK_Abzug_Li: <ItemStateUpdatedEvent name: iViEWoK_Abzug_Li, value: OFF>
[2023-05-12 15:54:31,287] [          HABApp.EventBus]     INFO |             iG_Licht: <GroupStateUpdatedEvent name: iG_Licht, value: OFF>
[2023-05-12 15:54:31,288] [          HABApp.EventBus]     INFO |              iG_EWoK: <GroupStateUpdatedEvent name: iG_EWoK, value: OFF>
[2023-05-12 15:54:31,310] [          HABApp.EventBus]     INFO |         iBticino_OWN: <ItemCommandEvent name: iBticino_OWN, value: *14*1*0314#4#01##>
[2023-05-12 15:54:31,311] [          HABApp.EventBus]     INFO |         iBticino_OWN: <ItemStateUpdatedEvent name: iBticino_OWN, value: *14*1*0314#4#01##>
[2023-05-12 15:54:31,323] [          HABApp.EventBus]     INFO | iViEWoK_Abzug_FilterReset: <ItemStateUpdatedEvent name: iViEWoK_Abzug_FilterReset, value: 0>
[2023-05-12 15:54:31,336] [          HABApp.EventBus]     INFO | iViEWoK_Abzug_MotorStufeSoll: <ItemStateUpdatedEvent name: iViEWoK_Abzug_MotorStufeSoll, value: 0>
[2023-05-12 15:54:31,349] [          HABApp.EventBus]     INFO | iViEWoK_Abzug_MotorStufeIst: <ItemStateUpdatedEvent name: iViEWoK_Abzug_MotorStufeIst, value: 0>
[2023-05-12 15:54:31,358] [          HABApp.EventBus]     INFO |        iVi_btMonitor: <ItemStateUpdatedEvent name: iVi_btMonitor, value: 2>
[2023-05-12 15:54:31,424] [          HABApp.EventBus]     INFO |           iHoftor_Ro: <ItemStateUpdatedEvent name: iHoftor_Ro, value: 0.0%>
[2023-05-12 15:54:31,432] [          HABApp.EventBus]     INFO |           iGarage_Ro: <ItemStateUpdatedEvent name: iGarage_Ro, value: 0.0%>
[2023-05-12 15:54:31,456] [          HABApp.EventBus]     INFO |         iViHoftor_Ro: <ItemStateUpdatedEvent name: iViHoftor_Ro, value: 2>
[2023-05-12 15:54:31,467] [          HABApp.EventBus]     INFO |         iViGarage_Ro: <ItemStateUpdatedEvent name: iViGarage_Ro, value: 2>
[2023-05-12 15:54:31,479] [          HABApp.EventBus]     INFO |   iViHoftor_Gehtuere: <ItemStateUpdatedEvent name: iViHoftor_Gehtuere, value: 0>
[2023-05-12 15:54:31,493] [          HABApp.EventBus]     INFO |         iViHaustuere: <ItemStateUpdatedEvent name: iViHaustuere, value: 0>
[2023-05-12 15:54:31,501] [          HABApp.EventBus]     INFO |      iViSackgasse_Li: <ItemStateUpdatedEvent name: iViSackgasse_Li, value: 0>
[2023-05-12 15:54:31,516] [          HABApp.EventBus]     INFO | iBad_Rasierer_Sd_Left: <ItemStateUpdatedEvent name: iBad_Rasierer_Sd_Left, value: 17>
[2023-05-12 15:54:31,516] [          HABApp.EventBus]     INFO | iBad_Rasierer_Sd_Left: <ItemStateChangedEvent name: iBad_Rasierer_Sd_Left, value: 17, old_value: 16>
[2023-05-12 15:54:31,829] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: params/heating.yml>
[2023-05-12 15:54:31,855] [          HABApp.EventBus]     INFO |         iSolar_State: <ItemStateUpdatedEvent name: iSolar_State, value: 2>
[2023-05-12 15:54:32,059] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Abzug.py>
[2023-05-12 15:54:32,060] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/BtManager.py>
[2023-05-12 15:54:32,060] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/FirstInit.py>
[2023-05-12 15:54:32,061] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/HofGarage.py>
[2023-05-12 15:54:32,061] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/ItemTimer.py>
[2023-05-12 15:54:32,062] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/MultifunctionSwitches.py>
[2023-05-12 15:54:32,062] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/NightLight.py>
[2023-05-12 15:54:32,062] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Shellys.py>
[2023-05-12 15:54:32,063] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Squeezes.py>
[2023-05-12 15:54:32,063] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Steca.py>
[2023-05-12 15:54:32,064] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Stove.py>
[2023-05-12 15:54:32,064] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Technik.py>
[2023-05-12 15:54:32,445] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: params/heating.yml>
[2023-05-12 15:54:32,524] [          HABApp.EventBus]     INFO | iBad_Rasierer_Sd_Left: <ItemStateUpdatedEvent name: iBad_Rasierer_Sd_Left, value: 16>
[2023-05-12 15:54:32,525] [          HABApp.EventBus]     INFO | iBad_Rasierer_Sd_Left: <ItemStateChangedEvent name: iBad_Rasierer_Sd_Left, value: 16, old_value: 17>
[2023-05-12 15:54:32,708] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Abzug.py>
[2023-05-12 15:54:32,709] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/BtManager.py>
[2023-05-12 15:54:32,709] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/FirstInit.py>
[2023-05-12 15:54:32,710] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/HofGarage.py>
[2023-05-12 15:54:32,710] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/ItemTimer.py>
[2023-05-12 15:54:32,711] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/MultifunctionSwitches.py>
[2023-05-12 15:54:32,711] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/NightLight.py>
[2023-05-12 15:54:32,711] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Shellys.py>
[2023-05-12 15:54:32,712] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Squeezes.py>
[2023-05-12 15:54:32,712] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Steca.py>
[2023-05-12 15:54:32,713] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Stove.py>
[2023-05-12 15:54:32,713] [          HABApp.EventBus]     INFO |         HABApp.Files: <RequestFileLoadEvent filename: rules/Technik.py>

i removed all rules and left just one and rebooted, but also this single rule gets loaded again and again:

2023-05-12 16:01:12,035 [DEBUG] [My_HABApp] - ### init HABApp.Rule basic_1.py ###

2023-05-12 16:01:12,092 [DEBUG] [My_HABApp] - ### basic_1.py on_rule_removed ###

2023-05-12 16:01:13,052 [DEBUG] [My_HABApp] - ### init HABApp.Rule basic_1.py ###

2023-05-12 16:01:13,105 [DEBUG] [My_HABApp] - ### basic_1.py on_rule_removed ###

2023-05-12 16:01:14,073 [DEBUG] [My_HABApp] - ### init HABApp.Rule basic_1.py ###

2023-05-12 16:01:14,135 [DEBUG] [My_HABApp] - ### basic_1.py on_rule_removed ###

2023-05-12 16:01:15,091 [DEBUG] [My_HABApp] - ### init HABApp.Rule basic_1.py ###

2023-05-12 16:01:15,149 [DEBUG] [My_HABApp] - ### basic_1.py on_rule_removed ###
1 Like

@dan12345 The new version will tolerate a certain amount of long running functions so you don’t have to create tasks any more.

1 Like

brilliant - thank you! Look forward to it!

I am looking at the UoM item handling and I am not sure what the most elegant way to handle this would be.

Would you prefer a new NumberUomItem which provides “unit” and “dimension” or have this integrated into NumberItem and have it return None for these?

I’ve incorporated all the necessary changes in the DEV branch and everything seems to work fine.
@bastler has already done some tests and it’s working as expected for him.

Maybe somebody else can take a look before I make a full release?
Some more feedback would be appreciated.

I get the following at startup:

2023-06-14 20:20:00.107 [INFO ] [HABApp                    ] - HABApp Version 1.1.0.DEV-8
2023-06-14 20:20:00.352 [INFO ] [HABApp.mqtt.connection    ] - MQTT disabled
2023-06-14 20:20:00.614 [WARN ] [HABApp.openhab.connection ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2023-06-14 20:20:00.615 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:20:01.637 [WARN ] [HABApp.openhab.connection ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2023-06-14 20:20:01.638 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:20:03.657 [WARN ] [HABApp.openhab.connection ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2023-06-14 20:20:03.658 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:20:07.677 [WARN ] [HABApp.openhab.connection ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2023-06-14 20:20:07.677 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:20:15.703 [WARN ] [HABApp.openhab.connection ] - "Cannot connect to host localhost:8080 ssl:default [Connect call failed ('127.0.0.1', 8080)]" (<class 'aiohttp.client_exceptions.ClientConnectorError'>)
2023-06-14 20:20:15.705 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:20:32.564 [INFO ] [HABApp.openhab.connection ] - ... offline!
2023-06-14 20:21:04.598 [ERROR] [HABApp.openhab.connection ] - Traceback (most recent call last):
2023-06-14 20:21:04.598 [ERROR] [HABApp.openhab.connection ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/http_connection.py", line 431, in try_connect
2023-06-14 20:21:04.599 [ERROR] [HABApp.openhab.connection ] -     root = await async_get_root()
2023-06-14 20:21:04.599 [ERROR] [HABApp.openhab.connection ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/http_connection.py", line 350, in async_get_root
2023-06-14 20:21:04.600 [ERROR] [HABApp.openhab.connection ] -     return await resp.json(loads=load_json, encoding='utf-8')
2023-06-14 20:21:04.600 [ERROR] [HABApp.openhab.connection ] -   File "/opt/habapp/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1104, in json
2023-06-14 20:21:04.601 [ERROR] [HABApp.openhab.connection ] -     raise ContentTypeError(
2023-06-14 20:21:04.601 [ERROR] [HABApp.openhab.connection ] - aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('http://localhost:8080/rest/')
2023-06-14 20:21:49.410 [INFO ] [HABApp.openhab.connection ] - Connected to OpenHAB version 4.0.0.M3 (Milestone Build)

Thanks - this should not have been an error and will be fixed.
Does everything else work as expected?

I have Just done a quick Installation Test, unfortunately I have These days Not the time for funktional Tests.

HABApp 1.1.0 is out!