molobrakos / tellsticknet

Interface to a Tellstick Net device on the local network
MIT License
32 stars 15 forks source link

ImportError when running tellsticknet mqtt #32

Open MacValley opened 8 months ago

MacValley commented 8 months ago

Goal: Listen for sensor data, send to MQTT (letting Home Assistant do the rest)

Here are my settings: Ubuntu 22.04 with Python 3.10.12. TellStick Net (firmware 17). MQTT server running on the same subnet.

  1. cd ~
  2. git clone https://github.com/molobrakos/tellsticknet.git
  3. cd tellsticknet
  4. pip install .
  5. nano ~/.config/mosquitto_pub with contents: -h 192.168.10.59 # the actual ip for my already running MQTT server -p 1883 -username ThisIsMyUsernameForMyMQTTserver -pw ThisIsMyPasswordForMyMQTTserver

Now I can run e.g 'tellsticknet --ip 192.168.10.180 listen' and I also get data from a bunch of sensors. However, when I try to run 'tellsticknet mqtt -d -vv' I get the following error: 23-12-25 12:48.16 INFO (MainThread) [tellsticknet.main] Debug is on 23-12-25 12:48.16 DEBUG (MainThread) [asyncio] Using selector: EpollSelector 23-12-25 12:48.16 DEBUG (MainThread) [tellsticknet.main] checking for config file /home/anders/.local/bin/tellsticknet.conf 23-12-25 12:48.16 DEBUG (MainThread) [tellsticknet.main] checking for config file /home/anders/.local/bin/.tellsticknet.conf 23-12-25 12:48.16 DEBUG (MainThread) [tellsticknet.main] checking for config file /home/anders/tellsticknet.conf 23-12-25 12:48.16 DEBUG (MainThread) [tellsticknet.main] checking for config file /home/anders/.tellsticknet.conf 23-12-25 12:48.16 DEBUG (MainThread) [tellsticknet.main] checking for config file /home/anders/.config/tellsticknet.conf 23-12-25 12:48.16 DEBUG (MainThread) [asyncio] Close <_UnixSelectorEventLoop running=False closed=False debug=True> Traceback (most recent call last): File "/home/anders/.local/bin/tellsticknet", line 8, in sys.exit(app_main()) File "/home/anders/.local/lib/python3.10/site-packages/tellsticknet/main.py", line 263, in app_main asyncio.run(main(args), debug=debug) # pylint: disable=no-member File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/home/anders/.local/lib/python3.10/site-packages/tellsticknet/main.py", line 174, in main from tellsticknet.mqtt import run File "/home/anders/.local/lib/python3.10/site-packages/tellsticknet/mqtt.py", line 12, in from hbmqtt.client import MQTTClient, ConnectException, ClientException File "/home/anders/.local/lib/python3.10/site-packages/hbmqtt/client.py", line 13, in from hbmqtt.session import Session File "/home/anders/.local/lib/python3.10/site-packages/hbmqtt/session.py", line 8, in from hbmqtt.mqtt.publish import PublishPacket File "/home/anders/.local/lib/python3.10/site-packages/hbmqtt/mqtt/init.py", line 5, in from hbmqtt.mqtt.packet import ( File "/home/anders/.local/lib/python3.10/site-packages/hbmqtt/mqtt/packet.py", line 8, in from hbmqtt.adapters import ReaderAdapter, WriterAdapter File "/home/anders/.local/lib/python3.10/site-packages/hbmqtt/adapters.py", line 6, in from websockets.protocol import WebSocketCommonProtocol ImportError: cannot import name 'WebSocketCommonProtocol' from 'websockets.protocol' (/home/anders/.local/lib/python3.10/site-packages/websockets/protocol.py)

Can anyone help with this? Also, I am wondering about the file ~/.config/tellsticknet.conf. Is that a file I have to fill in myself all together? By using 'tellsticknet --ip 192.168.10.180 listen' I do get protocol, model and sensorid, so I guess I could (should?).

The final goal is to get 'tellsticknet mqtt' running and then let Home Assistant do the rest. This last month (dec 2023) has been a real pain with Telldus Live, so I was really glad that I found this on GitHub. I also have a TellStick ZNet v2 in another subnet, but that is something Home Assistant already has support for with the local API.

To me it seems like a "simple" fix in the source code to get things referenced correctly, but I do not have enough competence to find out where to fix it. Hopefully someone can!

gsolem commented 8 months ago

Having the same issue, with the same error messages when trying to start the mqtt gateway. I am running Python 3.9, but as said same errors.

mosquitto_pub and config seem to be working fine (I can e.g. manage to switch a light on or off), as wel as listen for values. Only have issues with the mqtt connection.

Cresu2 commented 6 months ago

Had the same issue and this fixed it for me: pip install "websockets==8.1"

I also needed to add every sensor I want to track in homeassistant to tellsticknet.conf

I also manually added the mqtt sensors to configuration.yaml as I wanted to group them inside one device and added force_update: true so that sensor values are updated every time new data is received (normally only updated when data is changed).

markoku commented 2 months ago

It was typo in tellsticknet.conf -file. Left separator "---" in the end of file and after removing it works.

I can't get this to work. I tried with Ubuntu 22.04 and Debian 11. I am using christers updated fork (hbmqtt replaced with amqtt).I can find my tellsticknet from local network and get sensor values. Mqtt won't get to work. This is from Ubuntu (with tellsticknet mqtt -vv -d): 24-06-11 21:31.21 DEBUG (MainThread) [tellsticknet.mqtt] Setting up devices 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.client] Watch broker disconnection 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Task cancelled, reader loop ending 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Broker closed connection 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Reader coro stopped 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 puback waiters 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 pucomp waiters 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 purec waiters 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 purel waiters 24-06-11 21:31.21 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] waiting for tasks to be stopped 24-06-11 21:31.21 DEBUG (MainThread) [asyncio] Close <_UnixSelectorEventLoop running=False closed=False debug=True> Traceback (most recent call last): File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/coolbiz/temp/tellsticknet/tellsticknet/main.py", line 269, in app_main() File "/home/coolbiz/temp/tellsticknet/tellsticknet/main.py", line 263, in app_main asyncio.run(main(args), debug=debug) # pylint: disable=no-member File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete return future.result() File "/home/coolbiz/temp/tellsticknet/tellsticknet/main.py", line 176, in main await run(partial(discover, ip=ip), config) File "/home/coolbiz/temp/tellsticknet/tellsticknet/mqtt.py", line 547, in run for e in config File "/home/coolbiz/temp/tellsticknet/tellsticknet/mqtt.py", line 548, in if e.get("controller", controller.mac_address).lower() AttributeError: 'NoneType' object has no attribute 'get'

And this is what comes from Debian: 24-06-11 21:33.34 DEBUG (MainThread) [tellsticknet.mqtt] Setting up devices 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.client] Watch broker disconnection 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Task cancelled, reader loop ending 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Broker closed connection 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Reader coro stopped 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 puback waiters 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 pucomp waiters 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 purec waiters 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] Stopping 0 purel waiters 24-06-11 21:33.34 DEBUG (MainThread) [amqtt.mqtt.protocol.handler] waiting for tasks to be stopped 24-06-11 21:33.34 DEBUG (MainThread) [asyncio] Close <_UnixSelectorEventLoop running=False closed=False debug=True> Traceback (most recent call last): File "/home/coolbiz/.local/bin/tellsticknet", line 8, in sys.exit(app_main()) File "/home/coolbiz/.local/lib/python3.9/site-packages/tellsticknet/main.py", line 263, in app_main asyncio.run(main(args), debug=debug) # pylint: disable=no-member File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/home/coolbiz/.local/lib/python3.9/site-packages/tellsticknet/main.py", line 176, in main await run(partial(discover, ip=ip), config) File "/home/coolbiz/.local/lib/python3.9/site-packages/tellsticknet/mqtt.py", line 545, in run devices = [ File "/home/coolbiz/.local/lib/python3.9/site-packages/tellsticknet/mqtt.py", line 548, in if e.get("controller", controller.mac_address).lower() AttributeError: 'NoneType' object has no attribute 'get'

Any help is apreciated.