HABApp - Easy automation with openHAB

ah, of course!
Thank you!

Laziness, I think :wink:
config.yml would be the one and only file to edit (well, mostly) for all systems.

But I can live with a parameter file too.

But as an aspiring you already realized the potential of parameter files and plan on using them extensively.
:wink:

1 Like

Oh, yes, next up is automating my wallpugs that I use for engine heaters with HAPApp.
That will involve several OpenHAB items for each wallplug.
Hardcoding the Item names is not the way to go, as wallplugs changes and seasons change.

So I tried what you suggested and I still get a NULL value on the OH side. I do send couple of posts in a row, so could it be a timing issue?

    StringItem.get_item('EmailSubject').oh_post_update(subject)                                               
    StringItem.get_item('EmailBody').oh_post_update(body)                       
    StringItem.get_item('EmailAttachmentUrls').oh_post_update(', '.join(attachment_urls))                     
    StringItem.get_item('EmailAddresses').oh_post_update(', '.join(email_addresses))

Here’s the code on the JSR223 side:

if scope.UnDefType.NULL ==  bodyState or scope.UnDefType.UNDEF == bodyState:
    body = ''                                                           
    PE.logInfo("*** body is bad: {}".format(scope.items['EmailBody'].toString()))
else:                                                                   
    body = bodyState.toString()  

In OH, a post_update doesn’t trigger an event on the event bus but a send_command does. I am a bit surprised that both oh_post_update and oh_send_command work in the same way. My guess is that to OH, this is a value change and as such it triggers an event. But from the HABapp point of view, an oh_post_update won’t trigger an event within HABapp. Am I correct?

Thanks,

Of course it does, you just might not see it in the event.log.
It’ll create an event in OH and this event is then mirrored back to HABApp.
It can be a timing issue since immediate requests can be processed out of order.

Just send the final update that you trigger upon a little bit later

self.run_in(1, StringItem.get_item('EmailBody').oh_post_update, body)

Good news everyone!

I just released HABApp 0.19.0!

2 Likes

I just notice this line in the log when sending an empty string to a StringItem.

[2021-01-09 23:36:07,664] [HABApp.openhab.connection]  WARNING | Status 415 for PUT http://127.0.0.1:8080/rest/items/EmailBod
y/state/

415 is Unsupported Media Type.

This definitely worked in OH2, so I guess there was some kind of change.
–> #2095

Edit:
A fix in HABApp will be available with the next release

1 Like

Good news everyone!

I just released HABApp 0.20.0!

1 Like

How’s everyone doing? It’s been a while since we see traffic in this thread.
I just deprecated all my Jython rules and modules; almost all of them had been migrated to HABApp-based framework (close to 10K of code). And everything has been going great!

Thanks Seb for the library.

2 Likes

I think this is a good sign. Things seem to be mostly stable and while the docs still could use some overhaul they seem to answer most of the questions.
One of the last missing puzzle pieces was the event filter which further reduces the logic in the rules.

For the future I’ll focus on fixing bugs (and probably introducing new ones :wink:) and reworking some old logic (e.g. scheduler is high on my list).

And as always - If someone needs help with a rule just ping me here. :slight_smile:

2 Likes

out of interest, why did you do that? I’ve been getting on very happily with Jython… am I missing something better/easier?

Jython is python 2.x and this is end of life for quite some while (Sunsetting Python 2 | Python.org)
With a native python 3.x solution it is easy to integrate any modern python library.

thanks!

I took a little look at HABApp a while ago, but couldn’t see an obvious way to have events triggered by multiple items or groups, and then identify the item that had triggered the event. Can that now be done?

Yes, that is possible. You get the name of the triggering item as part of the event

thanks - are there any examples of that anywhere? If not, I’d be most grateful if you could post one…

Here you can see that the event passed into the callback contains the triggering item.
You can subscribe with the same callback to multiple items or create a rule that groups things logically.

e.g.

for name in ('MySwitch1', 'MySwitch2', 'MySwitch3'):
    SwitchItem.get_item(name).listen_event(self.my_callback, ValueChangeEvent)
    # or if its different items you can use the base class
    OpenhabItem.get_item(name).listen_event(self.my_callback, ValueChangeEvent)

Also HABApp allows you to trigger when an item is constant since last update/change for a certain ammount of time which makes so much timer stuff obsolete it’s mind blowing :wink:

Dan, it is good that Jython is working fine for you. It was mainly working for me as well, but there were a few annoying issues with the integration of the script engine and OH, and then there is the issue of the Jython implementation of Python itself. I wrote a post comparing the two at HABApp vs JSR223 Jython. Ultimately it is a personal choice :slight_smile: .

1 Like

Seb, is the use of authorization token on your radar (so that we don’t have to turn off authentication in OH 3)?