HABApp 1.0

my fault…I named it wrongly…now everything is fine…

Has anyone a BME280 script running with HABapp nd can share it?

from HABApp import Rule
from HABApp.openhab.events import ThingStatusInfoChangedEvent
from HABApp.openhab.items import Thing
from HABApp.core.events import EventFilter
import logging

import smbus
import time
import requests
from ctypes import c_short
from ctypes import c_byte
from ctypes import c_ubyte

log = logging.getLogger('HABApp')
bus = smbus.SMBus(1)

class CheckAllThings(Rule):
    def __init__(self):


        #for thing in self.get_items(Thing):
        #    thing.listen_event(self.thing_status_changed, EventFilter(ThingStatusInfoChangedEvent))
        #    log.info(f'{thing.name}: {thing.status}')

    def say_something(self):

    #def thing_status_changed(self, event: ThingStatusInfoChangedEvent):
    #    log.info(f'{event.name} changed from {event.old_status} to {event.status}')

Error is:

Error "No module named 'smbus'" in load:
2022-08-24 22:12:46.267 [ERROR] [HABApp.Rules                        ] - Could not load /etc/openhab/habapp/rules/test1.py!
2022-08-24 22:12:46.268 [ERROR] [HABApp.Rules                        ] - File "/etc/openhab/habapp/rules/test1.py", line 7 in test1.py
2022-08-24 22:12:46.268 [ERROR] [HABApp.Rules                        ] - --------------------------------------------------------------------------------
2022-08-24 22:12:46.269 [ERROR] [HABApp.Rules                        ] -      3 | from HABApp.openhab.items import Thing
2022-08-24 22:12:46.269 [ERROR] [HABApp.Rules                        ] -      4 | from HABApp.core.events import EventFilter
2022-08-24 22:12:46.270 [ERROR] [HABApp.Rules                        ] -      5 | import logging
2022-08-24 22:12:46.270 [ERROR] [HABApp.Rules                        ] - -->  7 | import smbus
2022-08-24 22:12:46.270 [ERROR] [HABApp.Rules                        ] -      8 | import time
2022-08-24 22:12:46.271 [ERROR] [HABApp.Rules                        ] -
2022-08-24 22:12:46.271 [ERROR] [HABApp.Rules                        ] - --------------------------------------------------------------------------------


python3-smbus is already the newest version (4.2-1+b1).

You have to restart HABApp if you install new dependencies. Also if you run HABApp in a venv you need to install the dependencies there.

HABApp 1.0.4

Usage (HSB works accordingly).

   from HABApp.core.types import RGB

   col = RGB(5, 15, 255)

   print(col.red)   # red value
   print(col.r)     # short name for red value
   print(col[0])    # access of red value through numeric index

   new_col = col.replace(red=22)

The main benefit is that the types can be posted directly to openHAB and will automatically get converted to the appropriate openHAB representation.

color_item.oh_send_command(RGB(5, 15, 255))

will work as expected.

Hi Sebastian!

I just upgraded to HABApp 1.0.4.

The following code:

from HABApp.openhab.events import (GroupItemStateChangedEvent, ItemStateChangedEventFilter)

        # Get the group items to trigger on
        for subgroup in self.openhab.get_item('gArea_Trigger').members:
            group_item = GroupItem.get_item(subgroup.name)
            # Trigger on item changes
            group_item.listen_event(self.group_item_state_change, GroupItemStateChangedEvent)

now throws an error:

ValueError: Argument event_filter must be an instance of event filter (is <class 'HABApp.openhab.events.item_events.GroupItemStateChangedEvent'>)

Nothing in the changelog about this.

I’d expect I should import GroupItemStateChangedEventFilter instead of GroupItemStateChangedEvent but there’s no such function declared.

Any ideas how I can make this code work again?

It’s in the change log for 1.0.0.
You have to use the EventFilter and pass the event class there (see the example below).

1 Like

Thank you for your kind help Sebastian.

I guess I should change

group_item.listen_event(self.group_item_state_change, GroupItemStateChangedEvent)

group_item.listen_event(self.group_item_state_change, EventFilter(GroupItemStateChangedEvent))

I will restore my backup of my upgraded system and give it a try. :grinning:

Edit: It seems to work!

1 Like

Cannot upgrade habapp from 0.31.2 to 1.0.4
i was using openhab 3.3.0 M4 and i decided to upgrade to 3.3.0 release.
I’ve read that habapp needs to be updated but apparently i cannot either by using openhabian-config or following the instructions of the habapp readthedocs site.

 python3 -m pip install --upgrade habapp
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: habapp in ./lib/python3.7/site-packages (0.31.2)

I have also tried to uninstall with openhabian but with no success.

Is my installation too old and I need a fresh install?

It is the same on my side. Even uninstall and install again still get not the version 1

The new 1.0 version requires at least python 3.8 but you are still on 3.7. You can

  • install a new version manually and then update HABApp
  • update your whole openhabian image
    (I think you have to use a fresh image but I am not sure)
1 Like

So you mean, a new python version?
Ok will try this

Yes, from 1.0 on >= python 3.8 is required, that’s why it won’t update your installation because the last supported HABApp version for python 3.7 is 0.31.2.

Ok, thanks. Then I will try to update to python 3.8.x on the weekend, if I have time.
thanks and have a nice weekend.