HABApp 1.0

Wow, a lot of work since I was last here! Thank you Seb, you’re awesome!

I have not updated yet, but I will – it’s time, now that I’m back writing scripts.
I have a question – a structural issue I’ve encountered ever since JSR223 days on OH2.4 when I first started.

On an ItemCommandEvent, if you get_value() the item that caused the event, you often get the old value, not the new value that caused the event.
If you look in the event object, the new value is there.
This is a huge headache when writing scripts where multiple items control the behavior of one thing.

For example (simple pseudocode example, obviously a real use case may have many more items controlling one thing)


def __init__:

  self.itemPower=SwitchItem.get_item("switch")
  self.itemPower.listen_event(self.update,ItemCommandEvent)

  self.itemBrightness=DimmerItem.get_item("dimmer")
  self.itemBrightness.listen_event(self.update,ItemCommandEvent)


def update(self, event):
  power=self.itemPower.get_value()
  bright=self.itemBrightness.get_value()

  if power == 0:
    bright = 0

  send_mqtt(light_topic,f"dimmer={bright}")

You may find that the light turns off when it’s supposed to turn on etc.

You can of course add the following to update():

if name=="switch":
  power=event.value;

if name=="dimmer":
  bright=event.value

…and that is what I’ve done so far in my scripts, but this is messy and adds a lot of extra work and code, for something I feel could be handled upstream, to simplify script development!

I understand that the openHAB event bus is asynchronous and multithreaded and that this is the root cause of the issue, but …
can’t HABApp work around this issue by caching the new value from the event callback so that when I call get_value(), I get the current value instead of an out of date value?

That would really simplify things.

Is this by any chance you’ve already taken care of? Any suggestions?

This is a misconception on your side. The ItemCommandEvent does not corelate with the item state.
If you send the command “ON” to a dimmer the state of the dimmer will become “100” once it is fully turned on, meaning the external device has reported the State back to the item.

The the flow is:
State is 0
Item receives command with ItemCommandEvent,
Item sends command to device
Device turns on
Device reports state back to item
ItemStateUpdate
ItemStateEvent (and ItemStateChangeEvent)

So if you want to use the item state you have to use the ItemStateEvent or ValueUpdateEvent.

Oh wow. THAT actually makes perfect sense… and that would explain why I didn’t have the same issue with MqttItems, where I’ve always used ValueUpdateEvent because there is no Command event.

Okay then, that ought to simplify things!! Thank you so much for the clear explanation.

Good news everyone!

HABApp 1.0.6

is out!

This version fixes a couple of thing and improves the Thing handling, especially then creating things.
I’ve completely reworked execute_subprocess. By default it returns only the captured string from the child process.
If you are currently using the process output you have to modify your rules, either to use the string in the callback or pass raw_info to execute_subprocess


Changelog:

  • Added log message if item for ping does not exist
  • File writer for Thing config doesn’t create empty files
  • Fixed thing table for textual thing config
  • Added execute_python to rule and reworked execute_subprocess
  • Added item_registry to ignored exception paths
1 Like

Hi Sebastian,

As I saw in the main community, openhab 3.4 is comming to be final.
Did you expect any influence on habapp, or major changes?

There were some breaking changes but I’ve already implemented them in 1.0.5.
However I have not yet tested the latest snapshot so there might still be some surprises. :wink:

Ok, thanks. We will see…

Good news everyone!

HABApp 1.0.8

is out!

This is a small bugfix and maintenance release.


Changelog:

  • ContactItem has open()/closed() methods which will update the state accordingly
  • Setting persistence values now works for some persistence services
  • Don’t connect when user/password is missing for openHAB
  • Added option to enable/disable Thing
  • Added is_enabled property to Thing
6 Likes

Hi, thanks a lot for your work.

I will directly upgrade this evening and will report if I have any issues.

I have one question: Can you please explain your versioning?
You wrote that you are using semantic versioning. But for my understanding the 1.0.8 release is not only a bugfix/patch release since you are adding new features. Can you please explain in which case you will increase the major (currently 1) and the minor (currently 0) version?

Thanks a lot :slight_smile:

You got me there - it’s currently not 100% correct.
You’re right - I should have increase the version number to HABApp 1.1.0 since I’ve added a new feature that is user facing. I’ll try to pay more attention next time.
I guess 2.0 will be the next breaking change which will probably be websocket support.

OK, thank you for your clarification.
It’s not a big issue :wink:

Since now, I had no issue with habapp 1.1.0 (I only had to change your documented braking changes)