Trying to get started with HabApp

Hi - I am running 3.1M3 on a RaspberryPi installed via openhabian.

I’ve gone back and forth with Jython and HabAPP with the intent on trying to retire my DSL rules and move some external python scripts into a more managed environment.

I installed HabAPP through openhabian-config, and I can get the ‘that was easy’ rule outputting to the console of my server running interactively:

/opt/habapp/bin/habapp -c /etc/openhab/habapp

But I can’t get either of the first two samples that interact with a real OpenHAB item to either respond to a change or state that the item is constant.

If I look at the logs, I see that it has connected to the bus successfully and it looks like it doesn’t like that I’m using a string item from OH instead of a HABApp item so clearly I don’t understand how it is really supposed to read items from OH. What am I missing.

[2021-04-05 21:24:25,595] [             HABApp.Rules]    ERROR |      cls = <class 'HABApp.core.items.item.Item'>
[2021-04-05 21:24:25,595] [             HABApp.Rules]    ERROR |      name = 'T_TestString'
[2021-04-05 21:24:25,595] [             HABApp.Rules]    ERROR |      initial_value = None
[2021-04-05 21:24:25,595] [             HABApp.Rules]    ERROR |      HABApp.core.Items.ItemNotFoundException = <class 'HABApp.core.Items.ItemNotFoundException'>
[2021-04-05 21:24:25,595] [             HABApp.Rules]    ERROR |      item = <StringItem name: T_TestString, value: 98, last_change: 2021-04-05 21:24:05.940186, last_update: 2021-04-05 21:24:05.940186>
[2021-04-05 21:24:25,596] [             HABApp.Rules]    ERROR |      HABApp.core.Items.add_item = <function 'add_item' Items.py:46>
[2021-04-05 21:24:25,596] [             HABApp.Rules]    ERROR |     ..................................................
[2021-04-05 21:24:25,596] [             HABApp.Rules]    ERROR |
[2021-04-05 21:24:25,596] [             HABApp.Rules]    ERROR | ---- (full traceback above) ----
[2021-04-05 21:24:25,596] [             HABApp.Rules]    ERROR | File "/opt/habapp/lib/python3.7/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
[2021-04-05 21:24:25,597] [             HABApp.Rules]    ERROR |     self.create_rules(created_rules)
[2021-04-05 21:24:25,597] [             HABApp.Rules]    ERROR | File "/opt/habapp/lib/python3.7/site-packages/HABApp/rule_manager/rule_file.py", line 68, in create_rules
[2021-04-05 21:24:25,597] [             HABApp.Rules]    ERROR |     '__HABAPP__RULES': created_rules,
[2021-04-05 21:24:25,597] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 263, in run_path
[2021-04-05 21:24:25,597] [             HABApp.Rules]    ERROR |     pkg_name=pkg_name, script_name=fname)
[2021-04-05 21:24:25,598] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
[2021-04-05 21:24:25,598] [             HABApp.Rules]    ERROR |     mod_name, mod_spec, pkg_name, script_name)
[2021-04-05 21:24:25,598] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
[2021-04-05 21:24:25,598] [             HABApp.Rules]    ERROR |     exec(code, run_globals)
[2021-04-05 21:24:25,599] [             HABApp.Rules]    ERROR | File "/etc/openhab/habapp/rules/test.py", line 31, in test.py
[2021-04-05 21:24:25,599] [             HABApp.Rules]    ERROR |     MyFirstRule()
[2021-04-05 21:24:25,599] [             HABApp.Rules]    ERROR | File "/etc/openhab/habapp/rules/test.py", line 10, in __init__
[2021-04-05 21:24:25,599] [             HABApp.Rules]    ERROR |     self.my_item = Item.get_create_item('T_TestString')
[2021-04-05 21:24:25,599] [             HABApp.Rules]    ERROR | File "/opt/habapp/lib/python3.7/site-packages/HABApp/core/items/item.py", line 24, in get_create_item
[2021-04-05 21:24:25,600] [             HABApp.Rules]    ERROR |     assert isinstance(item, cls), f'{cls} != {type(item)}'
[2021-04-05 21:24:25,600] [             HABApp.Rules]    ERROR |
[2021-04-05 21:24:25,600] [             HABApp.Rules]    ERROR | AssertionError: <class 'HABApp.core.items.item.Item'> != <class 'HABApp.openhab.items.string_item.StringItem'>
[2021-04-05 21:24:25,600] [             HABApp.Rules]  WARNING | Failed to load /etc/openhab/habapp/rules/test.py!

I already modified the docs because this part was not very clear:

HABApp uses an internal item registry to store both openhab items and locally created items (only visible within HABApp). Upon start-up HABApp retrieves a list of openhab items and adds them to the internal registry. Rules and HABApp derived libraries may add additional local items which can be used to share states across rules and/or files.
Posting values from the item will automatically create the events on the event bus. This example will create an item in HABApp (locally) and post some updates to it. To access items from openhab use the correct openhab item type.

So if you want to use a string item you have to use

from HABApp.openhab.items import StringItem

...

StringItem.get_item('my_item')

Thanks @Spaceman_Spiff - I think I was assuming it was easier than it was… had I read ahead in the docs, and not made an assumption, I think I would have figured it out.