HABApp - Easy automation with openHAB

Yes - this was already reported by “besynnerling” and is already fixed in the dev branch.
However I’m currently preparing a huge code change so I can’t release that yet.

Hello, I have previously installed (4 months ago) habapp with python2 (2.7 as I recall). I am now trying to do this on a new machine. I have both Python 3.7 and 2.7 installed. the 3.7 installation of habapp went fine. The 2.7 attempted installation gives an error:

Collecting habapp
  Using cached HABApp-0.31.1.tar.gz (102 kB)
    ERROR: Command errored out with exit status 1:
     command: 'C:\habapp27\Scripts\python2.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'c:\\users\\martin\\appdata\\local\\temp\\pip-install-_g0qe8\\habapp\\setup.py'"'"'; __file__='"'"'c:\\users\\martin\\appdata\\local\\temp\\pip-install-_g0qe8\\habapp\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'c:\users\martin\appdata\local\temp\pip-pip-egg-info-giuvyx'
         cwd: c:\users\martin\appdata\local\temp\pip-install-_g0qe8\habapp\
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\martin\appdata\local\temp\pip-install-_g0qe8\habapp\setup.py", line 8
        def load_version() -> str:
                           ^
    SyntaxError: invalid syntax

Any pointers appreciated!
Regards
Martin

grafik

Python 3 only

Well that answers that then! Clearly a memory glitch on my part…
Thank you.

Another countdown question please :slight_smile:

How could i easily check if the countdown is running or expired.

get_next_rungives me date date in 2038 if the countdown has expired ???

Correct. 2038 >= means currently not scheduled.
A property that returns a simple bool might be more elegant.
Could you please create an issue in the EAScheduler repo with a short description (so I don’t forget it)? I think you had some other ideas concerning the countdown as well …

Is there is an official possibility to get a list of all things? Thing names would be sufficient, class Thing would be OK also.
Otherwise I need to establish a parallel REST connection.

The reason is that I want to assure via the OpenhabThingDefinition and other queries that all items linked to any channel having a “<ga” of any KNX thing belonging to the KNX bridge thing have gotten their status from the KNX bus during startup, that means, that they are not null / None.
Then I can be pretty sure that the OH instance is completely up and running.

Done

https://habapp.readthedocs.io/en/latest/interface_openhab.html#check-status-if-thing-is-constant

Is there is an event to be informed about new or deleted (renamed) things? For a ThingStatusInfoChangedEvent one need an already existing thing

It takes 90 seconds to shut down HABApp via systemctl stop. Finally habapp is killed by systemd:

 habapp.service - HABApp
     Loaded: loaded (/etc/systemd/system/habapp.service; enabled; vendor preset: enabled)
     Active: failed (Result: timeout) since Fri 2022-02-11 16:18:23 CET; 6s ago
       Docs: https://habapp.readthedocs.io
    Process: 227810 ExecStart=/opt/habapp/bin/habapp -c /etc/openhab/habapp (code=killed, signal=KILL)
   Main PID: 227810 (code=killed, signal=KILL)
        CPU: 8.308s

Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228414 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228415 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228423 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228424 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228430 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Killing process 228431 (habapp) with signal SIGKILL.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Main process exited, code=killed, status=9/KILL
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Failed with result 'timeout'.
Feb 11 16:18:23 atoh systemd[1]: Stopped HABApp.
Feb 11 16:18:23 atoh systemd[1]: habapp.service: Consumed 8.308s CPU time.

Is this the intended behavior?

Unforunately not.

Of course not.

Seb,

I was installing HabApp on a fresh Pi4 (minimal Raspian distribution), and I had to manually install the following python modules: pydantic, EasyCo, eascheduler, stackprinter, watchdog, paho-mqtt, aiohttp, aiohttp_sse_client, immutables, bidict. Perhaps, these could be added to habapp’s setup.py file?

Thanks,

They actually are. I don’t know why these are not getting installed but I suspect it’s an issue with the pendulum installation. Did you get an error during installation?

Edit: If you look in “3rd Party” there are at least three threads which report the same problem.
However no one was able to reproduce the issue. Maybe you can shine some light on it?

It’s rather strange. When I install habapp, it doesn’t display any error. By all indications, all was good. However, when I install other modules, I do see their dependencies got pull in.

I try to move my windows watcher rule from timer to watch no change, but i didn’t get it right. i always get the error:

AttributeError: 'OpenhabItemDefinition' object has no attribute 'watch_change'

I used all definition form this thread and the documentation, but always the same

       self.monitored_item = self.oh.get_item(name)

        #watcher = self.monitored_item.watch_change(self.steady_time)
        #self.listen_event(self.monitored_item, self.on_constant_do, watcher.EVENT)

        #self.monitored_item.watch_change(self.steady_time).listen_event(self.on_constant_do)
        
        self.monitored_item.watch_change(self.steady_time)
        self.monitored_item.listen_event(self.on_constant_do, ItemNoChangeEvent)


But if i look into the documentation it said that there is a watch_change mathod for ContactItems as example.

What i am missing with this?

makes a sync request to openhab and returns the item definition from the rest api.
You need to use OpenhabItem.get_item or the corresponding type e.g. ContactItem.get_item

1 Like

With OpenhabItem the error is gone, but no event will be triggered. i Think i miss something fundamental.

# Dependency definitions
# HABApp:
#   reloads on:
#     - params/steady_item_information.yml

import logging
import HABApp

from HABApp import Rule
from HABApp.openhab.items import OpenhabItem
from HABApp.core.events import ItemNoChangeEvent

from datetime import datetime

PARAM_FILE = 'steady_item_information'

class SteadyItemInformation(HABApp.Rule):

    def __init__(self, name, parameter):
        super().__init__()

        # Get parameter data
        self.steady_time = parameter['steady_time']
        self.steady_state = parameter['steady_state']
        self.monitored_item = OpenhabItem.get_item(name)

        # Initialize listeners etc.
        OpenhabItem.get_item(name).watch_change(self.steady_time).listen_event(self.on_constant_do)

        log.info(f'Steady state watcher on "{self.monitored_item.name}" initialized!')
    
    def on_constant_do(self, event: ItemNoChangeEvent):
        log.info(f'Steady state "{event}" triggered!')



log = logging.getLogger('HABApp')
for monitored in HABApp.Parameter(PARAM_FILE, 'monitored').value:
    SteadyItemInformation(monitored, HABApp.Parameter(PARAM_FILE, monitored).value)

The event should come after the next item change. Have you tried manually changing the item?

1 Like

So simple - Now it is working. :grinning: