Trying to learn the mqtt-connection from the HABApp.Rule, but does not get it to work so far.
Im running HABApp from my PC in PyCharm venv. I have tried to disable temporarily windows firewalls, but did no difference.
What am I missing?
from HABApp.mqtt.items import MqttItem
from HABApp import Rule
from HABApp.core.events import ValueUpdateEvent, ValueUpdateEventFilter
class MqttTest(Rule):
def __init__(self):
super().__init__()
# self.my_mqtt_item = MqttItem.get_create_item('zigbee2mqtt/IKEA_ON_OFF_kontor/action')
# self.my_mqtt_item.listen_event(callback=self.on_mqtt_update, event_filter=ValueUpdateEventFilter())
self.mqtt.subscribe('zigbee2mqtt/IKEA_ON_OFF_kontor/action')
self.listen_event('zigbee2mqtt/IKEA_ON_OFF_kontor/action', callback=self.on_mqtt_update)
# self.mqtt.publish('test', payload='This is a test')
def on_mqtt_update(self, event: ValueUpdateEvent):
print(f'{event}')
MqttTest()
I got some entries in HABApp.log that seems to be correlated
[2022-12-19 11:03:43,663] [ HABApp.Rule] WARNING | C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\paho\mqtt\client.py:1782: ResourceWarning:unclosed <ssl.SSLSocket fd=1120, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.9.8.237', 58360), raddr=('10.9.8.143', 1883)>
[2022-12-19 11:05:04,387] [ HABApp.Rules] ERROR | Error "Mqtt client not connected" in load:
[2022-12-19 11:05:04,387] [ HABApp.Rules] ERROR | Could not load C:\_HG\\\Python\habapp_test_env\rules\test\test_mqtt.py!
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | File "C:\_HG\\\Python\habapp_test_env\rules\test\test_mqtt.py", line 26 in test_mqtt.py
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | --------------------------------------------------------------------------------
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 20 | # self.mqtt.publish('test', payload='This is a test')
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 22 | def on_mqtt_update(self, event: ValueUpdateEvent):
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 23 | print(f'{event}')
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | --> 26 | MqttTest()
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | log = <Logger TestDebug (INFO)>
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR |
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | File "C:\_HG\PN_AUTOMATION\CODING\Python\habapp_test_env\rules\test\test_mqtt.py", line 17 in __init__
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | --------------------------------------------------------------------------------
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 11 | def __init__(self):
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 12 | super().__init__()
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 14 | # self.my_mqtt_item = MqttItem.get_create_item('zigbee2mqtt/IKEA_ON_OFF_kontor/action')
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | 15 | # self.my_mqtt_item.listen_event(callback=self.on_mqtt_update, event_filter=ValueUpdateEventFilter())
[2022-12-19 11:05:04,388] [ HABApp.Rules] ERROR | --> 17 | self.mqtt.subscribe('zigbee2mqtt/IKEA_ON_OFF_kontor/action')
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | 18 | self.listen_event('zigbee2mqtt/IKEA_ON_OFF_kontor/action', callback=self.on_mqtt_update)
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | self = <MqttTest>
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR |
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | --------------------------------------------------------------------------------
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | Traceback (most recent call last):
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\HABApp\rule_manager\rule_file.py", line 77, in load
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | self.create_rules(created_rules)
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\HABApp\rule_manager\rule_file.py", line 67, in create_rules
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | runpy.run_path(str(self.path), run_name=str(self.path), init_globals=init_globals)
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | File "C:\Users\perno\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 289, in run_path
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | return _run_module_code(code, init_globals, run_name,
[2022-12-19 11:05:04,389] [ HABApp.Rules] ERROR | File "C:\Users\perno\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | _run_code(code, mod_globals, init_globals,
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | File "C:\Users\perno\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | exec(code, run_globals)
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | File "C:\_HG\\\Python\habapp_test_env\rules\test\test_mqtt.py", line 26, in test_mqtt.py
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | MqttTest()
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | File "C:\_HG\\\Python\habapp_test_env\rules\test\test_mqtt.py", line 17, in __init__
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | self.mqtt.subscribe('zigbee2mqtt/IKEA_ON_OFF_kontor/action')
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\HABApp\mqtt\mqtt_interface.py", line 67, in subscribe
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | if not __is_connected():
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\HABApp\mqtt\mqtt_interface.py", line 13, in __is_connected
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | raise ConnectionError('Mqtt client not connected')
[2022-12-19 11:05:04,390] [ HABApp.Rules] ERROR | ConnectionError: Mqtt client not connected
[2022-12-19 11:05:04,394] [ HABApp.Rules] WARNING | Failed to load C:\_HG\AUTOMATION\Python\habapp_test_env\rules\test\test_mqtt.py!
[2022-12-19 11:05:43,671] [ HABApp.Rule] WARNING | C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\paho\mqtt\client.py:1782: ResourceWarning:unclosed <ssl.SSLSocket fd=1056, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.9.8.237', 58365), raddr=('10.9.8.143', 1883)>
Mqtt-configuration is done in the config.yml
Mqtt-server is alive and currently not protected by password.