HABApp not recognizing rules (Solved)

I made the decision to start building a new setup based on OH3 and I figured since I’m doing that I would re-evaluate what rules languages I am using. I had been using Jython in the past but wanted to explore HABApp since it supports newer Python versions.

I set up OpenHAB using openhabian on a ubuntu 20.04 virtual machine. All installs appeared to go without any issue. I used openhabian to install HABApp as well. HABApp starts and runs without any issues.

However when I start writing rules it doesn’t seem to recognize them and VSCode does not recognize the HABApp namespace. I’m fairly inexperienced with Python as a whole so I’m hoping someone can help me figure out why the libraries aren’t being recognized.

Full details:

  • OH3 installed via latest Openhabian installer on Ubuntu 20.04
  • HABApp installed via Openhabian as well
  • Development machine is a Windows 11 laptop with VSCode the the python development extension installed

Code:

from HABApp import Rule
from HABApp.core.events import ValueChangeEvent, ValueUpdateEvent, ValueChangeEventFilter, ValueUpdateEventFilter
from HABApp.core.items import Item
import logging

log = logging.getLogger('MyRule')

class MyFirstRule(Rule):
    def __init__(self):
        super().__init__()
        self.listen_event('TestSwitch', self.on_change, ValueChangeEventFilter())

    def on_change(self, event: ValueChangeEvent):
        log.debug("Test Switch Changed: ")

Log output (HABApp.log):

2022-11-23 23:04:26.592 [INFO ] [HABApp                              ] - HABApp Version 1.0.6
2022-11-23 23:04:26.601 [INFO ] [HABApp.Config                       ] - Textual thing config disabled! Folder /etc/openhab/habapp/params does not exist!
2022-11-23 23:04:26.601 [INFO ] [HABApp.Config                       ] - Manual thing configuration disabled! Folder /etc/openhab/habapp/config does not exist!
2022-11-23 23:04:26.603 [INFO ] [HABApp.mqtt.connection              ] - MQTT disabled
2022-11-23 23:04:26.632 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB version 3.4.0.M4 (Milestone Build)
2022-11-23 23:04:26.644 [INFO ] [HABApp.openhab.items                ] - Updated 41 Items
2022-11-23 23:04:26.646 [INFO ] [HABApp.openhab.items                ] - Updated 0 Things
2022-11-23 23:04:32.113 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/MyFirstRule.py

Log Output (MyRule.log):

2022-11-23 22:40:30.480 [INFO ] [HABApp                              ] - HABApp Version 1.0.5
2022-11-23 22:40:30.488 [INFO ] [HABApp.Config                       ] - Textual thing config disabled! Folder /etc/openhab/habapp/params does not exist!
2022-11-23 22:40:30.488 [INFO ] [HABApp.Config                       ] - Manual thing configuration disabled! Folder /etc/openhab/habapp/config does not exist!      
2022-11-23 22:40:30.491 [INFO ] [HABApp.mqtt.connection              ] - MQTT disabled
2022-11-23 22:40:30.519 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB version 3.4.0.M4 (Milestone Build)
2022-11-23 22:40:30.531 [INFO ] [HABApp.openhab.items                ] - Updated 41 Items
2022-11-23 22:40:30.533 [INFO ] [HABApp.openhab.items                ] - Updated 0 Things
2022-11-23 22:40:36.003 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/MyFirstRule.py
2022-11-23 22:44:14.605 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/MyFirstRule.py
2022-11-23 22:56:39.329 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/MyFirstRule.py
2022-11-23 22:58:09.786 [WARN ] [HABApp.Rules                        ] - Found no instances of HABApp.Rule in /etc/openhab/habapp/rules/MyFirstRule.py

I just found my own solution. I failed to instantiate the rule. You would think that having programmed a number of other OOP languages I would remember this but I missed it.

Thanks to anyone who read this.

You have to install HABApp in your local python environment where you write the rules. Then everything properly gets picked up.

1 Like