Starting with HABApp and struggling with first rule: Found no instances of HABApp.Rule

Having a tough time getting started with HABapp. Have installed ver 1.1.2.

I have installed it following the docs on a Windows PC. My openHAB installation is on a Pi. The logs show that HABapp has connected to the openHAB instance which is great. Just having problems executing the first rule. The following appears in the logs whenever I save the file:

Found no instances of HABApp.Rule in D:\opt\habapp\rules\test.py

In HABApp not recognizing rules (Solved) - Apps & Services / 3rd Party - openHAB Community there is mention of instantiating the rule or installing habapp in the local python environment, but i’m struggling to understand how to achieve either. I just copied the script from the docs, so i expected it to work. I’m sure I missed something with my installation so just hoping for some tips.

The rule is this:

import HABApp

# Rules are classes that inherit from HABApp.Rule
class MyFirstRule(HABApp.Rule):
    def __init__(self):
        super().__init__()

        # Use run.at 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!')

I’m also not sure what it means to “watch the console”. At the moment all I can see is things being written to the HABapp.log file.

Help very much appreciated! Happy to provide any missing info.

Hi,

you just define the rule but not running it. To run the rule you have to start it with

MyFirstRule()

Put this after the rule.

This is also stated in the docs Getting Started — HABApp beta documentation

1 Like

Thank you. Yes you are 100% correct that line is missing. What happened is that I actually misunderstood the instructions and thought that I needed to type MyFirstRule() somewhere in order to run it :man_facepalming:.

Of course I can confirm it is working for me now.