HABApp - Easy automation with openHAB

Hello @Spaceman_Spiff
Here I am again, this time with a simple beginner question. :slight_smile:

See the question? :slight_smile:
It would save a roundtrip and reduce traffic.
Or, is it just not an issue because the current value of the dimmer is cached in HABApp anyway so no traffic is generated?

Sorry - no. :confused:

Okay, according to the openHAB documentation, dimmer items have an IncreaseDecrease command, which I assume increases or decreases the dimmer value in a single operation, rather than having to request current value, adjust value, and send the command back.
HABApp seems to lack this command, which means we do have to get_value, adjust, and oh_send_command. Is this an oversight? I would think this decreases performance. Or is it just not necessary?

Itā€™s would be just oh_send_command('INCREASE') and itā€™s an oversight

Hi Seb! Just wanted to let you know, ever since I learned about the docker stats command and found the high CPU load issue, and cleaned out some old test scripts (whatever it was that triggered the issue), I have not ever had a timeout or performance issue! Everything has been working great ever since. I even disabled my MqttDirect hack and everything has been fine without it. Knock on wood, HABApp has been functioning perfectly for weeks now.

Thank you again for all your work, not to mention your patience! :slight_smile:

1 Like

Hi Sebastian! Quick question this time hopefully.

Can I set unique names for the different instances of rules, when using multiple instances of the same rule?

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

RuleOne = TestRule()
RuleTwo = TestRule()
RuleThree = TestRule()
[2022-06-14 09:28:51,949] [             HABApp.Rules]     INFO | Added rule "TestRule" from rules/Game Room/GameroomTvCommands.py
[2022-06-14 09:28:51,950] [             HABApp.Rules]     INFO | Added rule "TestRule.2" from rules/Game Room/GameroomTvCommands.py
[2022-06-14 09:28:51,951] [             HABApp.Rules]     INFO | Added rule "TestRule.3" from rules/Game Room/GameroomTvCommands.py

Theyā€™re assigned TestRule, TestRule.2 and TestRule.3 by default.

The reason why this suddenly matters is that Iā€™m trying to use self.get_rule() from other rules.

Sure!

Uh, thatā€™s great, butā€¦ How? :slight_smile:

Your answer looks like a link but clicking it doesnā€™t go anywhere.

I forgot to copy paste the link :frowning:
Now itā€™s working

Hang on a second, I know about this page ā€“ Indeed it lets me call the rule up by name, but in order to do that, I first need to set descriptive names ā€“ and I have not been able to find any example in the documentation how to set a name for a rule instance. For complex control rules that I reuse for different items, I need to assign a descriptive name, like ā€œBedroomTVā€, ā€œLivingRoomTVā€, ā€œKitchenTVā€ rather than TVControl.1, TVControl.2, TVControl.3.

Let RuleOne(), RuleTwo() ā€¦ derive from TestRule() and create instances from them

1 Like

Nice one! I didnā€™t think of that. Thank you, works perfectly. That will come in handy for other things too.

ā€œIf you want to assign a custom name, you can change the rule name easily by assigning it to self.rule_name in init.ā€

So basically just do

self.rule_name = 'My_Name'

or use @Tokamak suggestion

1 Like

Iā€™m sorry! I must be blind. I must have looked at the article ten times but I did not see it until you pointed it out.

Hi,
Not sure if this is the only place to report any OpenHab/HabApp issues.
I keep openhab up to date and since a few days ago events in OpenHab are no longer triggering my HabApp rules.
Iā€™m also getting the following in my HabApp.log file:

[2022-06-18 20:20:39,662] [                   HABApp]    ERROR | Error 'topic' in on_sse_event:
[2022-06-18 20:20:39,663] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/sse_handler.py", line 25, in on_sse_event
[2022-06-18 20:20:39,664] [                   HABApp]    ERROR |     22   def on_sse_event(event_dict: dict):
[2022-06-18 20:20:39,664] [                   HABApp]    ERROR |     23       try:
[2022-06-18 20:20:39,665] [                   HABApp]    ERROR |     24           # Lookup corresponding OpenHAB event
[2022-06-18 20:20:39,666] [                   HABApp]    ERROR | --> 25           event = get_event(event_dict)
[2022-06-18 20:20:39,667] [                   HABApp]    ERROR |     26
[2022-06-18 20:20:39,668] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:20:39,669] [                   HABApp]    ERROR |      event_dict = {'type': 'ALIVE'}
[2022-06-18 20:20:39,669] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:20:39,670] [                   HABApp]    ERROR |
[2022-06-18 20:20:39,671] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/map_events.py", line 29, in get_event
[2022-06-18 20:20:39,671] [                   HABApp]    ERROR |     27   def get_event(_in_dict: dict) -> OpenhabEvent:
[2022-06-18 20:20:39,672] [                   HABApp]    ERROR |     28       event_type: str = _in_dict['type']
[2022-06-18 20:20:39,672] [                   HABApp]    ERROR | --> 29       topic: str = _in_dict['topic']
[2022-06-18 20:20:39,673] [                   HABApp]    ERROR |     30
[2022-06-18 20:20:39,673] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:20:39,674] [                   HABApp]    ERROR |      _in_dict = {'type': 'ALIVE'}
[2022-06-18 20:20:39,674] [                   HABApp]    ERROR |      OpenhabEvent = <class 'HABApp.openhab.events.base_event.OpenhabEvent'>
[2022-06-18 20:20:39,675] [                   HABApp]    ERROR |      event_type = 'ALIVE'
[2022-06-18 20:20:39,675] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:20:39,676] [                   HABApp]    ERROR |
[2022-06-18 20:20:39,676] [                   HABApp]    ERROR | KeyError: 'topic'
[2022-06-18 20:22:39,454] [                   HABApp]    ERROR | Error 'topic' in on_sse_event:
[2022-06-18 20:22:39,454] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/sse_handler.py", line 25, in on_sse_event
[2022-06-18 20:22:39,454] [                   HABApp]    ERROR |     22   def on_sse_event(event_dict: dict):
[2022-06-18 20:22:39,455] [                   HABApp]    ERROR |     23       try:
[2022-06-18 20:22:39,455] [                   HABApp]    ERROR |     24           # Lookup corresponding OpenHAB event
[2022-06-18 20:22:39,455] [                   HABApp]    ERROR | --> 25           event = get_event(event_dict)
[2022-06-18 20:22:39,456] [                   HABApp]    ERROR |     26
[2022-06-18 20:22:39,456] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:22:39,456] [                   HABApp]    ERROR |      event_dict = {'type': 'ALIVE'}
[2022-06-18 20:22:39,456] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:22:39,457] [                   HABApp]    ERROR |
[2022-06-18 20:22:39,457] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/map_events.py", line 29, in get_event
[2022-06-18 20:22:39,457] [                   HABApp]    ERROR |     27   def get_event(_in_dict: dict) -> OpenhabEvent:
[2022-06-18 20:22:39,458] [                   HABApp]    ERROR |     28       event_type: str = _in_dict['type']
[2022-06-18 20:22:39,458] [                   HABApp]    ERROR | --> 29       topic: str = _in_dict['topic']
[2022-06-18 20:22:39,458] [                   HABApp]    ERROR |     30
[2022-06-18 20:22:39,458] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:22:39,459] [                   HABApp]    ERROR |      _in_dict = {'type': 'ALIVE'}
[2022-06-18 20:22:39,459] [                   HABApp]    ERROR |      OpenhabEvent = <class 'HABApp.openhab.events.base_event.OpenhabEvent'>
[2022-06-18 20:22:39,460] [                   HABApp]    ERROR |      event_type = 'ALIVE'
[2022-06-18 20:22:39,460] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:22:39,460] [                   HABApp]    ERROR |
[2022-06-18 20:22:39,460] [                   HABApp]    ERROR | KeyError: 'topic'

My OpenHab version is: OpenHAB version 3.3.0 (Build #2953)
HabApp Version is: 0.31.2
Iā€™m running both on the same Rasperry Pi 4 with the latest Raspbian OS (Bullseye).

Is anyone else having this issue or suggest a fix?

Thanks,
Richie

Just doing some basic debugging and part of this issue is that the on_sse_event doesnā€™t always seem to have ā€œtopicā€ in it:

[2022-06-18 20:46:39,441] [HABApp.openhab.connection]  WARNING | RR_TEST: {'type': 'ALIVE'}
[2022-06-18 20:46:39,666] [                   HABApp]    ERROR | Error 'topic' in on_sse_event:
[2022-06-18 20:46:39,666] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/sse_handler.py", line 26, in on_sse_event
[2022-06-18 20:46:39,666] [                   HABApp]    ERROR |     22   def on_sse_event(event_dict: dict):
[2022-06-18 20:46:39,667] [                   HABApp]    ERROR |     23       try:
[2022-06-18 20:46:39,667] [                   HABApp]    ERROR |     24           # Lookup corresponding OpenHAB event
[2022-06-18 20:46:39,667] [                   HABApp]    ERROR |     25           log_warning(log, f'RR_TEST: {event_dict}')
[2022-06-18 20:46:39,667] [                   HABApp]    ERROR | --> 26           event = get_event(event_dict)
[2022-06-18 20:46:39,668] [                   HABApp]    ERROR |     27
[2022-06-18 20:46:39,668] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:46:39,668] [                   HABApp]    ERROR |      event_dict = {'type': 'ALIVE'}
[2022-06-18 20:46:39,668] [                   HABApp]    ERROR |      log = <Logger HABApp.openhab.connection (INFO)>
[2022-06-18 20:46:39,669] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:46:39,669] [                   HABApp]    ERROR |
[2022-06-18 20:46:39,670] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/map_events.py", line 29, in get_event
[2022-06-18 20:46:39,670] [                   HABApp]    ERROR |     27   def get_event(_in_dict: dict) -> OpenhabEvent:
[2022-06-18 20:46:39,671] [                   HABApp]    ERROR |     28       event_type: str = _in_dict['type']
[2022-06-18 20:46:39,671] [                   HABApp]    ERROR | --> 29       topic: str = _in_dict['topic']
[2022-06-18 20:46:39,671] [                   HABApp]    ERROR |     30
[2022-06-18 20:46:39,671] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:46:39,672] [                   HABApp]    ERROR |      _in_dict = {'type': 'ALIVE'}
[2022-06-18 20:46:39,672] [                   HABApp]    ERROR |      OpenhabEvent = <class 'HABApp.openhab.events.base_event.OpenhabEvent'>
[2022-06-18 20:46:39,672] [                   HABApp]    ERROR |      event_type = 'ALIVE'
[2022-06-18 20:46:39,672] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 20:46:39,673] [                   HABApp]    ERROR |
[2022-06-18 20:46:39,673] [                   HABApp]    ERROR | KeyError: 'topic'

Could something in OpenHab have changed recently?

Thanks,
Richie

Ok, so further investigation seems to indicate this (in map_events.py) no longer works correctly:

def get_event(_in_dict: dict) -> OpenhabEvent:
    event_type: str = _in_dict['type']
    topic: str = _in_dict['topic']

So an ā€œevent_typeā€ still gets treated as a topic (I think).
My limited Python knowledge is stuck on any further testing/solution :frowning:

Thanks,
Richie

If I understand the postings before yours correctly some changes are needed in HABApp in order to be able to work with OH 3.3.

Currently you should continue with OH 3.2

Hi,
Iā€™ve been running with 3.3 for a while now and itā€™s only one of the recent builds that has caused this.
Iā€™m still digging into it and now get the following errors (whilst ā€œplayingā€ around with the HabApp code):

[2022-06-18 22:06:39,506] [                   HABApp]    ERROR | Error Unknown Event: ALIVE for {'type': 'ALIVE'} in on_sse_event:
[2022-06-18 22:06:39,507] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/map_events.py", line 52, in get_event
[2022-06-18 22:06:39,507] [                   HABApp]    ERROR |     30   def get_event(_in_dict: dict):
[2022-06-18 22:06:39,508] [                   HABApp]    ERROR |  (...)
[2022-06-18 22:06:39,509] [                   HABApp]    ERROR |     48
[2022-06-18 22:06:39,509] [                   HABApp]    ERROR |     49
[2022-06-18 22:06:39,510] [                   HABApp]    ERROR |     50       # Find event from implemented events
[2022-06-18 22:06:39,510] [                   HABApp]    ERROR |     51       try:
[2022-06-18 22:06:39,510] [                   HABApp]    ERROR | --> 52           return __event_lookup[event_type].from_dict(topic, payload)
[2022-06-18 22:06:39,511] [                   HABApp]    ERROR |     53       except KeyError:
[2022-06-18 22:06:39,511] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,511] [                   HABApp]    ERROR |      _in_dict = {'type': 'ALIVE'}
[2022-06-18 22:06:39,512] [                   HABApp]    ERROR |      __event_lookup = {'ItemStateEvent': <class 'HABApp.openhab.events.item_events.ItemStateEvent'>,
[2022-06-18 22:06:39,512] [                   HABApp]    ERROR |                        'ItemStateChangedEvent': <class 'HABApp.openhab.events.item_events.ItemStateChangedEvent'>,
[2022-06-18 22:06:39,512] [                   HABApp]    ERROR |                        'ItemCommandEvent': <class 'HABApp.openhab.events.item_events.ItemCommandEvent'>,
[2022-06-18 22:06:39,513] [                   HABApp]    ERROR |                        'ItemAddedEvent': <class 'HABApp.openhab.events.item_events.ItemAddedEvent'>,
[2022-06-18 22:06:39,513] [                   HABApp]    ERROR |                        'ItemUpdatedEvent': <class 'HABApp.openhab.events.item_events.ItemUpdatedEvent'>,
[2022-06-18 22:06:39,513] [                   HABApp]    ERROR |                        'ItemRemovedEvent': <class 'HABApp.openhab.events.item_events.ItemRemovedEvent'>,
[2022-06-18 22:06:39,513] [                   HABApp]    ERROR |                        'ItemStatePredictedEvent': <class 'HABApp.openhab.events.item_events.ItemStatePredictedEvent'>,
[2022-06-18 22:06:39,514] [                   HABApp]    ERROR |                        'GroupItemStateChangedEvent': <class 'HABApp.openhab.events.item_events.GroupItemStateChangedEvent'>,
[2022-06-18 22:06:39,514] [                   HABApp]    ERROR |                        'ChannelTriggeredEvent': <class 'HABApp.openhab.events.channel_events.ChannelTriggeredEvent'>,
[2022-06-18 22:06:39,514] [                   HABApp]    ERROR |                        'ThingStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingStatusInfoEvent'>,
[2022-06-18 22:06:39,515] [                   HABApp]    ERROR |                        'ThingStatusInfoChangedEv...: <class 'HABApp.openhab.events.thing_events.ThingStatusInfoChangedEvent'>,
[2022-06-18 22:06:39,515] [                   HABApp]    ERROR |                        'ThingFirmwareStatusInfoE...: <class 'HABApp.openhab.events.thing_events.ThingFirmwareStatusInfoEvent'>,
[2022-06-18 22:06:39,515] [                   HABApp]    ERROR |                        'ConfigStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingConfigStatusInfoEvent'>,
[2022-06-18 22:06:39,515] [                   HABApp]    ERROR |                        'FirmwareStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingFirmwareStatusInfoEvent'>}
[2022-06-18 22:06:39,516] [                   HABApp]    ERROR |      event_type = 'ALIVE'
[2022-06-18 22:06:39,516] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,516] [                   HABApp]    ERROR |
[2022-06-18 22:06:39,517] [                   HABApp]    ERROR | KeyError: 'ALIVE'
[2022-06-18 22:06:39,517] [                   HABApp]    ERROR |
[2022-06-18 22:06:39,517] [                   HABApp]    ERROR | While handling the above exception, another exception occurred:
[2022-06-18 22:06:39,517] [                   HABApp]    ERROR |
[2022-06-18 22:06:39,518] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_handler/sse_handler.py", line 25, in on_sse_event
[2022-06-18 22:06:39,518] [                   HABApp]    ERROR |     22   def on_sse_event(event_dict: dict):
[2022-06-18 22:06:39,518] [                   HABApp]    ERROR |     23       try:
[2022-06-18 22:06:39,519] [                   HABApp]    ERROR |     24           # Lookup corresponding OpenHAB event
[2022-06-18 22:06:39,519] [                   HABApp]    ERROR | --> 25           event = get_event(event_dict)
[2022-06-18 22:06:39,519] [                   HABApp]    ERROR |     26
[2022-06-18 22:06:39,520] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,520] [                   HABApp]    ERROR |      event_dict = {'type': 'ALIVE'}
[2022-06-18 22:06:39,520] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,521] [                   HABApp]    ERROR |
[2022-06-18 22:06:39,521] [                   HABApp]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/map_events.py", line 54, in get_event
[2022-06-18 22:06:39,521] [                   HABApp]    ERROR |     30   def get_event(_in_dict: dict):
[2022-06-18 22:06:39,522] [                   HABApp]    ERROR |  (...)
[2022-06-18 22:06:39,522] [                   HABApp]    ERROR |     50       # Find event from implemented events
[2022-06-18 22:06:39,522] [                   HABApp]    ERROR |     51       try:
[2022-06-18 22:06:39,523] [                   HABApp]    ERROR |     52           return __event_lookup[event_type].from_dict(topic, payload)
[2022-06-18 22:06:39,523] [                   HABApp]    ERROR |     53       except KeyError:
[2022-06-18 22:06:39,523] [                   HABApp]    ERROR | --> 54           raise ValueError(f'Unknown Event: {event_type:s} for {_in_dict}')
[2022-06-18 22:06:39,524] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,524] [                   HABApp]    ERROR |      _in_dict = {'type': 'ALIVE'}
[2022-06-18 22:06:39,524] [                   HABApp]    ERROR |      __event_lookup = {'ItemStateEvent': <class 'HABApp.openhab.events.item_events.ItemStateEvent'>,
[2022-06-18 22:06:39,525] [                   HABApp]    ERROR |                        'ItemStateChangedEvent': <class 'HABApp.openhab.events.item_events.ItemStateChangedEvent'>,
[2022-06-18 22:06:39,525] [                   HABApp]    ERROR |                        'ItemCommandEvent': <class 'HABApp.openhab.events.item_events.ItemCommandEvent'>,
[2022-06-18 22:06:39,525] [                   HABApp]    ERROR |                        'ItemAddedEvent': <class 'HABApp.openhab.events.item_events.ItemAddedEvent'>,
[2022-06-18 22:06:39,525] [                   HABApp]    ERROR |                        'ItemUpdatedEvent': <class 'HABApp.openhab.events.item_events.ItemUpdatedEvent'>,
[2022-06-18 22:06:39,526] [                   HABApp]    ERROR |                        'ItemRemovedEvent': <class 'HABApp.openhab.events.item_events.ItemRemovedEvent'>,
[2022-06-18 22:06:39,526] [                   HABApp]    ERROR |                        'ItemStatePredictedEvent': <class 'HABApp.openhab.events.item_events.ItemStatePredictedEvent'>,
[2022-06-18 22:06:39,526] [                   HABApp]    ERROR |                        'GroupItemStateChangedEvent': <class 'HABApp.openhab.events.item_events.GroupItemStateChangedEvent'>,
[2022-06-18 22:06:39,527] [                   HABApp]    ERROR |                        'ChannelTriggeredEvent': <class 'HABApp.openhab.events.channel_events.ChannelTriggeredEvent'>,
[2022-06-18 22:06:39,527] [                   HABApp]    ERROR |                        'ThingStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingStatusInfoEvent'>,
[2022-06-18 22:06:39,527] [                   HABApp]    ERROR |                        'ThingStatusInfoChangedEv...: <class 'HABApp.openhab.events.thing_events.ThingStatusInfoChangedEvent'>,
[2022-06-18 22:06:39,527] [                   HABApp]    ERROR |                        'ThingFirmwareStatusInfoE...: <class 'HABApp.openhab.events.thing_events.ThingFirmwareStatusInfoEvent'>,
[2022-06-18 22:06:39,528] [                   HABApp]    ERROR |                        'ConfigStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingConfigStatusInfoEvent'>,
[2022-06-18 22:06:39,528] [                   HABApp]    ERROR |                        'FirmwareStatusInfoEvent': <class 'HABApp.openhab.events.thing_events.ThingFirmwareStatusInfoEvent'>}
[2022-06-18 22:06:39,528] [                   HABApp]    ERROR |      event_type = 'ALIVE'
[2022-06-18 22:06:39,529] [                   HABApp]    ERROR |     ..................................................
[2022-06-18 22:06:39,529] [                   HABApp]    ERROR |
[2022-06-18 22:06:39,530] [                   HABApp]    ERROR | ValueError: Unknown Event: ALIVE for {'type': 'ALIVE'}

Has there possibly been a new ā€˜ALIVEā€™ event type added in OpenHab over the last few days/weeks?

Thanks,
Richie

1 Like

Howdy! Iā€™m trying to understand the limitations of the ItemNoChangeEvent.
I have two different rules that each have watchers on the same openhab switch item, but for different purposes ā€“ and it seems they only worked one at a time (whichever rule was reloaded last) so I looked into the documentation and discovered:

self.no_change_group.add_no_change_watcher(item, fn, delay, alias="NCW_FloorLamp_GameRoomSwitch")

One of my rules was indeed using EventListenerGroup so this worked nicely, and it seems to have solved the problem!

But, how do I use alias with the regular item.watch_change(secs)? Neither watch_change() nor listen_event() have an alias parameter.

I would like to make sure to always use alias from now on so that this doesnā€™t come back to bite me. Am I understanding things correctly? Is this a real limitation of ItemNoChangeEvent that requires manually aliasing to prevent them stepping on each other, or is something else going on?