[wiki] HABAPP - A journey to start - Rules triggers

Hi everybody,

with HABApp there is another option to create rules and automations for openHAB availabe. HABApp is based on Python 3 and is connected to openHAB trough the REST API. So if someone is familar with Python (3) it is a good idea to try it.

I started writng DSL rules with openHAB 1.x and based on this i think it is a good idea to setup up a collection of threads/topics to map well known DSL things to HABApp things and maybe learn some more options.

So this first post should focus on rule triggers. The DSL documentation reference is: Rule-Triggers | openHAB ans the HABApp documentation reference is: Rule — HABApp beta documentation

Each post should show the DSL trigger and the solution with HABApp and we should not forget to add all the new options that HABApp offers.

I am sure that @Spaceman_Spiff will later transfer the posts to the HABApp dokumentation.

2 Likes

The hardest part is done. The thread is startet. :smile:

I general we could diifer between the following types:

  • Event based triggers (item based triggers)
  • Member of triggers
  • Time based triggers
  • System-based Triggers
  • Thing-based Triggers
  • Channel-based Triggers

One of my favorites is the option to trigger a rule based on the change or update of a member on a group.

DSL Trigger

Member of <group> changed

HABApp Solution

class myClass(HABApp.Rule):
    def __init__(self):
        super().__init__()

        for member in self.openhab.get_item('myGroup').members:
            item =  StringItem.get_item(member.name)
            item.listen_event(self.myRule, ValueChangeEvent)

    def myRule(self, event: ValueChangeEvent):
                log.info(f'Item {event.name} changed from "{event.old_value}" to "{event.value}"')


myClass()

Idea in HABApp is to create a listener for each member of the group.

2 Likes

The Member of trigger is exactly what I was looking for. I would warmly suggest to @Spaceman_Spiff to include this example in the docs, because it is really useful.

1 Like

7 posts were split to a new topic: Need help with HABApp Rule