I’ve been looking at this for days now, can’t figure it out! Hope that someone can point me in the correct direction!
I’m running Home Assistant on a VM on a Synology. Within Home Assistant, there is running a Mosquitto broker. I’m running MQTT-IO (https://mqtt-io.app/2.3.0/#/) on a RaspberryPi to connect its GPIO pins over MQTT to Home Assistant to control devices in my smart home. (https://mqtt-io.app/2.3.0/#/) Everything ran fine for over a year, last week my Pi ate the already old SD-card...
Because I’m stupid, I don’t have a backup of the PI :) So, I’ve been in the process of setting this up again, my old SD card boots and runs for +-10min before crashing. This way I can compare configs, but I’m not figuring it out!
It seems the “new” Pi is missing something.
Terminal input
python3 -m mqtt_io /home/Kwarco/Desktop/config.yml
Terminal output
`2024-06-14 22:33:59 mqtt_io.server [INFO] Digital output 'Ctrl_GordijnDicht' current value is False (raw: True)
2024-06-14 22:34:00 mqtt_io.server [INFO] Digital output 'Ctrl_GordijnOpen' current value is False (raw: True)
2024-06-14 22:34:01 mqtt_io.server [INFO] Digital output 'Ctrl_VerluchtingPower' current value is False (raw: True)
2024-06-14 22:34:02 mqtt_io.server [INFO] Digital output 'Ctrl_Verluchting1' current value is False (raw: True)
2024-06-14 22:34:03 mqtt_io.server [INFO] Digital output 'Ctrl_Verluchting2' current value is False (raw: True)
2024-06-14 22:34:04 mqtt_io.server [INFO] Digital output 'Ctrl_Verluchting3' current value is False (raw: True)
2024-06-14 22:34:05 mqtt_io.server [INFO] Digital output 'Ctrl_LuikDicht' current value is False (raw: False)
2024-06-14 22:34:06 mqtt_io.server [INFO] Digital output 'Ctrl_LuikOpen' current value is False (raw: False)
2024-06-14 22:34:06 mqtt_io.server [INFO] Connecting to MQTT...
2024-06-14 22:34:06 mqtt_io.server [ERROR] Exception in critical task:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 1380, in _main_loop
await self._connect_mqtt()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 707, in _connect_mqtt
await self.mqtt.connect()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 51, in inner
await func(*args, **kwargs)
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 116, in connect
await self._client.connect(timeout=timeout)
File "/home/Kwarco/.local/lib/python3.11/site-packages/asyncio_mqtt/client.py", line 82, in connect
if not isinstance(client_socket, mqtt.WebsocketWrapper):
^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'paho.mqtt.client' has no attribute 'WebsocketWrapper'
2024-06-14 22:34:08 mqtt_io.server [INFO] Reconnecting to MQTT broker (infinite retries remaining)
2024-06-14 22:34:08 mqtt_io.server [INFO] Connecting to MQTT...
2024-06-14 22:34:08 mqtt_io.server [ERROR] Exception in critical task:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 1380, in _main_loop
await self._connect_mqtt()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 707, in _connect_mqtt
await self.mqtt.connect()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 51, in inner
await func(*args, **kwargs)
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 116, in connect
await self._client.connect(timeout=timeout)
File "/home/Kwarco/.local/lib/python3.11/site-packages/asyncio_mqtt/client.py", line 82, in connect
if not isinstance(client_socket, mqtt.WebsocketWrapper):
^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'paho.mqtt.client' has no attribute 'WebsocketWrapper'
^CTraceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/__main__.py", line 115, in <module>
main()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/__main__.py", line 107, in main
mqtt_gpio.run()
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 1458, in run
self.loop.run_until_complete(self._main_task)
File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 1422, in _main_loop
await asyncio.sleep(reconnect_delay)
File "/usr/lib/python3.11/asyncio/tasks.py", line 639, in sleep
return await future
^^^^^^^^^^^^
asyncio.exceptions.CancelledError
Exception ignored in: <coroutine object MqttIo.digital_output_loop at 0x75804708>
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/mqtt_io/server.py", line 1304, in digital_output_loop
File "/usr/lib/python3.11/asyncio/queues.py", line 160, in get
File "/usr/lib/python3.11/asyncio/base_events.py", line 761, in call_soon
File "/usr/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <function Client.__del__ at 0x758173e8>
Traceback (most recent call last):
File "/home/Kwarco/.local/lib/python3.11/site-packages/paho/mqtt/client.py", line 880, in __del__
File "/home/Kwarco/.local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1139, in _reset_sockets
File "/home/Kwarco/.local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1132, in _sock_close
File "/home/Kwarco/.local/lib/python3.11/site-packages/paho/mqtt/client.py", line 2867, in _call_socket_close
File "/home/Kwarco/.local/lib/python3.11/site-packages/asyncio_mqtt/client.py", line 308, in _on_socket_close
File "/usr/lib/python3.11/asyncio/base_events.py", line 761, in call_soon
File "/usr/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'MqttIo._mqtt_publish' was never awaited
**Mosquitto broker logs:**
2024-06-14 22:34:06: New client connected from 192.168.XX.XX:43371 as mqtt-io-1634c5d8600786512fd602 (p2, c0, k60, u'Kwarco').
2024-06-14 22:34:08: New connection from 192.168.XX.XX:51041 on port 1883.
2024-06-14 22:34:08: Client mqtt-io-1634c5d8600786512fd602 already connected, closing old connection.
2024-06-14 22:34:08: New client connected from 192.168.XX.XX:51041 as mqtt-io-1634c5d860079c65156613caae5cfa86512fd602 (p2, c0, k60, u'Kwarco').
2024-06-14 22:34:09: Client mqtt-io-1634c5d8600786512fd602 closed its connection.`
/home/Kwarco/Desktop/config.yml content
mqtt:
host: 192.168.xx.xx
port: 1883
user: "Kwarco"
password: "xxxxxxxxxxxxxx"
ha_discovery:
enabled: yes
topic_prefix: pimqtt/gpio
status_topic: status
status_payload_running: online
status_payload_stopped: offline
status_payload_dead: dead
gpio_modules:
- name: raspberrypi
module: raspberrypi
digital_outputs:
- name: Ctrl_GordijnDicht
module: raspberrypi
pin: 2 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_GordijnOpen
module: raspberrypi
pin: 3 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_VerluchtingPower
module: raspberrypi
pin: 26 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_Verluchting1
module: raspberrypi
pin: 6 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_Verluchting2
module: raspberrypi
pin: 13 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_Verluchting3
module: raspberrypi
pin: 19 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: true
initial: high
- name: Ctrl_LuikDicht
module: raspberrypi
pin: 7 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: false
initial: low
- name: Ctrl_LuikOpen
module: raspberrypi
pin: 1 # GPIO
on_payload: "ON"
off_payload: "OFF"
inverted: false
initial: low
I don't understand that the connection is not going true. There is no change on the Home Assistant Side, i'm literally using the same config and commands, The only thing that is different is the versions of software. I tried to downgrade Raspberry Pi OS with no change. I cannot install a previous version of MQTT_IO
Best guess your old code was running with Paho v1.x and the latest (v2.1) removed the WebsocketWrapper
as part of the major version change at v2.0.
https://github.com/eclipse/paho.mqtt.python/releases/tag/v2.0.0
You need to force the installation of v1.x or upgrade the code to work with the new v2.0 paho library.
There is a migration guide here: https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html