HABApp - Easy automation with openHAB

Hm - it looks like a bug because I’m sure this has been working already. :unamused:
I’m currently in a rather big rewrite of the scheduler so this will be fixed with the next big release.
If you like you can already look at the “Develop” branch and test it from another machine(!) but be aware that there are/might/will still bugs in it.

Just a heads up for everyone:

The next version of HABApp will drop support for python 3.6.
Every major distribution is at least at 3.7 so this should be no problem but be sure to double check.
There will also be code changes necessary to properly use the scheduler but I’ll wrap the new usage in the old functions and issue a deprecation warning.

1 Like

As I was struggeling with getting persistence running after my upgrade to OH3 I quickly implemented an OH3 compatible influxdb persistence as an habapp rule.
Just if someone is interested…

class InfluxDBPersistence(HABApp.Rule):
    def __init__(self):
        super().__init__()
        self.logger = logging.getLogger("RuleLoggers").getChild (self.rule_name)
        self.logger.debug ("Initializing Persistence")
        config = HABApp.Parameter("influxdb").value
        self.client = InfluxDBClient(url=config['url'], token=config['token'], org=config['org'])
        self.bucket = config['bucket']
        self.write_api = self.client.write_api(write_options=WriteOptions(batch_size=10))
        num_items = 0
        for item in HABApp.core.Items.get_all_items():
            if isinstance(item, OpenhabItem):
                num_items = num_items +1
                item.listen_event(self.item_updated,ValueUpdateEvent)
        self.logger.info (f"Init completed. Registered {num_items} items")


    def item_updated(self,event):
        if event.value is not None:
            item_name = event.name
            item = HABApp.core.Items.get_item(item_name)
            if isinstance(item,SwitchItem):
                item_value = 1 if item.is_on() else 0
            elif isinstance(item,ContactItem):
                item_value = 1 if event.is_closed() else 0
            elif isinstance(item,NumberItem) or isinstance(item,DimmerItem) or isinstance(item,RollershutterItem):
                item_value = float(event.value)
            elif isinstance(item,DatetimeItem):
                item_value = int(event.value.timestamp() * 1000)
            else:
                item_value = str(event.value)
            record = {
                "measurement": item_name,
                "fields": {
                    "value": item_value
                },
                "tags": {
                    "item": item_name
                }
            }
            self.write_api.write(bucket=self.bucket, record=record)

                
InfluxDBPersistence()
2 Likes

Seb, I just upgraded to OpenHab3, and had to do this change to get HABapp to work w. OH.

Run “ssh -p 8101 openhab@localhost”. Use password “habopen”.
Once inside the section, run "bundle:stop org.openhab.core.io.rest.auth:

I notice that your patch for OH is now merged. Does it mean that we don’t have to run the above command for OH 3.1 and above? However, we would still have to enable the Basic digest authentication for REST API in the Settngs UI.

What do you think about adding section for configuring OH? E.g.:

  • 2.5.x: no need to configure anything
  • 3.0.1 → 3.1.0: disable rest authentication as above.
  • 3.1.0+: enable Basic digest authentication for REST API in the Settngs UI and configure username and password in HABApp’s config.yml file.

Thanks,

Hai

In the 3.1.0 M3 the changes are already included.
If there is a Cache Expiration Time Parameter the requests will be speed up.
There is no need for any more commands, just activate basic auth.

grafik

good idea

Good news everyone! Release 0.30.0 is out!

1 Like

Hi Sebastian - quick and possibly dumb question. How do I create an event listener that is triggered only by a command sent to an item, and not mere updates? ValueUpdateEvent and ValueChangeEvent seems to be triggered by updates and commands.

thanks!

Dan

Use HABApp.openhab.events.ItemCommandEvent as an event filter.

ValueUpdateEvent gets triggered by an ItemStateEvent, since the latter is a subclass of the former.

In the Example 1 the last listener uses it.

thank you again!

hello @Spaceman_Spiff i’ve noticed an error while creating item tags: it doesn’t properly set values in example:

create items:

  • type: Group
    name: ‘{thing_label, “\s+”, “"}’
    label: '{thing_label, “\s+”, "
    ”}’
    groups: [‘gThermostats’]
    tags: [‘HVAC’]
    metadata:
    model: ‘ZTEMP2’

creates
Group termostatoMatrimoniale “termostatoMatrimoniale” (gThermostats) [HVAC] {model=“ZTEMP2”}

instead of

Group termostatoMatrimoniale “termostatoMatrimoniale” (gThermostats) [“HVAC”] {model=“ZTEMP2”}

so the semantic model doesn’t working properly. did you already know it? is there a way to fix this?
thanks in advace

No, just heard of it

Is this only a problem with the generated *.items file or an actual problem with the generated item?

HABApp 0.30.1 is out!

@domoticaundici
The new version fixes your issue, it was just with the generated file, the item was created correctly.

1 Like

hello @Spaceman_Spiff ! many many thanks! it works great now

Troubles installing HABapp.
I’m trying to give HABApp a try but I am unable to install it. I am using OH3 on a raspberry pi 3 v1.2 with an openhabian image. I upgraded through openhabian-config to version 3.1 milestone 4. The openhabian script updated itself today. I also performed an update of raspberry-pi os, always through the openhabian interface

Installing HABApp always give an error. I set the debug log to maximum and it turns out that there is an error when performing pip install habapp. I therefore tried to issue directly the command

 sudo  python3 -m pip install  habapp

But it always end up with an error about a directory not found. Maybe it is a silly mistake but I can’t figure out how to proceed. I would like to avoid starting completely fresh with a new openhabian install, if possible.
The output of the pip command is the following

 sudo  python3 -m pip install  habapp
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting habapp
  Using cached https://files.pythonhosted.org/packages/b3/71/6947575f5004c5abd6badf07f4b05edbb7c10cce1ce626552a132dd42017/HABApp-0.30.1-py3-none-any.whl
Collecting pendulum==2.1.2 (from habapp)
  Using cached https://files.pythonhosted.org/packages/db/15/6e89ae7cde7907118769ed3d2481566d05b5fd362724025198bb95faf599/pendulum-2.1.2.tar.gz
  Installing build dependencies ... done
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.7/tokenize.py", line 447, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-dbvsk_wj/pendulum/setup.py'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-dbvsk_wj/pendulum/
o

Can you give some hint?
Thank you

The version of pip is too old - you have to upgrade it first:

python -m pip install --upgrade pip
1 Like

Thanks for your answer. I actually had to use a slightly different syntax

python3 -m pip install --upgrade pip

But then the openhabian menu to install hab app still give the same error.
Strange enough if I issue the install command directly,

 python3 -m pip install --upgrade habapp

it installs everything.
I am wondering wether there is some issue with openhbian installing packages as superuser.

At the end of the installation as normal user, I get some warnings,

  WARNING: The script watchmedo is installed in '/home/openhabian/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script habapp is installed in '/home/openhabian/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Are these warnings significant?

1 Like

I was under the impression that you are working with the instruction and are working in the venv.
If you follow the instructions there will be no warning and everything works fine!
Please don’t try anythign else!

I followed instructions and the warnings are gone. Thanks

create_channel_link geves an error. trying to execute

itemName=“adesso”
if not HABApp.openhab.interface.item_exists(itemName):
HABApp.openhab.interface.create_item(“DateTime”, itemName, label=‘Data e ora’, category=‘time’, tags=[], groups=[], group_type=’’, group_function=’’, group_function_params=[])if HABApp.openhab.interface.item_exists(itemName) and not HABApp.openhab.interface.channel_link_exists(“ntp:ntp:local:dateTime”, itemName):
HABApp.openhab.interface.create_channel_link(“ntp:ntp:local:dateTime”, itemName)

unable to create items with starting capital

HABApp.openhab.interface.create_item(‘Number’, ‘HABApp_Ping’, label=‘HABApp_Ping’, category=’’, tags=[], groups=[], group_type=’’, group_function=’’, group_function_params=[])

replacing HABApp_Ping with habAppPing (also in config.yml) works perfectly